Magic squares of odd order: Difference between revisions

m
m (J: interesting alternate approach)
Line 1,741:
| otherwise = []
 
-- TEST ------------------------ TEST ---------------------------
main :: IO ()
main = mapM_ putStrLn $ (showSquare . magicSquare) <$> [3, 5, 7]
 
-- GENERIC ----------------------- GENERIC -------------------------
applyN :: Int -> (a -> a) -> a -> a
applyN n f = foldr (.) id (replicate n f)
Line 1,770:
showSquare rows =
let srows = fmap show <$> rows
w = 1succ +$ maximum (length <$> concat srows)
in unlines $ concatMapfmap (justifyRight w ' ') =<$><) srows</lang>
{{Out}}
<pre> 8 1 6
9,655

edits