This commit is contained in:
Lea 2023-12-06 08:10:55 +01:00
parent 7e4021e32d
commit 68f86d816c
Signed by: Lea
GPG key ID: 1BAFFE8347019C42
6 changed files with 65 additions and 0 deletions

8
Cargo.lock generated
View file

@ -54,6 +54,14 @@ version = "0.1.0"
name = "day_5-2"
version = "0.1.0"
[[package]]
name = "day_6-1"
version = "0.1.0"
[[package]]
name = "day_6-2"
version = "0.1.0"
[[package]]
name = "memchr"
version = "2.6.4"

2
day_6/input.txt Normal file
View file

@ -0,0 +1,2 @@
Time: 60 80 86 76
Distance: 601 1163 1559 1300

8
day_6/part_1/Cargo.toml Normal file
View file

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

25
day_6/part_1/src/main.rs Normal file
View file

@ -0,0 +1,25 @@
fn main() {
let input = include_str!("../../input.txt").trim_end().lines().collect::<Vec<&str>>();
let mut times = input.first().unwrap().split(" ").filter(|item| item != &"").collect::<Vec<&str>>();
let mut distances = input.last().unwrap().split(" ").filter(|item| item != &"").collect::<Vec<&str>>();
let mut result = 1;
times.remove(0);
distances.remove(0);
for index in 0..times.len() {
let time = times[index].parse::<i32>().unwrap();
let distance = distances[index].parse::<i32>().unwrap();
let mut wins = 0;
for i in 0..=time {
if i * (time - i) > distance {
wins += 1;
}
}
result *= wins;
}
println!("Result: {result}");
}

8
day_6/part_2/Cargo.toml Normal file
View file

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

14
day_6/part_2/src/main.rs Normal file
View file

@ -0,0 +1,14 @@
fn main() {
let input = include_str!("../../input.txt").trim_end().lines().collect::<Vec<&str>>();
let time = input.first().unwrap().replace(" ", "").split(":").collect::<Vec<&str>>()[1].parse::<i64>().unwrap();
let distance = input.last().unwrap().replace(" ", "").split(":").collect::<Vec<&str>>()[1].parse::<i64>().unwrap();
let mut result = 0;
for i in 0..=time {
if i * (time - i) > distance {
result += 1;
}
}
println!("Result: {result}");
}