RosettaCodeData/Task/Zig-zag-matrix/Haskell/zig-zag-matrix-2.hs
2023-07-01 13:44:08 -04:00

12 lines
302 B
Haskell

-- format a 2d array of integers neatly
show2d a =
unlines
[ unwords
[ printf "%3d" (a ! (x, y) :: Integer)
| x <- axis fst ]
| y <- axis snd ]
where
(l, h) = bounds a
axis f = [f l .. f h]
main = mapM_ (putStr . ('\n' :) . show2d . zigZag) [(3, 3), (4, 4), (10, 2)]