day 6
This commit is contained in:
parent
7e4021e32d
commit
68f86d816c
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -54,6 +54,14 @@ version = "0.1.0"
|
||||||
name = "day_5-2"
|
name = "day_5-2"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day_6-1"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day_6-2"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.6.4"
|
version = "2.6.4"
|
||||||
|
|
2
day_6/input.txt
Normal file
2
day_6/input.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
Time: 60 80 86 76
|
||||||
|
Distance: 601 1163 1559 1300
|
8
day_6/part_1/Cargo.toml
Normal file
8
day_6/part_1/Cargo.toml
Normal 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
25
day_6/part_1/src/main.rs
Normal 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
8
day_6/part_2/Cargo.toml
Normal 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
14
day_6/part_2/src/main.rs
Normal 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}");
|
||||||
|
}
|
Loading…
Reference in a new issue