Created
September 4, 2012 00:04
-
-
Save djanatyn/3615071 to your computer and use it in GitHub Desktop.
build list of all possible results of flipping coins
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
(defn split-list [coin-flips] | |
"returns two lists - one with heads added, and one with tails added" | |
(let [add-to-front (fn [coll x] (concat coll [x]))] | |
(list (add-to-front coin-flips 'heads) | |
(add-to-front coin-flips 'tails)))) | |
(defn list-possible-sequences [num-flips] | |
(loop [result '((heads) (tails)) | |
count num-flips] | |
(if (= count 1) result | |
(recur (apply concat (map split-list result)) (- count 1))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment