EmacsLisp版を追加
authorj8takagi <info@j8takagi.net>
Sun, 28 Oct 2012 14:01:37 +0000 (23:01 +0900)
committerj8takagi <info@j8takagi.net>
Sun, 28 Oct 2012 14:03:08 +0000 (23:03 +0900)
emacslisp/.gitignore [new file with mode: 0644]
emacslisp/fizzbuzz.el [new file with mode: 0644]

diff --git a/emacslisp/.gitignore b/emacslisp/.gitignore
new file mode 100644 (file)
index 0000000..c531d98
--- /dev/null
@@ -0,0 +1 @@
+*.elc
diff --git a/emacslisp/fizzbuzz.el b/emacslisp/fizzbuzz.el
new file mode 100644 (file)
index 0000000..a2e18c2
--- /dev/null
@@ -0,0 +1,19 @@
+;; fizzbuzz.el
+;; ターミナルで「emacs --batch --script fizzbuzz.el」を実行
+(defun fizzbuzz (num)
+  (let
+      ((fizz (= (% num 3) 0))
+       (buzz (= (% num 5) 0)))
+    (cond
+     ((and fizz buzz) "FizzBuzz")
+     (fizz "Fizz")
+     (buzz "Buzz")
+     (t num))))
+
+(let
+    (i (min 1) (max 100))
+  (setq i min)
+  (while (<= i max)
+    (princ (fizzbuzz i))
+    (princ "\n")
+    (setq i (1+ i))))