Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not sure why it doesn't work, all those appends and reverses are hard to follow, and not sure what's going on with all that set! stuff. Putting the state into a tail call is a lot easier to follow and usually more efficient to boot. </p> <pre><code> (define (apa-add . Lists) (define (cdrs-no-null L) (cond ((null? L) '()) ((null? (cdar l)) (cdrs-no-null (cdr L))) (else (cons (cdar l) (cdrs-no-null (cdr l)))))) (let loop ((carry 0) (Lists (map reverse Lists)) (sum '())) (if (null? Lists) (if (zero? carry) sum (cons carry sum)) (loop (quotient (fold + carry (map car Lists)) 10) (cdrs-no-null Lists) (cons (modulo (fold + carry (map car Lists)) 10) sum))))) (define (apa-mult . Lists) (define (mult-by-factor n order L) (let loop ((order order) (L (reverse L)) (carry 0) (sum '())) (cond ((&gt; order 0) (loop (- order 1) L carry (cons 0 sum))) ((null? L) (if (zero? carry) sum (cons carry sum))) ;;bug here if carry &gt; 9 (else (loop 0 (cdr L) (quotient (+ carry (* n (car L))) 10) (cons (modulo (+ carry (* n (car L))) 10) sum)))))) (define (apa-mult2 L1 L2) (let ((rL1 (reverse L1)) (rL2 (reverse L2)) (zip-with-order (lambda (L) (let loop ((order 0) (L L) (accum '())) (if (null? L) accum (loop (+ 1 order) (cdr L) (cons (cons (car L) order) accum))))))) (fold apa-add '(0) (map (lambda (x) (mult-by-factor (car x) (cdr x) L2)) (zip-with-order rl1))))) (fold apa-mult2 '(1) Lists))) </code></pre> <p>(apa-mult '(3 1 2) '(6 1 4)))</p> <p>;Value 7: (1 9 1 5 6 8)</p> <p>(apa-mult '(2 0 0) '(3 1 2) '(6 1 4))</p> <p>;Value 8: (3 8 3 1 3 6 0 0)</p> <p>(apa-mult '(7 3 1 2) '(6 1 4))</p> <p>;Value 9: (4 4 8 9 5 6 8)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload