Skip to content

Instantly share code, notes, and snippets.

@nilsnh
Last active December 13, 2015 20:58
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 nilsnh/4974250 to your computer and use it in GitHub Desktop.
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
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}"
@nilsnh
Copy link
Author

nilsnh commented Feb 18, 2013

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

@snorremd
Copy link

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

@Torthu
Copy link

Torthu commented Feb 18, 2013

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);
}

@Torthu
Copy link

Torthu commented Feb 18, 2013

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);

@snorremd
Copy link

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)

@nilsnh
Copy link
Author

nilsnh commented Feb 18, 2013

Aktiv Gist dette her. ^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment