Fizzbuzz

2012-09-03

So I recently went back to the Newgrounds programming Forum and an interesting topic appeared; called FizzBuzz -- described as:

"FizzBuzz is program used to test if a programmer can even write a simple program. Basically, you print numbers 1 - 100, print Fizz on numbers divisible by 3, print Buzz on numbers divisible by 5 and FizzBuzz on numbers divisible by 3 and 5.

Hard mode: Do it without using the Modulos operator.

God mode: Do it without the division operator."

So here is my attempt using BASH:

~~~~
#!/bin/bash
for count in {1..100}; do
        echo -ne $count" "
        for d3 in {1..33}; do
                div3=$(($d3*3))
                if [[ $div3 == $count ]]; then
                        fizz="FIZZ"
                else
                        fizz=""
                fi
                echo -ne $fizz
        done
        for d5 in {1..20}; do
                div5=$(($d5*5))
                if [[ $div5 == $count ]]; then
                        buzz="BUZZ"
                else
                        buzz=""
                fi
                echo -ne $buzz
        done
        echo -ne "\n"
done
~~~~
You can find my post -- and lots of other very good ones in the thread: http://www.newgrounds.com/bbs/topic/1316032

(My username on newgrounds is "urbn").