FizzBuzz

This Kata was posted by someone anonymously. Michael Feathers and EmilyBache performed it at agile2008 when competing in “Programming with the stars” in python, in 4 minutes.

Difficulty: Easy, good for teaching: TDD, BabySteps, TheSimplestThingThatCouldPossiblyWork, HurryToGreen, Refactor and CodeSmells.

Yellow belt

  • List the numbers from 1 to 100.
  • If the number is divisible by 3, write “Fizz” instead.
  • If the number is divisible by 5, write “Buzz” instead
  • If the number is divisible by both 3 and 5, write “FizzBuzz”.
  • If the number is not divisible neither by 3 nor 5, write the string representation of the number.

Sample code:

1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16

Green belt

  • A number is fizz if it is divisible by 3 or if it has a 3 in it.
  • A number is buzz if it is divisible by 5 or if it has a 5 in it.

Sample code:

1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz Fizz 14 FizzBuzz 16

Red belt

  • Dinamically define range of numbers in the list.
  • Make system case-insensitive.
  • Do not use primitives.

Black belt

  • Do not use conditionals.
  • Use methods (no returns).
  • Apply solid to dead.