Magic squares of doubly even order: Difference between revisions
→{{header|Haskell}}: dropped splitEvery for chunksOf, updated output
No edit summary |
(→{{header|Haskell}}: dropped splitEvery for chunksOf, updated output) |
||
Line 637:
=={{header|Haskell}}==
<lang Haskell>import Data.List.Split (
import Data.List (transpose, unfoldr)
magicSquare :: Int -> [[Int]]
Line 643 ⟶ 644:
| rem n 4 > 0 = []
| otherwise =
-- Taken directly from the integer series where True
-- and from the reverse of that series where False
Line 663 ⟶ 664:
-- minimum truth table, horizontally and vertically
| otherwise =
concat . concat . concat . scale $ scale <$> chunksOf 4 (magicSeries 4)
where
scale = replicate $ quot n 4
magicSeries :: Int -> [Bool]
magicSeries = (iterate (
splitEvery :: Int -> [a] -> [[a]]▼
isPowerOf :: Int -> Int -> Bool
isPowerOf k n = until (
main :: IO ()▼
main = mapM_ print $ magicSquare 8▼
checked :: Int -> (Int, Bool)
checked n = (h, all (h ==) t)
Line 692 ⟶ 687:
diagonals square -- diagonals
▲main :: IO ()
main = do
▲diagonals xs = flip (zipWith (!!)) [0 ..] <$> [xs, reverse xs]
putStrLn ""
{{Out}}
<pre>[1,63,62,4,60,6,7,57]
[
[
[
[
[
[
[
(260,True)</pre>
|