Created
February 16, 2014 19:29
-
-
Save KushalP/9039352 to your computer and use it in GitHub Desktop.
Example implementation of card shuffling in Clojure
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
(def suits [:clubs :hearts :spades :diamonds]) | |
(def ranks [2 3 4 5 6 7 8 9 10 :jack :queen :king :ace]) | |
(def deck (for [s suits, r ranks] [s r])) | |
(println "Shuffled deck:" (shuffle deck)) |
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
$ clj cards.clj | |
Shuffled deck: [[:clubs 6] [:clubs 7] [:clubs 8] [:spades 3] [:spades 9] [:diamonds 10] [:hearts 7] [:diamonds 7] [:spades 5] [:diamonds 4] [:hearts 4] [:clubs 10] [:diamonds :ace] [:clubs 3] [:hearts :king] [:spades :queen] [:diamonds 6] [:clubs :jack] [:hearts 8] [:spades :king] [:spades :jack] [:spades :ace] [:hearts 3] [:clubs 9] [:clubs 2] [:spades 7] [:diamonds 3] [:spades 2] [:clubs :queen] [:clubs 5] [:clubs :king] [:hearts :queen] [:diamonds :jack] [:hearts 5] [:clubs 4] [:spades 8] [:clubs :ace] [:hearts 6] [:hearts 10] [:hearts :jack] [:diamonds 5] [:diamonds 9] [:hearts 9] [:diamonds 2] [:spades 6] [:hearts 2] [:hearts :ace] [:diamonds 8] [:spades 10] [:spades 4] [:diamonds :queen] [:diamonds :king]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment