Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- getSumOfLastN :: (Eq t, Num p, Num t) => [p] -> t -> p
- getSumOfLastN [] _ = 0
- getSumOfLastN _ 0 = 0
- getSumOfLastN x n = last x + getSumOfLastN (init x) (n-1)
- --sumLast :: (Num a) => a -> a -> [a]
- sumLast el n = helper el n [el]
- where helper a b c = a : (helper newE b (c ++ [newE]))
- where newE = (getSumOfLastN c b)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement