Skip to content

Instantly share code, notes, and snippets.

@rsslldnphy
Last active August 29, 2015 14:06
Show Gist options
  • Save rsslldnphy/1a4ef4535d9ad889b968 to your computer and use it in GitHub Desktop.
Save rsslldnphy/1a4ef4535d9ad889b968 to your computer and use it in GitHub Desktop.
(ns coins)
(def heads (repeat 50 :H))
(def tails (repeat 50 :T))
(def flip {:H :T :T :H})
(defn permutation [n]
[(concat (take n heads) (drop n tails))
(concat (drop n heads) (take n tails))])
(defn count-coins
[face coins]
(count (filter #{face} coins)))
(if (every? true? (map (fn [n]
(let [[left right] (permutation n)]
(= (count-coins :T (map flip left))
(count-coins :T right))))
(range 51)))
(println "Looks like it works for all combinations!")
(println "Looks like you win, sir wobin...."))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment