4 ms·
I honestly don't know if it's the mathematician in me, or if I'm just a cranky person, or if I actually have a valid point, but if I were given the FizzBuzz tas
by thebear 12y ago
I honestly don't know if it's the mathematician in me, or if I'm just a cranky person, or if I actually have a valid point, but if I were given the FizzBuzz task the way it is worded here, I would reject it on the grounds that it is self-contradictory:
'for multiples of three print “Fizz” instead of the number [...]. For numbers which are multiples of both three and five print “FizzBuzz”'
So for the number 15, for example, I am being asked to print "Fizz" instead of the number, but I am also asked to print "FizzBuzz". That cannot be done. A valid way of formulating the problem would be:
Write a program that prints the numbers from 1 to 100. But for multiples of three that are not multiples of five print “Fizz” instead of the number, and for multiples of five that are not multiples of three print “Buzz” instead of the number. For numbers which are multiples of both three and five print “FizzBuzz” instead of the number.
An alternate way of saying it would be:
Write a program that prints the numbers from 1 to 100, except for numbers that are multiples of three or five. For multiples of three print “Fizz”. For multiples of five print “Buzz”.
(Edit: no, the above doesn't work, because it would allow you to print "BuzzFizz" for numbers like 15. You'd still have to add, 'For numbers which are multiples of both three and five, print “FizzBuzz”.' So it's really just the clause "instead of the number" in the original formulation that causes the contradiction.)
- mcv 12y agoIt's still a good test. I wouldn't hire you if you insist on making a problem out of something you understand perfectly well.