diff options
Diffstat (limited to 'day02/part2.rb')
-rw-r--r-- | day02/part2.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/day02/part2.rb b/day02/part2.rb new file mode 100644 index 0000000..871a332 --- /dev/null +++ b/day02/part2.rb @@ -0,0 +1,35 @@ +def whatplay(them, outcome) + case them + when 1 + case outcome + when 0; 3 + when 3; 1 + when 6; 2 + end + when 2 + case outcome + when 0; 1 + when 3; 2 + when 6; 3 + end + when 3 + case outcome + when 0; 2 + when 3; 3 + when 6; 1 + end + end +end + +rounds = $stdin.readlines.map(&:strip).map(&:split) + +score = 0 + +rounds.each do |them, outcome| + ti = {?A => 1, ?B => 2, ?C => 3}[them] + oi = {?X => 0, ?Y => 3, ?Z => 6}[outcome] + score += whatplay(ti, oi) + score += oi +end + +puts score |