Last active
September 26, 2015 15:28
-
-
Save kgadek/1119119 to your computer and use it in GitHub Desktop.
Clojure: 99 bottles (II)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns org.gadek.fun.bottles) | |
(defn bottle-cnt [stock] | |
(str (if (zero? stock) "No more" stock) | |
" bottle" (when (not (= 1 stock)) "s") | |
" of beer")) | |
(defn verses [& [stock prev]] | |
(lazy-seq (let [stock (or stock 0) ; start from 0 | |
prev (or prev (bottle-cnt 99)) ; even earlier -- 99 bottles | |
num-bottles (bottle-cnt stock) ; hey, joe! how many bottles? | |
command (if (zero? stock) ; what to do with it? | |
"Go to the store and buy some more" | |
"Take one down and pass it around")] | |
(cons (str num-bottles " on the wall, " (.toLowerCase num-bottles) ".\n" | |
command ", " (.toLowerCase prev) " on the wall.\n\n") | |
(verses (inc stock) (bb stock)))))) | |
(def sing #(->> (verses) (take 100) reverse (apply str) println)) | |
; take 100 verses (0->99), reverse them (99->0), join and print it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment