Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
523 B
13
Indexable
Never
points = 0
points_for_action = {
  X: 1,
  Y: 2,
  Z: 3,
}

swap_rules = {
  'A X' => 'Z',
  'B X' => 'X',
  'C X' => 'Y',
  'A Y' => 'X',
  'B Y' => 'Y',
  'C Y' => 'Z',
  'A Z' => 'Y',
  'B Z' => 'Z',
  'C Z' => 'X',
}

rules = {
  'A X' => 3,
  'B X' => 0,
  'C X' => 6,
  'A Y' => 6,
  'B Y' => 3,
  'C Y' => 0,
  'A Z' => 0,
  'B Z' => 6,
  'C Z' => 3,
}

File.read('day2/input.txt').split("\n").each do |round|
  round[2] = swap_rules[round]
  points += rules[round] + points_for_action[round[2].to_sym]
end

p points