Welcome, guest | Sign In | My Account | Store | Cart

This is my version of the FizzBuzz test.

Bash, 26 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash -   
#title          :fizzbuzz.sh
#description    :Pass the fizzbuzz test. Get that job.
#author         :bgw
#date           :20111031
#version        :0.1    
#usage          :./fizzbuzz.sh
#notes          :       
#bash_version   :4.1.5(1)-release
#==============================================================================

for n in {1..100} ; do
    if [ $(expr $n % $((5*3))) -eq 0 ] ; then
        echo FizzBuzz
        sleep 1
    elif [ $(expr $n % 5) -eq 0 ] ; then 
        echo Buzz
        sleep 1
    elif [ $(expr $n % 3) -eq 0 ] ; then 
        echo Fizz
        sleep 1
    else
        echo $n
        sleep 1
    fi
done

After hearing about the fizzbuzz test I had to try it out myself. Did I pass?