I didn't success doing it. But I did it with iruby is there a way to adapt it ?
def odd_magic_square(n) raise ArgumentError "Need odd positive number" if n.even? || n <= 0 n.times.map{|i| n.times.map{|j| n*((i+j+1+n/2)%n) + ((i+2*j-5)%n) + 1} } end [3].each do |n| #puts "\nSize #{n}, magic sum #{(n*n+1)/2*n}" fmt = "%#{(n*n).to_s.size + 1}d" * n #odd_magic_square(n).each{|row| puts fmt % row} end IRuby.table(odd_magic_square(3)) Le samedi 15 octobre 2016 04:59:20 UTC+2, Henri Girard a écrit : > > Hi, > Is it possible to have a table with only the result ? > I don't want row /column names. > > using DataFrames > function iain_magic(n::Int) > M = zeros(Int, n, n) > for I = 1:n, J = 1:n > @inbounds M[I,J] = n*((I+J-1+(n >> 1))%n)+((I+2J-2)%n) + 1 > end > return M > end > mm=iain_magic(3) > df=DataFrame(mm) >