Magic squares of doubly even order: Difference between revisions

m
(→‎{{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]
zipWith
(\x i ->
if x
then i
else limit - i)
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 ""[]</lang>
{{Out}}
<pre>main
9,655

edits