Skip to content

Instantly share code, notes, and snippets.

Created July 20, 2014 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5233a7e836f15be227a5 to your computer and use it in GitHub Desktop.
Save anonymous/5233a7e836f15be227a5 to your computer and use it in GitHub Desktop.
(defn build-words [chain]
(loop [words []]
(if (= (count words) 5)
words
(if (empty? words)
(let [[word next-words] (rand-nth (seq chain))
next-word (rand-nth next-words)]
(recur (conj words word next-word)))
(let [last-word (last words)
next-words (get chain last-word)]
(if (nil? next-words)
words
(recur (conj words (rand-nth (seq next-words))))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment