Jump to content

Multiplication tables: Difference between revisions

m
(→‎{{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 w ' ') <$>)) <$> tbl
unlines $
(unwords . w =(justifyRight (length $ (last . last) tbl) ' ' <$>)) <$> tbl
where
tbl = multTable n
w = length $ (last . last) tbl
justifyRight n c s = drop (length s) (mappend (replicate n c) s)
tbl = multTable n
 
main :: IO ()
main = putStr $ tableString 1240</lang>
 
{{Out}}
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.