(define (same-parity a . xs)
(let ((parity (if (odd? a) odd? even?)))
(define (iter items result)
(if (null? items)
result
(iter (cdr items)
(if (parity (car items))
(cons result (car items))
result))))
(iter xs a)))
; Testing
(display (same-parity 1 2 3 4 5 6 7 8 9 10))
(newline)
KGRlZmluZSAoc2FtZS1wYXJpdHkgYSAuIHhzKQogICAgICAgIChsZXQgKChwYXJpdHkgKGlmIChvZGQ/IGEpIG9kZD8gZXZlbj8pKSkKICAgICAgICAgICAgICAgIChkZWZpbmUgKGl0ZXIgaXRlbXMgcmVzdWx0KQogICAgICAgICAgICAgICAgICAgICAgICAoaWYgKG51bGw/IGl0ZW1zKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChpdGVyIChjZHIgaXRlbXMpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoaWYgKHBhcml0eSAoY2FyIGl0ZW1zKSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKGNvbnMgcmVzdWx0IChjYXIgaXRlbXMpKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQpKSkpCiAgICAgICAgICAgICAgICAoaXRlciB4cyBhKSkpCgo7IFRlc3RpbmcKCihkaXNwbGF5IChzYW1lLXBhcml0eSAxIDIgMyA0IDUgNiA3IDggOSAxMCkpCihuZXdsaW5lKQo=