FizzBuzz In 3 Acts
Learning to code was full of learning moments. One that I look back upon fondly was when I did the Flatiron lesson on...
For further actions, you may consider blocking this person and/or reporting abuse
Another one of the scalability aspects that we can explore is that what if the game wont stop at just 2 denominators (e.g. If I add 7 to the game, so for numbers multiple of 3 print Fizz, multiple of 5 print Buzz, multiple of 15 (3 and 5) print FizzBuzz, multiple of 35 (5 and 7) print BuzzBazz, multiple of 21 (3 and 7) print FizzBazz, and multiple of 105 (3 and 5 and 7) print FizzBuzzBazz). How we would go about scale it up on this aspect is to make use of hashmap, iterating through the map to determine the output. Here is the implementation in Go:
Here is the solution in js
Nice, I never thought of scaling it in that direction.
I like the idea of using a Hash.
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
002for 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.