Skip to content

Instantly share code, notes, and snippets.

@jrheard
Created November 24, 2011 04:32
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 jrheard/1390621 to your computer and use it in GitHub Desktop.
Save jrheard/1390621 to your computer and use it in GitHub Desktop.
fizzbuzz
for i in range(1, 100):
line = ""
if i % 3 == 0:
line += "Fizz"
if i % 5 == 0:
line += "Buzz"
if line == "":
line = str(i)
print line
@jeffmicklos
Copy link

in my interviews I have them do this, then I have them do it without a loop.

@jrheard
Copy link
Author

jrheard commented Nov 29, 2011

without a loop? as in recursively? or as in

print 1
print 2
print "fizz"

@jeffmicklos
Copy link

I have had people that want to do it manually but yeah, recursion is the right answer here...

var iterator = function iterator(num) {
// modulo stuff here
// eventually call recursively:
iterator(num++);
}(0);

Another thing that is fun to ask is "write a for loop in every language on your resume."
The response you get from that is often kind of scary...

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