Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.36 KB | None | 0 0
  1. (define (sumLast k n)
  2.   (define (helper s currList)
  3.     (let* ((currentList (if (< (length currList) n) (cons s currList)
  4.                                                      (cons s (take currList (- n 1)))))
  5.           (value (foldr + 0 currentList)))                    
  6.     (stream-cons value (helper value currentList))))
  7.    (stream-cons k (helper k '())))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement