Advertisement
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*))
- 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 | dark | BLACKMOX | NONBLACKMOX
- NONBLACKMOX = mox (manamorph | cantor | narco)
- BLACKMOX = mox (dark | cabal | therapy | win)
- ANY = cantor | pact | petal | mox | dark | cabal | guide | manamorph | win | kill | narco | therapy
- 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]
- (loop [hands (combi/permutations hand)]
- (if (empty? hands)
- false
- (let [cur (apply str (first hands))
- rst (rest hands)]
- (if-not (insta/failure? (parser cur))
- true
- (recur rst))))))
- (defn first-turn-kills
- [hands]
- (->>
- hands
- (filter (fn [[hand _]] (some #{\w} hand)))
- (filter (fn [[hand _]] (kill? hand)))
- (map (fn [[_ amount]] amount))
- (reduce +)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement