Last active
May 10, 2020 10:06
-
-
Save l1x/9c3b598dd62c8d240050c10fe0947dbf to your computer and use it in GitHub Desktop.
Spiral print in Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
transpose :: [[Int]] -> [[Int]] | |
transpose m = | |
case m of | |
[] -> [] | |
([]:_) -> [] | |
x -> (map head x) : transpose (map (drop 1) x) | |
spiralPrintShort :: [[Int]] -> [Int] | |
spiralPrintShort matrix = | |
case matrix of | |
[] -> [] | |
x:xs -> x ++ spiralPrintShort (reverse (transpose xs)) | |
main :: IO () | |
main = do | |
print (spiralPrintShort [[1, 2, 3], [8, 9, 4], [7, 6, 5]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment