Last active
October 29, 2019 22:04
-
-
Save chelseatroy/6b520650ab11e09e10f170c6cafa2247 to your computer and use it in GitHub Desktop.
Parity Function
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)) | |
(same-parity 2 1 2 3 4 5) ;----> (4, 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment