;#!/usr/bin/racket
;#lang scheme
; List reversing
(define (reverse ls)
(define (iter xs result)
(if (null? xs)
result
(iter (cdr xs) (cons (car xs) result))))
(iter ls '()))
(define (same-parity a . xs)
(let ((parity (if (odd? a) odd? even?)))
(define (iter items result)
(if (null? items)
(reverse result)
(iter (cdr items)
(if (parity (car items))
(cons (car items) result)
result))))
(iter xs (list a))))
; Testing
(display (same-parity 1 2 3 4 5 6 7 8 9 10))
(newline)
OyMhL3Vzci9iaW4vcmFja2V0CjsjbGFuZyBzY2hlbWUKCjsgTGlzdCByZXZlcnNpbmcKKGRlZmluZSAocmV2ZXJzZSBscykKICAgICAgICAoZGVmaW5lIChpdGVyIHhzIHJlc3VsdCkKICAgICAgICAgICAgICAgIChpZiAobnVsbD8geHMpCiAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdAogICAgICAgICAgICAgICAgICAgICAgICAoaXRlciAoY2RyIHhzKSAoY29ucyAoY2FyIHhzKSByZXN1bHQpKSkpCiAgICAgICAgKGl0ZXIgbHMgJygpKSkKCihkZWZpbmUgKHNhbWUtcGFyaXR5IGEgLiB4cykKICAgICAgICAobGV0ICgocGFyaXR5IChpZiAob2RkPyBhKSBvZGQ/IGV2ZW4/KSkpCiAgICAgICAgICAgICAgICAoZGVmaW5lIChpdGVyIGl0ZW1zIHJlc3VsdCkKICAgICAgICAgICAgICAgICAgICAgICAgKGlmIChudWxsPyBpdGVtcykKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAocmV2ZXJzZSByZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKGl0ZXIgKGNkciBpdGVtcykKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChpZiAocGFyaXR5IChjYXIgaXRlbXMpKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoY29ucyAoY2FyIGl0ZW1zKSByZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdCkpKSkKICAgICAgICAgICAgICAgIChpdGVyIHhzIChsaXN0IGEpKSkpCgoKOyBUZXN0aW5nCihkaXNwbGF5IChzYW1lLXBhcml0eSAxIDIgMyA0IDUgNiA3IDggOSAxMCkpCihuZXdsaW5lKQo=