Skip to content

Instantly share code, notes, and snippets.

@rafd
Created September 14, 2020 21:11
Show Gist options
  • Save rafd/ba7fd06bdbf382ce5c854a5970bafc74 to your computer and use it in GitHub Desktop.
Save rafd/ba7fd06bdbf382ce5c854a5970bafc74 to your computer and use it in GitHub Desktop.
clojodojo-2020-09-14
(ns demo)
(defn hello []
"sagasgd x")
(defonce run? (atom true))
(defn run []
(future
(Thread/sleep 1000)
(when @run?
(println (hello))
(recur))))
#_(reset! run? false)
(defn deck []
(for [suit [:card.suit/hearts :card.suit/spades
:card.suit/clubs :card.suit/diamonds]
rank (range 1 14)]
{:card/suit suit
:card/rank rank}))
(shuffle (deck))
[ 1 2 3 4 5 1 2 5 1 2 ]
[ ] [ ]
; [1 2 3 4].reduce (function(accum, item) { return accum + item }, 0)
(defn deal [card-count player-count]
(let [cards [1 2 3 4 5 6 7 8 9 10 11 12] #_(deck)]
(reduce (fn [hands card]
(if (< (count (last hands)) card-count)
(update-in hands [(dec (count hands))] conj card)
(conj hands [card])))
[[]]
cards)))
(defn deal [card-count player-count]
(take player-count (partition card-count (deck))))
((if true
+
-) 1 2 3 4 5 6)
(defn deal [card-count player-count]
(->> (deck)
(partition card-count)
(take player-count)))
; deck
; .partition(card_count)
; .take(player_count)
(deal 3 2)
; reduce
; take & recur?
; loop ?
; partition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment