Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Created October 29, 2019 22:07
Show Gist options
  • Save chelseatroy/215d783dc68f35452af4be5de033a008 to your computer and use it in GitHub Desktop.
Save chelseatroy/215d783dc68f35452af4be5de033a008 to your computer and use it in GitHub Desktop.
Reversing the Parity List
; 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