Skip to content

Instantly share code, notes, and snippets.

@qcom
Last active December 27, 2015 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qcom/7257781 to your computer and use it in GitHub Desktop.
Save qcom/7257781 to your computer and use it in GitHub Desktop.
return the elements of a list with an odd index (1, 3, 5, etc.)
(define (odds lis)
(reverse (odds-reduce lis '())))
(define (odds-reduce l1 l2)
(cond
((null? l1) l2)
((= (length l1) 1) (cons (car l1) l2))
(else (odds-reduce (cddr l1) (cons (car l1) l2)))
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment