Multiplication tables: Difference between revisions

→‎{{header|Haskell}}: Simpler route to max integer string length
(→‎{{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:
multTable n =
(\x ->
(mappend (show x) ":") :
((\y ->
if y < x
Line 2,333:
[1 .. n])) <$>
[1 .. n]
 
tableString :: Int -> String
tableString n = unlines $ (unwords . ((justifyRight (maxLen tbl)w ' ') <$>)) <$> tbl
where
justifyRight n c s = drop (length s) (mappend (replicate n c) s)
mx = maximumBy (comparing length)
maxLen = length . mx . (mx <$>)
tbl = multTable n
maxLenw = length .$ mx(last . (mxlast) <$>)tbl
justifyRight n c s = drop (length s) (mappend (replicate n c) s)
 
main :: IO ()
9,659

edits