Jump to content

Multiplication tables: Difference between revisions

m
m (→‎{{header|Haskell}}: Tidied, removed one import.)
Line 3,522:
mulTable :: [Int] -> [[Maybe Int]]
mulTable xs =
(Nothing : axislabels) :
zipWith
(:)
axislabels
[[upperMul x y | y <- xs] | x <- xs]
where
axislabels = Just <$> xs
upperMul x y
| x > y = Nothing
Line 3,537:
main :: IO ()
main =
(putStrLn . unlines) $
showTable . mulTable
<$> [ [13 .. 20],
Line 3,548:
showTable xs = unlines $ head rows : [] : tail rows
where
w = 1succ +$ (length . show) (fromMaybe 0 $ (last . last) xs)
gap = replicate w ' '
rows = (maybe gap (rjust w ' ' . show) =<<) <$> xs
9,655

edits

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