Magic squares of doubly even order: Difference between revisions

→‎{{header|Haskell}}: Made the test more direct
(→‎{{header|Haskell}}: dropped splitEvery for chunksOf, updated output)
(→‎{{header|Haskell}}: Made the test more direct)
Line 645:
| otherwise =
chunksOf n $
-- Taken directly from the integer series where True
-- and from the reverse of that series where False
zipWith
(\x i ->
Line 658 ⟶ 656:
limit = sqr + 1
series
-- For integer powers of 2, the (append not) 'magic' series directly
-- yields the truth table that we need
| isPowerOf 2 n = magicSeries $ floor (logBase 2 (fromIntegral sqr))
-- where n is not an integer power of 2, we can replicate a
-- minimum truth table, horizontally and vertically
| otherwise =
concat . concat . concat . scale $ scale <$> chunksOf 4 (magicSeries 4)
Line 677 ⟶ 671:
diagonals = fmap (flip (zipWith (!!)) [0 ..]) . ((:) <*> (return . reverse))
 
checked :: [[Int]] -> (Int, Bool)
checked nsquare = (h, all (h ==) t)
where
square = magicSquare n
h:t =
sum <$>
Line 689 ⟶ 682:
main :: IO ()
main = do
mapM_let printsquare $= magicSquare 8
mapM_ print square
putStrLn ""
print $ checked 8square</lang>
{{Out}}
<pre>[1,63,62,4,60,6,7,57]
9,659

edits