Skip to content

Instantly share code, notes, and snippets.

@underhilllabs
Last active January 18, 2016 03:51
Show Gist options
  • Save underhilllabs/6108908 to your computer and use it in GitHub Desktop.
Save underhilllabs/6108908 to your computer and use it in GitHub Desktop.
Fizzbuzz in emacs lisp. It works!
(defun fizzbuzz ()
"Fizzbuzz written in elisp. Count from 1 to 100, replacing numbers mod 3 with fizz, mod 5 with buzz,
and mod 3 and mod 5 with Fizzbuzz."
(interactive)
(insert "let's start this fizzbuzzin up!\n")
(mapcar (lambda (num)
(cond
;; if ((x % 3 == 0) && (x % 5 == 0))
((and (= (% num 3) 0) (= (% num 5) 0))
(insert "fizzbuzz\n"))
((= (% num 3) 0)
(insert "fizz\n"))
((= (% num 5) 0)
(insert "buzz\n"))
;; default
(t
(insert (format "%s\n" num)))))
;; range(1, 100)
(number-sequence 1 100)))
@underhilllabs
Copy link
Author

  1. cut and paste into *Scratch*
  2. C-xC-e after the definition
  3. M-x fizzbuzz

@LandonPowell
Copy link

Now let's see vim do that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment