Skip to content

Instantly share code, notes, and snippets.

@ipwnponies
Last active January 9, 2019 18:55
Show Gist options
  • Save ipwnponies/33f48cc03665a289055e158f20130ca7 to your computer and use it in GitHub Desktop.
Save ipwnponies/33f48cc03665a289055e158f20130ca7 to your computer and use it in GitHub Desktop.
Fizzbuzz in different languages

What is this

Fizzbuzz in different languages

Why does this even exist

Someone once declined to write fizzbuzz because they had recently only been doing shell programming. And, therefore, my request was invalid and unfair since it's not a real language.

So, for funsies, I'm going to demonstrate that you can write fizzbuzz in turing complete languages. Not an incredible feat, more of a refutation of said argument.

#!/usr/bin/fish
function modulo
set dividend $argv[1]
set modulo $argv[2]
math $dividend \% $modulo
end
for i in (seq 1 100)
if test (modulo $i 3) -eq 0; and test (modulo $i 5) -eq 0;
echo fizzbuzz
else if test 0 -eq (modulo $i 3)
echo fizz
else if test 0 -eq (modulo $i 5)
echo buzz
else
echo $i
end
end
#!/bin/bash
modulo () {
local dividend=$1
local modulo=$2
echo $dividend % $modulo | bc
}
for i in $(seq 1 100);
do
if [ $(modulo $i 3) -eq 0 ] && [ $(modulo $i 5) -eq 0 ]
then
echo fizzbuzz
elif test 0 -eq $(modulo $i 3); then
echo fizz
elif test 0 -eq $(modulo $i 5); then
echo buzz
else
echo $i
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment