FizzBuzz
A collection of ways to solve the FizzBuzz problem
Simple Rules
Simple Rules
To replace multiples of 3 with Fizz, multiples of 5 with Buzz, and multiples of both 3 and 5 with FizzBuzz...
awk
awk
seq 1 100 | awk '$0=NR%15?NR%5?NR%3?$0:"Fizz":"Buzz":"FizzBuzz"'
sed
sed
seq 1 100 | sed '0~3s/.*/Fizz/;0~5s/[0-9]*$/Buzz/'
This is actually a bit of a cheat as it just prints Fizz or Buzz based on position not actual number. I.e. if you start the sequence from any number other than 1, it doesn't work.
seq 1 100 | ./fizzbuzz.sed
bash
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
Python
seq 1 100 | ./fizzbuzz.py
seq 1 100 | ./fizzbuzz1.py
PL/SQL
PL/SQL
SQL
SQL
Alternate Rules
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
bash
seq 1 100 | ./fizzbuzz2.sh
Python
Python
seq 1 100 | ./fizzbuzz2.py
Bibliography
Bibliography
https://en.wikipedia.org/wiki/Fizz_buzzhttps://www.byrdseed.com/fizz-buzz-a-divisibility-game/https://dev.to/taw/100-languages-speedrun-episode-07-sed-and-regular-expression-fizzbuzz-23l9http://philcrissman.net/posts/eulers-fizzbuzz/https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition/tree/uinversehttps://www.rosettacode.org/wiki/FizzBuzz/AWKhttps://www.rosettacode.org/wiki/FizzBuzzhttps://web.archive.org/web/20160805202854/http://cocktails.about.com/od/partiesholidays/p/biz_buz_gm.htm