Skip to content

Instantly share code, notes, and snippets.

@khirotaka
Last active January 4, 2020 12:10
Show Gist options
  • Save khirotaka/8b33ad0593778afce2a0b1d96bc50b03 to your computer and use it in GitHub Desktop.
Save khirotaka/8b33ad0593778afce2a0b1d96bc50b03 to your computer and use it in GitHub Desktop.
Bash で FizzBuzzをするコード。Bashの練習のため
#!/bin/zsh
function fizzbuzz () {
if [ $(( $1 % 15 )) -eq 0 ]; then
echo FizzBuzz
elif [ $(( $1 % 3 )) -eq 0 ]; then
echo Fizz
elif [ $(( $1 % 5 )) -eq 0 ]; then
echo Buzz
else
echo $1
fi
}
function main() {
for i in $(seq 1 $1); do
fizzbuzz $i
done
}
main $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment