News & Articles:

Kata: Fizz Buzz

A widespread Code Kata involves generating a “Cheat Sheet” for the popular maths game “Fizz Buzz”.

Introduction

The game of Fizz Buzz works like this.  The game is played by a number of players, sitting in a circle, in competition with each other. The first player starts to count at 1, is followed by the second, and so on around the circle. Counting proceeds normally except that any number exactly divisible by 3 is replaced with “Fizz”, and any number divisible by 5 is replaced with “Buzz”. A number divisible by both is (excitingly) replaced with “FizzBuzz”. A player who misses a Fizz or a Buzz, or Fizzes (or Buzzes) in the wrong place, is out of the game.

Task

Write a program that prints a “Cheat Sheet” for the children’s game of “Fizz Buzz”. The cheat sheet should print the first 100 terms in 5 neatly formatted columns. Each term should be a number, “Fizz”, “Buzz” or “FuzzBuzz”.

Variations

Instead of being *divisible* by 3, a number is a “Fizz” if it *contains* a 3. Likewise for 5 and “Buzz”. Note that 35 and 53 are “FizzBuzz”.

Finally, combine the two above. So a number is “Fizz” if it is divisible by 3 or if it contains a 3.

Creative Commons Licence
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Posted in Technical

Tags: , ,