Magic squares of singly even order: Difference between revisions

→‎{{header|Haskell}}: Added comments to nextSiam function
(→‎{{header|Haskell}}: Rotated display for better match with description of LUX method)
(→‎{{header|Haskell}}: Added comments to nextSiam function)
Line 525:
nextSiam uBound sMap (x, y) =
let alt (a, b)
| a > uBound && b < 0 = (uBound, 1) -- Top right corner ?
| a > uBound = (0, b) -- beyond right edge ?
| b < 0 = (a, uBound) -- above top edge ?
| isJust (M.lookup (a, b) sMap) = (a - 1, b + 2) -- already filled ?
| otherwise = (a, b) -- Up one, right one.
in alt (x + 1, y - 1)
 
Line 544:
where
diagonals = fmap (flip (zipWith (!!)) [0 ..]) . ((:) <*> (return . reverse))
h:t = sum <$> square <> transpose square <> diagonals square
h:t =
sum <$>
square ++ -- rows
transpose square ++ -- cols
diagonals square -- diagonals
 
table :: String -> [[String]] -> [String]
9,655

edits