Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Last active October 29, 2019 22:04
Show Gist options
  • Save chelseatroy/6b520650ab11e09e10f170c6cafa2247 to your computer and use it in GitHub Desktop.
Save chelseatroy/6b520650ab11e09e10f170c6cafa2247 to your computer and use it in GitHub Desktop.
Parity Function
; 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