Hello gentleman,

Why isn't '(sum-milt-iter three five a b sum1 sum2)' evaluating to 23 given 
that  '(mult-sum 5)' and '(mult-sum 3)' return the right answer, namely 5 and 
18?

; linear iterative process for computing the sum of the multiples of 3 and 5 < 
10
#lang racket
(define (sum-mult three five)
  (sum-mult-iter three five 1 1 0 0))

(define (sum-mult-iter three five a b sum1 sum2)
      (cond
        [(and (>= (* five b) 10)
              (> (* three a) 10)
                  (+ sum1 sum2))]
        [else
          (sum-mult-iter three five (+ a 1) (+ b 1) (+ sum1 (* three a)) (+ 
sum2 (* five b)))]))

; Ive spent some time trying to understand why '(+ sum1 sum2)' does not 
evaluate to 23, but I cannot see why.

given that:

(define (mult-sum five)
    (mult-sum-iterator five 1 0) )
(define (mult-sum-iterator five b sum2)
   (if (>= (* five b) 10)
       sum2
      (mult-sum-iterator five (+ b 1) (+ sum2 (* five b))))

; test
> (milt-sum 5) ; 5

and likewise '(milt-sum three)' evaluates to 18.
(define (mult-sum three)
    (mult-sum-iterator three 1 0) )
(define (mult-sum-iterator three a sum2)
   (if (>= (* five a) 10)
       sum2
      (mult-sum-iterator five (+ a 1) (+ sum2 (* five a))))
; test
> (mult-sum 3) ; 18

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to