Build a FizzBuzz program that stores the FizzBuzz data in a hash data structure.
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", and for values that are multiples of three and five print out "FizzBuzz". - Interview Question Specification by Tom Dalling
hashed_fizz_buzz 25 { 1=>1, 2=>2, 3=>"Fizz", 4=>4, 5=>"Buzz", 6=>"Fizz", 7=>7, 8=>8, 9=>"Fizz", 10=>"Buzz", 11=>11, 12=>"Fizz", 13=>13, 14=>14, 15=>"FizzBuzz", 16=>16, 17=>17, 18=>"Fizz", 19=>19, 20=>"Buzz", 21=>"Fizz", 22=>22, 23=>23, 24=>"Fizz", 25=>"Buzz" }
This is one of the most popular coding interview questions. This is due to the fact that it tests:
With that in mind, it's an important set of concepts to understand. If you are not able to build this exercise without Googling the answer you may want to consider reviewing these concepts. I purposefully left out any advanced Ruby code so it can be as easy to read as possible.
Can be found on the solutions branch on github.
I've been a software engineer for the past decade and have traveled the world building applications and training individuals on a wide variety of topics.