Skip to content

Instantly share code, notes, and snippets.

@jumboly
Created April 9, 2012 14:21
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 jumboly/2343760 to your computer and use it in GitHub Desktop.
Save jumboly/2343760 to your computer and use it in GitHub Desktop.
FizzBuzz 2012/04/09
(define range
(lambda (start count)
(cond
((<= count 0) '())
(else (cons start (range (+ start 1) (- count 1)))))))
(define map
(lambda (f l)
(cond
((null? l) '())
(else (cons (f (car l)) (map f (cdr l)))))))
(define fizz?
(lambda (n)
(= (mod n 3) 0)))
(define buzz?
(lambda (n)
(= (mod n 5) 0)))
(define fizzbuzz?
(lambda (n)
(and (fizz n) (buzz n))))
(define fizzbuzz
(lambda (n)
(map (lambda (i)
(cond
((fizzbuzz? i) 'FizzBuzz)
((fizz? i) 'Fizz)
((buzz? i) 'Buzz)
(else i)))
(range 1 n))))
(fizzbuzz 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment