Multiplication tables: Difference between revisions

m
Line 2,322:
<lang haskell>import Data.List (maximumBy)
import Data.Ord (comparing)
import Data.Monoid ((<>))
 
multTable :: Int -> [[String]]
multTable n =
(\x ->
(show x) <> ":" :
((\y ->
if y < x
Line 2,336:
 
tableString :: [[String]] -> String
tableString tbl = unlines $ (unwords . (justifyRight colWidth ' ' <$>)) <$> tbl
unlines $
(unwords . (justifyRight colWidth ' ' <$>)) <$> tbl
where
colWidth = length $ (last . last) tbl
justifyRight n c s = drop (length s) ((replicate n c) <> s)
 
main :: IO ()
9,659

edits