Last active
December 19, 2015 17:39
-
-
Save yshl/5992982 to your computer and use it in GitHub Desktop.
FizzBuzz in Scheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (fizzbuzz n c) | |
((lambda(d m g) | |
(g g 1 | |
(lambda(l) | |
(m m l | |
(lambda(i c) | |
(d i 15 | |
(lambda(b) | |
(if b | |
(c "FizzBuzz") | |
(d i 5 | |
(lambda(b) | |
(if b | |
(c "Buzz") | |
(d i 3 | |
(lambda(b) | |
(if b | |
(c "Fizz") | |
(c i))))))))))) | |
(lambda(l) | |
(m m l | |
(lambda(i c) | |
(c (print i))) | |
c)))))) | |
(lambda(m n c) | |
(c (zero? (modulo m n)))) | |
(lambda(m l f c) | |
(if (pair? l) | |
(f (car l) | |
(lambda(i) | |
(m m (cdr l) f | |
(lambda(l) | |
(c (cons i l)))))) | |
(c '()))) | |
(lambda(g i c) | |
(if (<= i n) | |
(g g (+ i 1) | |
(lambda(l) | |
(c (cons i l)))) | |
(c '()))))) | |
(call/cc | |
(lambda(c) | |
(fizzbuzz 100 c))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use srfi-1) ; for iota | |
(define (map-cpsfun fun lis) | |
(if (pair? lis) | |
(fun (car lis) | |
(lambda(elem) | |
(cons elem (map-cpsfun fun (cdr lis))))) | |
'())) | |
(define (fizzbuzz n) | |
(map-cpsfun | |
(lambda(i cont) | |
((lambda(printi) | |
(if (zero? (modulo i 5)) | |
(cont (print "Buzz")) | |
(printi (lambda(cont2) (cont cont2))))) | |
(if (zero? (modulo i 3)) | |
(begin (display "Fizz") | |
(lambda(c) (c (print "")))) | |
(lambda(c) (c (print i)))))) | |
(iota n 1))) | |
(fizzbuzz 100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment