fork download
  1. ; your code goes here
  2. (define (same-parity x xs)
  3. (define parity (remainder x 2))
  4. (define (iter xs acc)
  5. (if (null? xs)
  6. (reverse acc)
  7. (if (= (remainder (car xs) 2) parity)
  8. (iter (cdr xs) (cons (car xs) acc))
  9. (iter (cdr xs) acc))))
  10. (iter xs '()))
  11.  
  12. (define xs (list 1 2 3 4 5 6 7 8 9 10))
  13.  
  14. (display (same-parity 1 xs))
  15. (newline)
  16. (display (same-parity 2 xs))
  17. (newline)
Success #stdin #stdout 0.03s 8616KB
stdin
Standard input is empty
stdout
(1 3 5 7 9)
(2 4 6 8 10)