# [racket] sicp exercise 2.20

 From: Martin DeMello (martindemello at gmail.com) Date: Tue Jul 20 11:20:57 EDT 2010 Previous message: [racket] sicp exercise 2.20 Next message: [racket] sicp exercise 2.20 Messages sorted by: [date] [thread] [subject] [author]

```Ah, nice :) Thanks!

martin

On Tue, Jul 20, 2010 at 8:39 PM, Jos Koot <jos.koot at telefonica.net> wrote:
> Yet another one using -apply-:
>
> (define (same-parity x . xs)
>  (cond
>   ((null? xs) (list x))
>   ((equal? (even? x) (even? (car xs))) (cons x (apply same-parity xs)))
>   (else (apply same-parity x (cdr xs)))))
>
> Jos
>
>> -----Original Message-----
>> From: users-bounces at racket-lang.org
>> [mailto:users-bounces at racket-lang.org] On Behalf Of Martin DeMello
>> Sent: 20 July 2010 15:37
>> To: PLT-Scheme Mailing List
>> Subject: [racket] sicp exercise 2.20
>>
>> By way of a puzzle, I've been trying to solve SICP exercise 2.20
>> ----------------------------
>> Using the (define (f x . args)) notation, write a procedure
>> "same-parity" that takes one or more integers and returns a
>> list of all the arguments that have the same even-odd parity
>> as the first argument. For example, (same-parity 1 2 3 4 5 6 7)
>> (1 3 5 7)
>> (same-parity 2 3 4 5 6 7)
>> (2 4 6)
>> ----------------------------
>> using "straight recursion", that is, without using any `let`
>> or `define` constructs. Still not managed to find the trick
>> that will tack on the first argument as the head of the list.
>> Anyone have a hint?
>>
>> martin
>> _________________________________________________