This commit is contained in:
BlackDemonFire 2023-12-02 12:53:27 +01:00
parent bbdab23098
commit 8d235ecbc4
Signed by: lucy
SSH key fingerprint: SHA256:LOoXGgXjn6B8CcfqWHkd2Y5gFaffr0b2tAzBKlEG6Xc
6 changed files with 72 additions and 0 deletions

8
Cargo.lock generated
View file

@ -9,3 +9,11 @@ version = "0.1.0"
[[package]]
name = "d01t2"
version = "0.1.0"
[[package]]
name = "d02t1"
version = "0.1.0"
[[package]]
name = "d02t2"
version = "0.1.0"

View file

@ -4,4 +4,6 @@ resolver = "2"
members = [
"d01t1",
"d01t2",
"d02t1",
"d02t2",
]

8
d02t1/Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "d02t1"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

22
d02t1/src/main.rs Normal file
View file

@ -0,0 +1,22 @@
fn main() {
let input = include_str!("../input.txt");
let mut result = 0;
for line in input.lines() {
let (game_id, game_values) = line.split_once(": ").unwrap();
if !game_values.split("; ").any(|die_set| {
die_set.split(", ").any(|v| {
let (val, color) = v.split_once(" ").unwrap();
let val = val.parse::<usize>().unwrap();
match color {
"red" => val > 12,
"green" => val > 13,
"blue" => val > 14,
c => panic!("unknown color {c}"),
}
})
}) {
result += game_id.split_once(" ").unwrap().1.parse::<i32>().unwrap();
}
}
println!("d02t1: {result}");
}

8
d02t2/Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "d02t2"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

24
d02t2/src/main.rs Normal file
View file

@ -0,0 +1,24 @@
fn main() {
let input = include_str!("../input.txt");
let result = input
.lines()
.map(|line| {
let (_game_id, game_values) = line.split_once(": ").unwrap();
let mut min_red = 0;
let mut min_green = 0;
let mut min_blue = 0;
game_values.replace(";", ",").split(", ").for_each(|v| {
let (val, color) = v.split_once(" ").unwrap();
let val = val.parse::<usize>().unwrap();
match color {
"red" => min_red = min_red.max(val),
"green" => min_green = min_green.max(val),
"blue" => min_blue = min_blue.max(val),
c => panic!("unknown color {c}"),
}
});
min_red * min_green * min_blue
})
.sum::<usize>();
println!("d02t2: {result}");
}