Skip to content

Instantly share code, notes, and snippets.

@yayitswei
Last active August 11, 2021 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yayitswei/d44ae8cba31544532285bf49295b5950 to your computer and use it in GitHub Desktop.
Save yayitswei/d44ae8cba31544532285bf49295b5950 to your computer and use it in GitHub Desktop.
creating packs of cards
(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