Live data from Hacker News

Fizz Buzz without conditionals or booleans

evanhahn.com

71–72 of 72 posts

Re: Fizz Buzz without conditionals or booleans

#71
post #33
post #28

Earlier quoted context omitted.

A loop either never halts or has a conditional. I guess a compiler could elide a “while True:” to a branch-less jump instruction. One hack would be to use recursion and let stack exhaustion stop you.

Other would be to use goto (though Python doesn't have it) & introduce something that will panic/throw exception, like creating variable with value 1/(max-i).

Recursion would work for that, you don't need goto.

The division by zero trick is pretty good too!

Re: Fizz Buzz without conditionals or booleans

#72
post #70

Earlier quoted context omitted.

That is in arbitrary line I am willing to draw in the battle against pedantry. Surely though a fizzbuzz isn't supposed to run forever though right? Gotta end it somehow, and the for loop is idiomatic.

It's a challenge and you can do whatever version you want. If I'm pedantring about it it's because it can be done with a stricter restriction (or at least I think it can be done). I'd also add that it isn't a particularly hard problem, so I would recommend that if you are having trouble with solving for the hardest interpretation of the problem, that you keep on trying because there is quite a simple solution. If I w…

You got me. I'd surely fail your interview. I admit I know nothing about CPU comparisons and conditional jumps.
Post reply on HN