FizzBuzz Implementation

By: Nathan Dekeyrel

What This Program Does

This program implements the classic FizzBuzz problem with a twist. It prints numbers from 1 to n, but:

Implementation Approach

Fizzbuzz itself is a fairly straightforward problem. It can be solved using a couple if-statements in a loop to check a set of rules. A common follow-up to this problem is seeing how a programmer would modify their code to handle changes to the rules. My implementation uses a dictionary/map to store the rules. This design choice provides:

How to Run

The program can be run using the provided shell script:

For example:

./run.sh 15

The shell script executes the following command:

python main.py 15

Example Output

Running ./run.sh produces:

1
2
Bob
4
Cat
Bob
7
8
Bob
Cat
11
Bob
13
14
BobCat

API

This solution is also available via an API. You can spin up a local server using

python app.py
Then, in another terminal window, run
curl http://localhost:5000/fizzbuzz
to get back:


  "result": [
    "1",
    "2",
    "Bob",
    "4",
    "Cat",
    "Bob",
    "7",
    "8",
    "Bob",
    "Cat",
    "11",
    "Bob",
    "13",
    "14",
    "BobCat"
  ]
    

You can also pass an optional argument like curl http://localhost:5000/fizzbuzz?number=5 to get back:


  "result": [
    "1",
    "2",
    "Bob",
    "4",
    "Cat"
  ]
    

Back