Created
October 14, 2011 01:38
-
-
Save ympbyc/1286040 to your computer and use it in GitHub Desktop.
fibbuzz in JSLisp
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 fib (lambda (n) | |
(fib_in n 0 1))) | |
(define fib_in (lambda (n p1 p2) | |
(if (== n 0) | |
p1 | |
(fib_in (- n 1) (+ p1 p2) p1)))) | |
(define fibbuzz (lambda (n) | |
(if (>= (= a (fib n)) 1000) | |
(String a) | |
(if (== (% a 15) 0) | |
(+ "fizzbuzz, " (fibbuzz (+ n 1))) | |
(if (== (% a 5) 0) | |
(+ "buzz, " (fibbuzz (+ n 1))) | |
(if (== (% a 3) 0) | |
(+ "fizz, " (fibbuzz (+ n 1))) | |
(+ (String a) ", " (fibbuzz (+ n 1))))))))) | |
(display (fibbuzz 0)) |
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
var fib = function (n){ | |
return (fib_in)(n,0,1)}; | |
var fib_in = function (n,p1,p2){ | |
return (n == 0) ? p1 : (fib_in)((n - 1),(p1 + p2),p1)}; | |
var fibbuzz = function (n){ | |
return ((a = (fib)(n)) >= 1000) ? (String)(a) : ((a % 15) == 0) ? ("fizzbuzz, " + (fibbuzz)((n + 1))) : ((a % 5) == 0) ? ("buzz, " + (fibbuzz)((n + 1))) : ((a % 3) == 0) ? ("fizz, " + (fibbuzz)((n + 1))) : ((String)(a) + ", " + (fibbuzz)((n + 1)))}; | |
(display)((fibbuzz)(0)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment