Multiplication tables: Difference between revisions

m
(→‎{{header|Haskell}}: Separated the table generation from the formatting)
Line 2,322:
<lang haskell>import Data.List (maximumBy)
import Data.Ord (comparing)
import Data.Monoid
 
multTable :: Int -> [[String]]
multTable n =
(\x ->
mappend (show x) <> ":" :
((\y ->
if y < x
Line 2,337 ⟶ 2,338:
tableString tbl =
unlines $
(unwords . (justifyRight (length $ (last . last) tbl)colWidth ' ' <$>)) <$> tbl
where
justifyRight n c scolWidth = drop (length s)$ (mappendlast (replicate. n clast) s)tbl
justifyRight n c s = drop (length s) ((replicate n c) <> s)
 
main :: IO ()
9,659

edits