;; sumNr: num --> n ;; sums all the numbers from 1 to n (define (sumNr n) (cond [(zero? n) 0] [else (+ n (sumNr (sub1 n)))])) "Reverse accumulation tests:" (time (sumNr 5)) (time (sumNr 5000)) (time (sumNr 500000)) ;; sumNf: num --> n ;; sums all the numbers from 1 to n (define (sumNf n) (cond [(zero? n) 0] [else (sumNf_help (sub1 n) n)])) ;; sumNf_help: num, num --> n ;; adds acc to the sum of all the numbers from 1 to n (define (sumNf_help n acc) (cond [(zero? n) acc] [else (sumNf_help (sub1 n) (+ n acc))])) "" "Forward accumulation tests:" (time (sumNf 5)) (time (sumNf 5000)) (time (sumNf 500000))