Magic squares of doubly even order: Difference between revisions
Content added Content deleted
Line 602: | Line 602: | ||
limit = sqr + 1 |
limit = sqr + 1 |
||
series |
series |
||
-- For powers of 2, the (append not) 'magic' series directly |
-- For integer powers of 2, the (append not) 'magic' series directly |
||
-- yields the truth table that we need |
-- yields the truth table that we need |
||
| isPowerOf 2 n = |
| isPowerOf 2 n = |
||
magicSeries $ floor (logBase 2 (fromIntegral sqr)) |
magicSeries $ floor (logBase 2 (fromIntegral sqr)) |
||
-- where n is not |
-- where n is not an integer power of 2, we can replicate a |
||
-- minimum truth table, horizontally and vertically |
-- minimum truth table, horizontally and vertically |
||
| otherwise = (concat . concat . concat . |
| otherwise = (concat . concat . concat . |
||
Line 623: | Line 623: | ||
where |
where |
||
xs = magicSeries (n - 1) |
xs = magicSeries (n - 1) |
||
splitEvery :: Int -> [a] -> [[a]] |
splitEvery :: Int -> [a] -> [[a]] |
||
splitEvery n xs |
splitEvery n xs |
||
Line 652: | Line 652: | ||
diagonals :: [[Int]] -> [[Int]] |
diagonals :: [[Int]] -> [[Int]] |
||
diagonals xs = |
diagonals xs = |
||
(\x -> zipWith (!!) x [0..]) <$> [xs, reverse xs] |
|||
main2 :: IO () |
main2 :: IO () |