RosettaCodeData/Task/Spiral-matrix/Haskell/spiral-matrix-3.hs
2023-07-01 13:44:08 -04:00

10 lines
385 B
Haskell

import Data.List (transpose)
import Text.Printf (printf)
-- spiral is the first row plus a smaller spiral rotated 90 deg
spiral 0 _ _ = [[]]
spiral h w s = [s .. s+w-1] : rot90 (spiral w (h-1) (s+w))
where rot90 = (map reverse).transpose
-- this is sort of hideous, someone may want to fix it
main = mapM_ (\row->mapM_ ((printf "%4d").toInteger) row >> putStrLn "") (spiral 10 9 1)