Last active
August 29, 2015 14:06
-
-
Save rsslldnphy/1a4ef4535d9ad889b968 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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