aboutsummaryrefslogtreecommitdiff
path: root/day02/part1.rb
diff options
context:
space:
mode:
authorNat Lasseter <nat.lasseter@york.ac.uk>2022-12-02 11:02:28 +0000
committerNat Lasseter <nat.lasseter@york.ac.uk>2022-12-02 11:02:28 +0000
commit17d5ad4f0b630f2e8363c85182ff3dfdeee6dc52 (patch)
tree870606437421e6ac6efb4a05d717f77d73df07e2 /day02/part1.rb
parentbf99f840cd83ee8f886c96737ed97fd3c54e4b09 (diff)
Day 02
Diffstat (limited to 'day02/part1.rb')
-rw-r--r--day02/part1.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/day02/part1.rb b/day02/part1.rb
new file mode 100644
index 0000000..150ee75
--- /dev/null
+++ b/day02/part1.rb
@@ -0,0 +1,34 @@
+def play(them, us)
+ us + case them
+ when 1
+ case us
+ when 1; 3
+ when 2; 6
+ when 3; 0
+ end
+ when 2
+ case us
+ when 1; 0
+ when 2; 3
+ when 3; 6
+ end
+ when 3
+ case us
+ when 1; 6
+ when 2; 0
+ when 3; 3
+ end
+ end
+end
+
+rounds = $stdin.readlines.map(&:strip).map(&:split)
+
+score = 0
+
+rounds.each do |them, us|
+ ti = {?A => 1, ?B => 2, ?C => 3}[them]
+ ui = {?X => 1, ?Y => 2, ?Z => 3}[us]
+ score += play(ti, ui)
+end
+
+puts score