Multiplication tables: Difference between revisions
Content added Content deleted
m (→{{header|Haskell}}: Tidied, removed one import.) |
|||
Line 3,522: | Line 3,522: | ||
mulTable :: [Int] -> [[Maybe Int]] |
mulTable :: [Int] -> [[Maybe Int]] |
||
mulTable xs = |
mulTable xs = |
||
(Nothing : |
(Nothing : labels) : |
||
zipWith |
zipWith |
||
(:) |
(:) |
||
labels |
|||
[[upperMul x y | y <- xs] | x <- xs] |
[[upperMul x y | y <- xs] | x <- xs] |
||
where |
where |
||
labels = Just <$> xs |
|||
upperMul x y |
upperMul x y |
||
| x > y = Nothing |
| x > y = Nothing |
||
Line 3,537: | Line 3,537: | ||
main :: IO () |
main :: IO () |
||
main = |
main = |
||
putStrLn . unlines $ |
|||
showTable . mulTable |
showTable . mulTable |
||
<$> [ [13 .. 20], |
<$> [ [13 .. 20], |
||
Line 3,548: | Line 3,548: | ||
showTable xs = unlines $ head rows : [] : tail rows |
showTable xs = unlines $ head rows : [] : tail rows |
||
where |
where |
||
w = |
w = succ $ (length . show) (fromMaybe 0 $ (last . last) xs) |
||
gap = replicate w ' ' |
gap = replicate w ' ' |
||
rows = (maybe gap (rjust w ' ' . show) =<<) <$> xs |
rows = (maybe gap (rjust w ' ' . show) =<<) <$> xs |