Jul 22, 2011

FizzBuzz!

Saw an interesting article in thedailywtf that referred to FizzBuzz in the comments section. There is a test called FizzBuzz, based on the UK math book of math story problems.


Write a program that prints the numbers from 1 to 100.
But for multiples of three print "Fizz" instead of the
number and for the multiples of five print "Buzz". For
numbers which are multiples of both three and five print
"FizzBuzz".


Here's my javascripted solution. It took all of 4 minutes using TextWrangler and Safari, including limited HTML. HTML4 only sorry, another 10 minutes to get validated HTML5! (That should be part of the requirement!)

Yes, I realize if you were concerned about the number of rows, I'd make the output into an array and join("") on it instead of the slower string concatenation, but this has the "less than 256 bytes" or so feel to it, so I'm not going to spend time on string manipulation.

No comments:

Post a Comment