Magic squares of odd order: Difference between revisions

Content added Content deleted
m (J: oops, diagonals matter)
Line 387: Line 387:
to allow for first class functions and closures.
to allow for first class functions and closures.


<lang AppleScript>-- oddMagicSquare :: Int -> [[Int]]
<lang AppleScript>---------------- MAGIC SQUARE OF ODD ORDER ---------------

-- oddMagicSquare :: Int -> [[Int]]
on oddMagicSquare(n)
on oddMagicSquare(n)
cond((n mod 2) > 0, ¬
if 0 < (n mod 2) then
cycleRows(transpose(cycleRows(table(n)))), ¬
cycleRows(transpose(cycleRows(table(n))))
else
missing value)
missing value
end if
end oddMagicSquare
end oddMagicSquare



-- TEST -----------------------------------------------------------------------
--------------------------- TEST -------------------------
on run
on run
-- Orders 3, 5, 11
-- Orders 3, 5, 11
Line 448: Line 453:




-- GENERIC FUNCTIONS ----------------------------------------------------------
-------------------- GENERIC FUNCTIONS -------------------


-- intercalate :: Text -> [Text] -> Text
-- intercalate :: Text -> [Text] -> Text
Line 521: Line 526:
end transpose
end transpose



-- WIKI DISPLAY ---------------------------------------------------------------

----------------------- WIKI DISPLAY ---------------------


-- formattedTable :: [[Int]] -> String
-- formattedTable :: [[Int]] -> String