Magic squares of doubly even order: Difference between revisions
Magic squares of doubly even order (view source)
Revision as of 08:32, 3 September 2019
, 4 years ago→{{header|Haskell}}
(→{{header|rust}}: Rust version) |
|||
Line 1,108:
<lang Haskell>import Data.List (transpose, unfoldr, intercalate)
import Data.List.Split (chunksOf)
import Data.Bool (bool)
import Control.Monad (forM_)
Line 1,114 ⟶ 1,115:
| rem n 4 > 0 = []
| otherwise =
chunksOf n $ zipWith (flip (bool =<< (-) limit)) series [1 .. sqr]
where
sqr = n * n
Line 1,137 ⟶ 1,131:
isPowerOf :: Int -> Int -> Bool
isPowerOf k n = until ((0 /=) . flip rem k) (`quot` k) n == 1
-- TEST AND DISPLAY FUNCTIONS --------------------------------------------------
checked :: [[Int]] -> (Int, Bool)
checked square =
Line 1,166 ⟶ 1,158:
putStrLn $ unlines (table " " (fmap show <$> test))
print $ checked test
putStrLn
{{Out}}
<pre>main
|