RosettaCodeData/Task/Zig-zag-matrix/Haskell/zig-zag-matrix-2.hs

13 lines
302 B
Haskell
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
-- 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)]