;; sum0ton (define (sum0ton n) (if (zero? n) 0 (+ n (sum0ton ( n 1)))))
: (model (sum0ton 3)) (+ 3 (sum0ton 2)) (+ 3 (+ 2 (sum0ton 1))) (+ 3 (+ 2 (+ 1 (sum0ton 0)))) ;; base case (+ 3 (+ 2 (+ 1 0))) ;; now going back up, "cleaning up" (+ 3 (+ 2 1)) (+ 3 3) 6
;; sum0tontail ;; ;; INPUTS : A single number, n ;; REQUIRES : The number be a positive integer ;; SIDEEFFECTS : None ;; RETURNS : The sum of all the integers from 0 to n. ;; EXAMPLE : (sum0tontail 3) ==> 6 ;; 0 + 1 + 2 + 3 = 6 : (define (sum0tontail n) ==> : (define (sum0tontailhelper n sumsofar) ==> ==> ==>
: (model (sum0tontail 3)) (sum0tontailhelper 3 0) (sum0tontailhelper 2 3) (sum0tontailhelper 1 5) (sum0tontailhelper 0 6) ;; base case 6 ;; ...done! No need to "clean up"
(define (mycount s) (if (empty? s) 0 (+ 1 (mycount (bf s)))))
: (model (mycount '(a b c))) (+ 1 (mycount '(b c))) (+ 1 (+ 1 (mycount '(c)))) (+ 1 (+ 1 (+ 1 (mycount '())))) ;; base case (+ 1 (+ 1 (+ 1 0))) ;; cleaning up (+ 1 (+ 1 1)) (+ 1 2) 3
: (define (mycounttail s) ==> : (define (mcthelper s countsofar) ;; shortened name for convenience ==> ==> ==>
: (model (mycounttail '(a b c))) (mcthelper '(a b c) 0) (mcthelper '(b c) 1) (mcthelper '(c) 2) (mcthelper '() 3) ;; base case, no clean up needed! 3
;; countevenandodds ;; ;; INPUTS : A sentence of integers, s ;; REQUIRES : The sentence consist only of integers ;; SIDEEFFECTS : None ;; RETURNS : A twoword sentence, wherein the first word ;; : is the number of even numbers in the sentence, and ;; : the second word is the number of odd numbers ;; EXAMPLE : (countevenandodds '(1 2 3 0 4 8 5)) ==> (4 3) ;; : (countevenandodds '(7 9 5 795)) ==> (0 4) ;; : (countevenandodds '(2 4 999998)) ==> (3 0) ;; : (countevenandodds '()) ==> (0 0) : (define (countevenandodds s) ==> : (define (ceaohelper ==> ==> ==> ==> ==>
;; allincreasing? ;; ;; INPUTS : A sentence, s ;; REQUIRES : The sentence consist only of integers, ;; : AND the sentence be nonempty ;; SIDEEFFECTS : None ;; RETURNS : #t if the sentence is in strictly increasing order, else #f ;; EXAMPLE : (allincreasing? '(50 1 2 3 5)) ==> #t ;; : (allincreasing? '(1 2 3 0)) ==> #f : (define (allincreasing? s) ==> : (define (aihelper? ==> ==> ==> ==>
;; longestwinstreak ;; ;; INPUTS : A sentence of w's and l's, s ;; REQUIRES : The sentence consist only of w's and l's ;; : AND the sentence be nonempty ;; SIDEEFFECTS : None ;; RETURNS : The count of the team's longest winning streak ;; EXAMPLE : (longestwinstreak '(l l l l)) ==> 0 ;; : (longestwinstreak '(l w w w l w w l l l l w)) ==> 3 : (define (longestwinstreak s) ==> : (define (lwshelper ==> ==> ==> ==>
columns (C) 

o w s (R) 
0  1  2  3  4  5  ...  
0  1 
... 

1  1 
1 
... 

2  1 
2 
1 
... 

3  1 
3 
3 
1 
... 

4  1 
4 
6 
4 
1 
... 

5  1 
5 
10 
10 
5 
1 
... 

...  ... 
.. 
... 
... 
... 
... 
... 
pascal(C,R) = pascal(C1,R1) + pascal(C,R1)
(define (pascal C R) ==> ==> ==>
pascal(C,R) = R! / ((RC)! C!)
(pairall '(a b c d) '(1 2 3)) ;; ==> (a1 a2 a3 b1 b2 b3 c1 c2 c3 d1 d2 d3) (pairall '(to re on) '(ad ward ly)) ;; ==> (toad toward toly read reward rely onad onward only)
(define (appendprefix prefix suffixes) ==> ==> ==> (define (pairall prefixes suffixes) ==> ==> ==> ==> ==> ==> ==>