Spiral matrix: Difference between revisions
Content added Content deleted
m (→{{header|Haskell}}: (tidying - switched if to guards)) |
|||
Line 1,884: | Line 1,884: | ||
spiral n = go n n 0 |
spiral n = go n n 0 |
||
where |
where |
||
go rows cols |
go rows cols x |
||
| 0 < rows = |
|||
[x .. pred cols + x] : |
|||
fmap reverse (transpose $ go cols (pred rows) (x + cols)) |
|||
| otherwise = [[]] |
|||
main :: IO () |
|||
main = putStrLn $ wikiTable (spiral 5) |
|||
Line 1,899: | Line 1,896: | ||
wikiTable = |
wikiTable = |
||
join . |
join . |
||
("{| class=\"wikitable\" style=\"text-align: |
("{| class=\"wikitable\" style=\"text-align: right;" :) . |
||
("width:12em;height:12em;table-layout:fixed;\"\n|-\n" :) . |
("width:12em;height:12em;table-layout:fixed;\"\n|-\n" :) . |
||
return . |
return . |
||
Line 1,906: | Line 1,903: | ||
fmap (('|' :) . (' ' :) . intercalate " || " . fmap show)</lang> |
fmap (('|' :) . (' ' :) . intercalate " || " . fmap show)</lang> |
||
{{Out}} |
{{Out}} |
||
{| class="wikitable" style="text-align: |
{| class="wikitable" style="text-align: right;width:12em;height:12em;table-layout:fixed;"|- |
||
| 0 || 1 || 2 || 3 || 4 |
| 0 || 1 || 2 || 3 || 4 |
||
|- |
|- |