Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns oops.core
- (:require
- [clojure.math.combinatorics :as combi]
- [instaparse.core :as insta]))
- (def deck
- (concat
- [\c] ;; wild cantor
- (repeat 4 \p) ;; summoner's pact
- (repeat 4 \l) ;; lotus petal
- (repeat 4 \x) ;; mox
- (repeat 4 \d) ;; dark ritual
- (repeat 4 \r) ;; cabal ritual
- (repeat 8 \g) ;; spirit guide
- (repeat 4 \m) ;; manamorphose
- (repeat 8 \w) ;; voittokeino
- (repeat 4 \t) ;; tappo
- (repeat 4 \n) ;; narcomoeba
- (repeat 3 \h))) ;; cabal therapy
- (def bnf
- "S = 1B 2MORE win ANY* |
- 2B (1MORE | dark) win ANY*
- NOWINCON = 1B 2MORE NOTWIN* |
- 2B 1MORE NOTWIN*
- ONEMANASHORT= 1B 1MORE win (NOTMANA* | mox*) |
- 2B win (NOTMANA* | mox*)
- 2MORE = 1MORE 1MORE | dark
- 2B = petal dark |
- BLACKMOX dark |
- CANTORBLACK dark |
- 1B 1MORE
- 1B = manamorph (pact | guide | mox (manamorph | cantor)) COLORLESS |
- petal COLORLESS |
- BLACKMOX COLORLESS |
- CANTORBLACK COLORLESS
- CANTORBLACK = (pact | guide | (mox manamorph)) (pact | cantor)
- 1MORE = pact | guide | petal | cabal | BLACKMOX | NONBLACKMOX
- COLORLESS = pact | guide | petal | BLACKMOX | NONBLACKMOX
- NONBLACKMOX = mox (manamorph | cantor | narco)
- BLACKMOX = mox (dark | cabal | therapy | win)
- ANY = NOTWIN | win
- NOTWIN = cantor | pact | petal | mox | dark | cabal | guide | manamorph | kill | narco | therapy
- NOTMANA = cantor | manamorph | kill | narco | therapy | win
- cantor = 'c'
- petal = 'l'
- pact = 'p'
- guide = 'g'
- mox = 'x'
- dark = 'd'
- cabal = 'r'
- manamorph = 'm'
- win = 'w'
- kill = 't'
- narco = 'n'
- therapy = 'h'")
- (def parser
- (insta/parser bnf))
- (defn hands
- [n]
- (->>
- (combi/combinations deck n)
- (map sort)
- frequencies
- seq))
- (defn kill?
- ([hand] (kill? hand :S))
- ([hand start-symbol]
- (loop [hands (combi/permutations hand)]
- (if (empty? hands)
- false
- (let [cur (apply str (first hands))
- rst (rest hands)]
- (if-not (insta/failure? (parser cur :start start-symbol))
- (parser cur :start start-symbol)
- (recur rst)))))))
- (defn filter-with-all
- [coll & preds]
- (reduce
- (fn [c pred]
- (filter pred c))
- coll
- preds))
- (defn filter-hands
- [hands & preds]
- (let [hand-preds (map #(fn [[hand _]] (% hand)) preds)]
- (apply filter-with-all hands hand-preds)))
- (defn count-hands
- [hands]
- (->>
- hands
- (map (fn [[_ amount]] amount))
- (reduce +)))
- (defn first-turn-kills
- [hands]
- (filter-hands
- hands
- #(some #{\w} %)
- kill?))
- (defn one-mana-short
- [hands]
- (filter-hands
- hands
- #(some #{\w} %)
- #(kill? % :ONEMANASHORT)))
- (defn no-win-con
- [hands]
- (filter-hands
- hands
- #(not-any? #{\w} %)
- #(kill? % :NOWINCON)))
- (println (count-hands (no-win-con (hands 7)))) ;; => 4200393
- (println (count-hands (one-mana-short (hands 7)))) ;; => 4630860
- (println (count-hands (first-turn-kills (hands 7)))) ;; => 3895364
Advertisement
Add Comment
Please, Sign In to add comment