FizzBuzz
A collection of ways to solve the FizzBuzz problem
Simple Rules
To replace multiples of 3 with Fizz, multiples of 5 with Buzz, and multiples of both 3 and 5 with FizzBuzz...
awk
seq 1 100 | awk '$0=NR%15?NR%5?NR%3?$0:"Fizz":"Buzz":"FizzBuzz"'
seq 1 100 | awk '($0%3 > 0) && ($0%5 > 0) {print; next} $0%3 == 0 {printf "fizz"} $0%5 == 0 {printf "buzz"} {printf "\n"}'Â Â
sed
seq 1 100 | sed '0~3s/.*/Fizz/;0~5s/[0-9]*$/Buzz/'
seq 1 100 | ./fizzbuzz.sed
bash
seq 1 100 | while read -r i;do((i%3))&&x=||x=Fizz;((i%5))||x+=Buzz;echo ${x:-$i};done
seq 1 100 | ./fizzbuzz.sh
Python
seq 1 100 | ./fizzbuzz.py
seq 1 100 | ./fizzbuzz1.py
PL/SQL
SQL
Alternate Rules
When we played FizzBuzz, there was an additional rule... not just multiples of 3 and 5, but also any numbers containing 3 or 5...
bash
seq 1 100 | ./fizzbuzz2.sh
Python
seq 1 100 | ./fizzbuzz2.py