Multiplication tables: Difference between revisions
→{{header|Haskell}}: Abbreviated slightly with bool
(Add task to ARM assembly Raspberry pi) |
(→{{header|Haskell}}: Abbreviated slightly with bool) |
||
Line 2,580:
=={{header|Haskell}}==
<lang haskell>import Data.
import Data.
import Data.Bool (bool)
let xs = [1 .. n]
in xs >>=
\x -> [show x <> ":" : (xs >>= \y -> [bool (show (x * y)) mempty (y < x)])]
table :: String -> [[String]] -> [String]
table
let justifyRight c n s = drop (length s) (replicate n c <> s)
in intercalate
transpose
((fmap =<< justifyRight ' ' . maximum . fmap length) <$> transpose rows)
main :: IO ()
main = (putStrLn . unlines . table " " .
{{Out}}
<pre> 1: 1 2 3 4 5 6 7 8 9 10 11 12
|