From what I gleaned from people who had used this test "in the wild", the single most neglected step was "or else, print the number." Pretenders (or not-paying-attention-to-details developers) would get so wrapped up in all of the exceptions that they'd forget the "else" condition at the end.
Just for fun, here's one you probably didn't expect... COBOL 85 or after. (imagine column 1 starts at column 8 if your compiler cares about that...)
edit: Holy cow, this code formatter knows COBOL! Disregard the note above...
identification division.
program-id. fizzbuzz.
environment division.
data division.
working-storage section.
77 nbr pic 9(3) value zero.
77 quotient pic 9(3) value zero.
77 rem pic 9(2) value zero.
procedure division.
begin.
perform varying nbr from 1 by 1 until nbr > 100
divide nbr by 15 giving quotient remainder rem
evaluate rem
when 0
display "FizzBuzz"
when 3
when 6
when 9
when 12
display "Fizz"
when 5
when 10
display "Buzz"
when other
display nbr
end-evaluate
end-perform.
stop run.
This outputs 002 for 2, but I'm not posting a completely correct FizzBuzz solution on the public Internet. Interviewers don't want memorizers, they want programmers. :)
He/Him/His
I'm a Software Engineer and a teacher.
There's no feeling quite like the one you get when you watch someone's eyes light up learning something they didn't know.
Guess that last part is left as an exercise for the reader (from my understanding, COBOL programmers don't have silly riddles in their interviews these days... :)
I'm less than 4 years from the end of my current employment, and need to decide what to do next. Helping prop up aging COBOL is on my list to consider. :)
To bring it into this century, here's an F# version...
From what I gleaned from people who had used this test "in the wild", the single most neglected step was "or else, print the number." Pretenders (or not-paying-attention-to-details developers) would get so wrapped up in all of the exceptions that they'd forget the "else" condition at the end.
Just for fun, here's one you probably didn't expect... COBOL 85 or after. (imagine column 1 starts at column 8 if your compiler cares about that...)
edit: Holy cow, this code formatter knows COBOL! Disregard the note above...
This outputs
002
for 2, but I'm not posting a completely correct FizzBuzz solution on the public Internet. Interviewers don't want memorizers, they want programmers. :)Oh wow! I was NOT expecting a COBOL solution ;)
Guess that last part is left as an exercise for the reader (from my understanding, COBOL programmers don't have silly riddles in their interviews these days... :)
I'm less than 4 years from the end of my current employment, and need to decide what to do next. Helping prop up aging COBOL is on my list to consider. :)
To bring it into this century, here's an F# version...
...although, technically, this separates them by commas rather than listing one per line.