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 ControlData.MonadList (joinintercalate, transpose)
import Data.List (intercalate, transpose)
 
---------------------- TABLESPIRAL FORMATTINGMATRIX ---------------------
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 =
joinconcat
. ("{| class=\"wikitable\" style=\"text-align: right;" :)
. ("width:12em;height:12em;table-layout:fixed;\"\n|-\n" :)
9,655

edits