diff options
Diffstat (limited to '2022/day2/part1')
-rw-r--r-- | 2022/day2/part1/Cargo.toml | 9 | ||||
-rw-r--r-- | 2022/day2/part1/src/main.rs | 21 |
2 files changed, 30 insertions, 0 deletions
diff --git a/2022/day2/part1/Cargo.toml b/2022/day2/part1/Cargo.toml new file mode 100644 index 0000000..f14fe90 --- /dev/null +++ b/2022/day2/part1/Cargo.toml | |||
@@ -0,0 +1,9 @@ | |||
1 | [package] | ||
2 | name = "part1" | ||
3 | version = "0.1.0" | ||
4 | edition = "2021" | ||
5 | |||
6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
7 | |||
8 | [dependencies] | ||
9 | itertools = "0.10.5" | ||
diff --git a/2022/day2/part1/src/main.rs b/2022/day2/part1/src/main.rs new file mode 100644 index 0000000..44ebe3a --- /dev/null +++ b/2022/day2/part1/src/main.rs | |||
@@ -0,0 +1,21 @@ | |||
1 | let rps_result = vec![4, 1, 7, 8, 5, 2, 3, 9 ,6]; | ||
2 | |||
3 | |||
4 | fn main() { | ||
5 | let score = include_str!("../../example").lines().fold(0, parse_line); | ||
6 | } | ||
7 | |||
8 | fn parse_line(score: usize, line: &str) -> usize { | ||
9 | let mut moves = line.split(' '); | ||
10 | let opponent_move = moves.next().unwrap(); | ||
11 | let my_move = moves.next().unwrap(); | ||
12 | |||
13 | match opponent_move { | ||
14 | "A" => 1, | ||
15 | "B" => 2, | ||
16 | "C" => 3, | ||
17 | _ => unreachable!(), | ||
18 | }; | ||
19 | |||
20 | 0 + score | ||
21 | } | ||