Spiral matrix: Difference between revisions
m
→{{header|Haskell}}: Tidied, added main.
m (→{{header|Haskell}}: Tidied, added main.) |
|||
Line 2,064:
Or less ambitiously,
{{Trans|AppleScript}}
<lang Haskell>import
spiral :: Int -> [[Int]]
spiral n = go n n 0
Line 2,072:
go rows cols x
| 0 < rows =
[x .. pred cols + x] :
fmap
reverse
(transpose $ go cols (pred rows) (x + cols))
| otherwise = [[]]
▲--------------------- TABLE FORMATTING -------------------
--------------------------- TEST -------------------------
main :: IO ()
main = putStrLn $ wikiTable $ spiral 5
--------------------- TABLE FORMATTING -------------------
wikiTable :: Show a => [[a]] -> String
wikiTable =
. ("{| class=\"wikitable\" style=\"text-align: right;" :)
. ("width:12em;height:12em;table-layout:fixed;\"\n|-\n" :)
|