シェルスクリプト版を作成
authorj8takagi <info@j8takagi.net>
Sun, 28 Oct 2012 16:48:40 +0000 (01:48 +0900)
committerj8takagi <info@j8takagi.net>
Sun, 28 Oct 2012 16:48:40 +0000 (01:48 +0900)
sh/fizzbuzz.sh [new file with mode: 0755]

diff --git a/sh/fizzbuzz.sh b/sh/fizzbuzz.sh
new file mode 100755 (executable)
index 0000000..2b009c9
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+MIN=1
+MAX=100
+
+fizzbuzz() {
+    unset FIZZ;
+    unset BUZZ;
+    if test $(expr $1 % 3) -eq 0; then
+        FIZZ="Fizz";
+    fi
+    if test $(expr $1 % 5) -eq 0; then
+        BUZZ="Buzz";
+    fi
+    if test -z ${FIZZ} && test -z ${BUZZ}; then
+        echo $1;
+    else
+        echo ${FIZZ}${BUZZ};
+    fi
+}
+
+for i in $(seq ${MIN} ${MAX}); do
+    fizzbuzz $i
+done