/ Rust / 2022 / 02.rs
02.rs
 1  #![feature(test)]
 2  
 3  type Input = Vec<(u32, u32)>;
 4  
 5  fn setup(input: &str) -> Input {
 6      input
 7          .trim()
 8          .split('\n')
 9          .map(|line| {
10              (
11                  (line.as_bytes()[0] - b'A') as u32,
12                  (line.as_bytes()[2] - b'X') as u32,
13              )
14          })
15          .collect()
16  }
17  
18  fn part1(input: &Input) -> u32 {
19      input.iter().map(|(a, b)| (4 + b - a) % 3 * 3 + b + 1).sum()
20  }
21  
22  fn part2(input: &Input) -> u32 {
23      input.iter().map(|(a, b)| (2 + a + b) % 3 + 1 + b * 3).sum()
24  }
25  
26  aoc::main!(2022, 2, ex: 1);