Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- example input: [1,6,2,5,4]
- -- result: [(1, 0), (6, 1), (2, 7), (5, 9), (4, 14)]
- -- every element of the result list is a pair that has
- -- the element of the list as the first element, and
- -- as the second element the sum of all the preceding
- -- elements.
- before xs = inner xs 0
- where inner [] _ = []
- inner (x:[]) acc = [(x, acc)]
- inner (x:xs) acc = (x, acc):(inner xs (acc + x))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement