Skip to content

Instantly share code, notes, and snippets.

@hmaurer
Created March 3, 2014 15:11
Show Gist options
  • Save hmaurer/9326996 to your computer and use it in GitHub Desktop.
Save hmaurer/9326996 to your computer and use it in GitHub Desktop.
sumUpTo :: Int -> [(Int, Int)]
sumUpTo n = map (\x -> (x, n - x)) [0..n]
mult xs ys = do
cs <- map sumUpTo [0..maxCoef]
return (sum $ map g $ filter f cs)
where
maxCoef = length xs + length ys - 2
f (x, y) = x < length xs && y < length ys
g (x, y) = (xs !! x) * (ys !! y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment