blob: 73099d86b5a0cd1a0dc1154e6fb7141fa969b138 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
(ns aocclj.day02
(:require [clojure.set :as set]
[clojure.string :as str]))
(def loses-to {:rock :scissors :scissors :paper :paper :rock})
(def wins-to (set/map-invert loses-to))
(defn translate [play]
(case play
(A X) :rock
(B Y) :paper
(C Z) :scissors))
(defn weight [play]
(case play
:rock 1
:paper 2
:scissors 3))
(defn match [my other]
(cond
(= my (wins-to other)) 6
(= my other) 3
:else 0))
(defn static-play [my-instruction other]
(translate my-instruction))
(defn reactive-play [my-instruction other]
(case my-instruction
X (loses-to other)
Y other
Z (wins-to other)))
(defn score [strategy game-play]
(let [[oponent my] game-play
oponent (translate oponent)
my-play (strategy my oponent)]
(+ (weight my-play) (match my-play oponent))))
(defn solver [strategy input]
(transduce
(comp
(map #(map symbol (str/split % #" ")))
(map (partial score strategy)))
+ input))
|