Magic squares of doubly even order: Difference between revisions
Content added Content deleted
m (→{{header|Haskell}}: (Tweaked the point at which the 'magic series' starts, for more natural indexing) |
|||
Line 282: | Line 282: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
<lang Haskell> |
<lang Haskell>module DoubleEvenMagic where |
||
import Data.List (transpose) |
|||
magicSquare :: Int -> [[Int]] |
magicSquare :: Int -> [[Int]] |
||
Line 300: | Line 302: | ||
-- 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 a power of 2, we can replicate a |
-- where n is not a 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 $ |
||
scale $ fmap scale $ splitEvery 4 $ magicSeries |
scale $ fmap scale $ splitEvery 4 $ magicSeries 4) |
||
where scale = replicate $ quot n 4 |
where scale = replicate $ quot n 4 |
||
----------------------------------------------------------------------- |
------------------------------------------------------------------------ |
||
magicSeries :: Int -> [Bool] |
magicSeries :: Int -> [Bool] |
||
magicSeries n |
magicSeries n |
||
| n <= 1 = [True] |
| n <= 1 = [True, False] |
||
| otherwise = xs ++ (not <$> xs) |
| otherwise = xs ++ (not <$> xs) |
||
where |
where |