Skip to content

Instantly share code, notes, and snippets.

@akagr
Created July 7, 2021 15:39
Show Gist options
  • Save akagr/f728c58c530f24ca3a0b58e93aa40087 to your computer and use it in GitHub Desktop.
Save akagr/f728c58c530f24ca3a0b58e93aa40087 to your computer and use it in GitHub Desktop.
functional fizz buzz in emacs lisp
(defun divisible (a b)
(equal 0 (% a b)))
(defun to_s (item) (format "%s" item))
(defun fizzbuzz (num)
(let* ((fizz (if (divisible num 3) "fizz" ""))
(buzz (if (divisible num 5) "buzz" ""))
(combi (concat fizz buzz))
(result (if (length> combi 0) combi (to_s num))))
(message result)))
(mapcar 'fizzbuzz (number-sequence 1 50))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment