Write a program that counts from 1 to 100 but replaces any number divisible by three with the word "Fizz" and any number divisible by five with the word "Buzz". If a number is divisible by both, three and five, the program should replace it with "FizzBuzz".

The program output should look like this: 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, ...

An interesting fact about the Fizz Buzz problem is that it is commonly used as a job interview question that helps ruling out more than 95% of programmer candidates. Allegedly, the problem is so hard for many people because its solution doesn't follow any of the standard patterns taught in schools.

Get solution

Implement a base-*n* counter for any *n* between 2 and 10.

Base-*n* counting is like usual counting except that you use a different number of digits. Basically, each counting step starts by incrementing the rightmost digit by one. If the digit cannot be incremented any further, the digit is set back to zero, and its left nearest neighbor is incremented by one. This continues until either a digit can be incremented or all the digits are set back to zero and the digit 1 is added to the left of the counter.

For example, a base-2 (binary) counter counts like:
0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, ...

A base-4 counter would go as:
0, 1, 2, 3, 10, 11, 12, 13, 20, 21, 22, 23, 30, 31, 32, 33, 100, 101, 102, 103, 110, ...

In everyday counting we use a base-10 (decimal) counting:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ...

Hint: You can convert any base-10 number to its base-*n* representation by simply collecting all the remainders of consecutive divisions of that number by *n*.

Get solution