Multiplication tables: Difference between revisions
Content added Content deleted
(→{{header|Haskell}}: Adjusted for more flexible column widths (for larger tables and longer integer strings)) |
(→{{header|Haskell}}: Simpler route to max integer string length) |
||
Line 2,326: | Line 2,326: | ||
multTable n = |
multTable n = |
||
(\x -> |
(\x -> |
||
mappend (show x) ":" : |
(mappend (show x) ":") : |
||
((\y -> |
((\y -> |
||
if y < x |
if y < x |
||
Line 2,333: | Line 2,333: | ||
[1 .. n])) <$> |
[1 .. n])) <$> |
||
[1 .. n] |
[1 .. n] |
||
tableString :: Int -> String |
tableString :: Int -> String |
||
tableString n = unlines $ (unwords . (justifyRight |
tableString n = unlines $ (unwords . ((justifyRight w ' ') <$>)) <$> tbl |
||
where |
where |
||
⚫ | |||
mx = maximumBy (comparing length) |
|||
⚫ | |||
tbl = multTable n |
tbl = multTable n |
||
⚫ | |||
⚫ | |||
main :: IO () |
main :: IO () |