Created
November 24, 2011 04:32
-
-
Save jrheard/1390621 to your computer and use it in GitHub Desktop.
fizzbuzz
This file contains hidden or 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 range(1, 100): | |
line = "" | |
if i % 3 == 0: | |
line += "Fizz" | |
if i % 5 == 0: | |
line += "Buzz" | |
if line == "": | |
line = str(i) | |
print line |
without a loop? as in recursively? or as in
print 1
print 2
print "fizz"
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
in my interviews I have them do this, then I have them do it without a loop.