Last active
December 13, 2015 20:58
-
-
Save nilsnh/4974250 to your computer and use it in GitHub Desktop.
Coffee-script fizzbuzz. Just had to try and make one after reading this: http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html
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
for i in [1..100] | |
if i % 3 is 0 and i % 5 is 0 then console.log "FizzBuzz" | |
else if i % 3 is 0 then console.log "Fizz" | |
else if i % 5 is 0 then console.log "Buzz" | |
else console.log "#{i}" |
Just to examplify how sarily similar the Python-implementation is:
for i in range(1,101):
if i % 3 == 0 and i % 5 == 0: print "FizzBuzz"
elif: i % 3 == 0: print "Fizz"
elif: i % 5 == 0: print "Buzz"
else: print i
Plain 'ol Javascript just for the heck of it
for(var i = 1;i <= 100;i++) {
if(i % 3 == 0 && i % 5 == 0) console.log('FizzBuzz');
else if(i % 3 == 0) console.log('Fizz');
else if(i % 5 == 0) console.log('Buzz');
else console.log(i);
}
Let's over engineer it
(function fizzbuzz(i, iterations) {
if(i % 3 == 0 && i % 5 == 0) console.log('FizzBuzz');
else if(i % 3 == 0) console.log('Fizz');
else if(i % 5 == 0) console.log('Buzz');
else console.log(i);
if(i < iterations) fizzbuzz(i+1, iterations);
})(1, 100);
La oss ta et rekursivt eksempel, because:
def fizzbuzz(n):
if(n > 100): pass
if i % 3 == 0 and i % 5 == 0: print "FizzBuzz"
elif: i % 3 == 0: print "Fizz"
elif: i % 5 == 0: print "Buzz"
else: print i
fizzbuzz(n+1)
fizzbuzz(1)
Aktiv Gist dette her. ^_^
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Regarding the article I linked to above I'm sure this would be harder to implement during an interview situation, where you have a tech lead breathing down your neck. -_o