12345678910111213141516171819202122232425262728293031323334353637383940 |
- (import
- (scheme base))
- (define (add-two l1 l2)
- (let loop ((in1 l1)
- (in2 l2)
- (out '())
- (carry? #f))
- (define next1 (if (null? in1)
- 0
- (car in1)))
- (define next2 (if (null? in2)
- 0
- (car in2)))
- (cond
- ((or (not (null? in1))
- (not (null? in2))
- carry?)
- (let* ((sum-val (+ next1
- next2
- (if carry? 1 0)))
- (next-carry? (>= sum-val 10))
- (actual-val (if next-carry?
- (- sum-val 10)
- sum-val)))
- (loop (if (null? in1)
- in1
- (cdr in1))
- (if (null? in2)
- in2
- (cdr in2))
- (cons actual-val out)
- next-carry?)))
- (else
- (reverse out)))))
- (define (solution2 arg1 arg2)
- (add-two arg1 arg2))
|