Well, my friend and I tried several times to do this and refused to go to the mentor, because everything they do gives us answers, and this does not help us learn anything.
Currently, I can get the code to do one of two things, return the amount of the list or return the list itself, and we need to get it so that it returns the list and the last digit of the amount. Here are two things that we still have:
(define (add-checksum ls) (cond [(null? ls) 0] [else (+ (car ls) (add-checksum (cdr ls)))])) (define (add-checksum-helper ls) (cond [(null? ls) 0] [else (cons (car ls) (add-checksum-helper (cdr ls)))]))
The first set of codes adds and returns the amount. The second returns a list plus a .0 , where should the last digit of the sum go? Can anybody help us? Thanks!
EDIT:
(define (checksum ls) (append ls ((cdr (add-checksum ls))))) (define (add-checksum ls) (cond [(null? ls) 0] [else (+ (car ls) (add-checksum (cdr ls)))]))
Return:
(checksum '(4 5 6 7 8)) ((4 5 6 7 8) . 30)
We need to return (4 5 6 7 8 0) instead of (.30) . We donโt know how easy it is to get 0 . if we do (cdr 30) , we get a list not paired. Any suggestions now?
source share