Advertisement
Guest User

Untitled

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