Spiral matrix: Difference between revisions
Content added Content deleted
(Updated to work with Nim 1.4 + removed “^” procedure, removed “newSeqWith”, removed useless type “Pos”) |
|||
Line 1,975: | Line 1,975: | ||
Or less ambitiously, |
Or less ambitiously, |
||
{{Trans|AppleScript}} |
{{Trans|AppleScript}} |
||
<lang Haskell>import |
<lang Haskell>import Control.Monad (join) |
||
import |
import Data.List (intercalate, transpose) |
||
spiral :: Int -> [[Int]] |
spiral :: Int -> [[Int]] |
||
Line 1,984: | Line 1,984: | ||
| 0 < rows = |
| 0 < rows = |
||
[x .. pred cols + x] : |
[x .. pred cols + x] : |
||
fmap |
|||
⚫ | |||
reverse |
|||
⚫ | |||
| otherwise = [[]] |
| otherwise = [[]] |
||
⚫ | |||
⚫ | |||
wikiTable :: Show a => [[a]] -> String |
wikiTable :: Show a => [[a]] -> String |
||
wikiTable = |
wikiTable = |
||
join |
join |
||
("{| class=\"wikitable\" style=\"text-align: right;" :) |
. ("{| 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 |
|||
( |
. (<> "\n|}") |
||
intercalate "\n|-\n" |
. intercalate "\n|-\n" |
||
fmap (('|' :) . (' ' :) . intercalate " || " . fmap show)</lang> |
. fmap (('|' :) . (' ' :) . intercalate " || " . fmap show)</lang> |
||
{{Out}} |
{{Out}} |
||
{| class="wikitable" style="text-align: right;width:12em;height:12em;table-layout:fixed;"|- |
{| class="wikitable" style="text-align: right;width:12em;height:12em;table-layout:fixed;"|- |