37 lines
1,001 B
Rust
37 lines
1,001 B
Rust
use eyes::parse;
|
|
|
|
fn main() {
|
|
let input = aoc::input!();
|
|
println!("part 1: {}", part1(&input));
|
|
println!("part 1: {}", part2(&input));
|
|
}
|
|
|
|
fn part1(input: &str) -> i64 {
|
|
input
|
|
.lines()
|
|
.map(|line| parse!(line, "{} {}", char, char))
|
|
.map(|(them, you)| ((them as u8 - b'A') as i64, (you as u8 - b'X') as i64))
|
|
.map(|(them, you)| ((you + 4 - them) % 3 * 3) + (you + 1)) // (outcome score) + (shape score)
|
|
.sum::<i64>()
|
|
}
|
|
|
|
fn part2(input: &str) -> i64 {
|
|
input
|
|
.lines()
|
|
.map(|line| parse!(line, "{} {}", char, char))
|
|
.map(|(them, you)| ((them as u8 - b'A') as i64, (you as u8 - b'X') as i64))
|
|
.map(|(them, you)| (you * 3) + ((you + 2 + them) % 3 + 1)) // (outcome score) + (shape score)
|
|
.sum::<i64>()
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn examples() {
|
|
let example = "A Y\nB X\nC Z";
|
|
assert_eq!(part1(example), 15);
|
|
assert_eq!(part2(example), 12);
|
|
}
|
|
}
|