diff --git a/Cargo.lock b/Cargo.lock index 214cf77..6357306 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/day_6/input.txt b/day_6/input.txt new file mode 100644 index 0000000..e0996e8 --- /dev/null +++ b/day_6/input.txt @@ -0,0 +1,2 @@ +Time: 60 80 86 76 +Distance: 601 1163 1559 1300 diff --git a/day_6/part_1/Cargo.toml b/day_6/part_1/Cargo.toml new file mode 100644 index 0000000..62e495b --- /dev/null +++ b/day_6/part_1/Cargo.toml @@ -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] diff --git a/day_6/part_1/src/main.rs b/day_6/part_1/src/main.rs new file mode 100644 index 0000000..96c35c2 --- /dev/null +++ b/day_6/part_1/src/main.rs @@ -0,0 +1,25 @@ +fn main() { + let input = include_str!("../../input.txt").trim_end().lines().collect::>(); + let mut times = input.first().unwrap().split(" ").filter(|item| item != &"").collect::>(); + let mut distances = input.last().unwrap().split(" ").filter(|item| item != &"").collect::>(); + let mut result = 1; + + times.remove(0); + distances.remove(0); + + for index in 0..times.len() { + let time = times[index].parse::().unwrap(); + let distance = distances[index].parse::().unwrap(); + let mut wins = 0; + + for i in 0..=time { + if i * (time - i) > distance { + wins += 1; + } + } + + result *= wins; + } + + println!("Result: {result}"); +} diff --git a/day_6/part_2/Cargo.toml b/day_6/part_2/Cargo.toml new file mode 100644 index 0000000..269826a --- /dev/null +++ b/day_6/part_2/Cargo.toml @@ -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] diff --git a/day_6/part_2/src/main.rs b/day_6/part_2/src/main.rs new file mode 100644 index 0000000..8372895 --- /dev/null +++ b/day_6/part_2/src/main.rs @@ -0,0 +1,14 @@ +fn main() { + let input = include_str!("../../input.txt").trim_end().lines().collect::>(); + let time = input.first().unwrap().replace(" ", "").split(":").collect::>()[1].parse::().unwrap(); + let distance = input.last().unwrap().replace(" ", "").split(":").collect::>()[1].parse::().unwrap(); + let mut result = 0; + + for i in 0..=time { + if i * (time - i) > distance { + result += 1; + } + } + + println!("Result: {result}"); +}