two paths to the same buzz

Let’s talk about how we get to two different solutions for the game FizzBuzz.

Solution 1

Solution 2

The first solution uses a while loop to iterate through numbers 1 to 100. Using if/elsif control flow, we achieve the desired outcome of fizz for numbers divisible by 3, buzz for numbers divisible by 5, and fizzbuzz for numbers divisible by both 5 and 3.

The second solution employs the each method on range 1..100, storing the various instances of divisibility by 3 & 5 in two variables: m3 & m5. Next, the uses a case statement (as the condition of the iterator) to print out the values fizz, buzz, fizzbuzz, or i.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s