-
-
Save yayitswei/d44ae8cba31544532285bf49295b5950 to your computer and use it in GitHub Desktop.
creating packs of cards
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
(def decks [[:a1 :a2 :a3 :a4] [:b1 :b2 :b3 :b4] [:c1 :c2 :c3 :c4] [:d1 :d2]]) | |
(defn deal-hands [n decks] | |
(loop [left (mapv shuffle decks) | |
results []] | |
(if (empty? left) results | |
(recur (->> (map pop left) (remove empty?)) | |
(concat results (->> (map peek left) shuffle (partition n))))))) | |
(deal-hands 2 decks) | |
;; => ((:d2 :b3) (:a3 :c4) (:d1 :a2) (:c3 :b1) (:b2 :c1) (:c2 :a1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment