I subscribe to a blog called Quora.  You can set filters on what sort of questions are presented. I’ve set them to show math, physics, and computer science posts.

Today I saw a post that asked if someone with an advanced degree in computer science could fail the “Fizz Buzz Test“.

I had no idea what this test was so I did a Google Search on the words “fizzbuzz test” and came up with a wikipedia page dedicated to the game which also mentions the test (here is the page).

After reading the article section named “Other Uses” and messing around with a python script today I can safely say I do fall into the category of someone who has used this game as a “Software Kata

Here is what I’ve done so far.  And, in my defense, I did start out with a VERY SIMPLE version of this game and it sort of “grew-like-topsy” to what you see below.

I’ve used the WordPress tags to embed the code below.  So this blog post not only talks about the Fizz Buzz Test but also gives a demonstration of how source code embedding works on WordPress.

# Fizz Buzz (beep) Script
import os

def sayIt( anIndex, aCount, phrase):
  indexString = "The "+str(aCount)
  if aCount >= 11 and aCount <= 20:
    indexString += 'th'
  elif aCount % 10 == 1:
    indexString += 'st'
  elif aCount % 10 == 2:
    indexString += 'nd'
  elif aCount % 10 == 3:
    indexString += 'rd'
    indexString += 'th'
  indexString += ' element is '+str(anIndex)+' and we say '+phrase
  os.system("say " +indexString)

def findPhrase( index, fizzNumber, buzzNumber, beepNumber ):
  newNumber = index
  thePhrase = ''
  if fizzNumber != 0:
    while newNumber % fizzNumber == 0:
      thePhrase += 'FIZZ '
      newNumber = newNumber / fizzNumber
  if buzzNumber != 0:
    while newNumber % buzzNumber == 0:
      thePhrase += 'BUZZ '
      newNumber = newNumber / buzzNumber
  if beepNumber != 0:
    while newNumber % beepNumber == 0:
      thePhrase += 'BEEP '
      newNumber = newNumber / beepNumber
  return thePhrase

def fizzBuzzBeep(maxCount, fizzNumber, buzzNumber, beepNumber):
  count = 0
  index = 1
  while (count<maxCount):
    aPhrase = findPhrase( index, fizzNumber, buzzNumber, beepNumber )
    if len(aPhrase) != 0:
      count +=1
      print("{0:3d} - {1:3d} {2}".format(count, index, aPhrase))
      sayIt( index, count, aPhrase)
    index +=1

if __name__ == '__main__':
  fizzBuzzBeep(100, 3, 5, 7)