Multiplication tables: Difference between revisions
Content added Content deleted
(→{{header|Haskell}}: Switched core type from [Int] to Maybe Int) |
|||
Line 2,254: | Line 2,254: | ||
Or, making do without imports beyond the Prelude, and separating data from formatting: |
Or, making do without imports beyond the Prelude, and separating data from formatting: |
||
<lang Haskell>multTable :: Int -> [[ |
<lang Haskell>multTable :: Int -> [[Maybe Int]] |
||
multTable n = |
multTable n = |
||
(\x -> Just x : Nothing : ( |
|||
(\y -> if y < x then Nothing else Just (x * y)) |
|||
<$> range)) |
|||
<$> range |
|||
where range = [1..n] |
|||
tableString :: [[ |
tableString :: [[Maybe Int]] -> String |
||
tableString tbl = |
tableString tbl = |
||
unlines $ (concat . (fmt <$>)) <$> tbl |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
where |
where |
||
pad = " " |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
main :: IO () |
main :: IO () |