Skip to content

Instantly share code, notes, and snippets.

View phillipberndt's full-sized avatar

Phillip Berndt phillipberndt

View GitHub Profile
function magic!(M::Array{Int}, n::Int)
# Fast magic square generation
#
#
if n % 2 == 1
# Odd-order magic square
# Algorithm: http://en.wikipedia.org/wiki/Magic_square#Method_for_constructing_a_magic_square_of_odd_order
#
ndiv2 = div(n, 2);
for I = 1:n