Created
October 29, 2019 22:07
-
-
Save chelseatroy/215d783dc68f35452af4be5de033a008 to your computer and use it in GitHub Desktop.
Reversing the Parity List
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 2.20 | |
(define (same-parity first . remaining) | |
(define (iter-list parity-list unprocessed-remaining) | |
(if (null? unprocessed-remaining) | |
parity-list | |
(if (= (remainder first 2) (remainder (car unprocessed-remaining) 2)) | |
(iter-list (cons(car unprocessed-remaining) parity-list) (cdr unprocessed-remaining)) | |
(iter-list parity-list (cdr unprocessed-remaining))) | |
) | |
) | |
(iter-list null remaining)) | |
(reverse (same-parity 2 1 2 3 4 5)) ;----> (2, 4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment