aboutsummaryrefslogtreecommitdiff
path: root/day02/part1.rb
blob: 150ee752a8a57d840d013e35b45489159c630272 (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
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