diff --git a/Cargo.toml b/Cargo.toml index 6693c0d..c6112ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ members = [ "advent-of-code-2023/d03-gear-ratios", "advent-of-code-2023/d04-scratchcards", "advent-of-code-2023/d05-if-you-give-a-seed-a-fertilizer", - "advent-of-code-2023/d06", + "advent-of-code-2023/d06-wait-for-it", "advent-of-code-2023/d07-camel-cards", "advent-of-code-2023/d08-haunted-wasteland", "advent-of-code-2023/d09", diff --git a/advent-of-code-2023/d06/Cargo.toml b/advent-of-code-2023/d06-wait-for-it/Cargo.toml similarity index 85% rename from advent-of-code-2023/d06/Cargo.toml rename to advent-of-code-2023/d06-wait-for-it/Cargo.toml index ca91a5f..ff955ff 100644 --- a/advent-of-code-2023/d06/Cargo.toml +++ b/advent-of-code-2023/d06-wait-for-it/Cargo.toml @@ -6,3 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +aoc = { path = "../../aoc" } diff --git a/advent-of-code-2023/d06/README.md b/advent-of-code-2023/d06-wait-for-it/README.md similarity index 100% rename from advent-of-code-2023/d06/README.md rename to advent-of-code-2023/d06-wait-for-it/README.md diff --git a/advent-of-code-2023/d06-wait-for-it/src/main.rs b/advent-of-code-2023/d06-wait-for-it/src/main.rs new file mode 100644 index 0000000..acf405e --- /dev/null +++ b/advent-of-code-2023/d06-wait-for-it/src/main.rs @@ -0,0 +1,17 @@ +fn brute_force(time: i64, distance: i64) -> u64 { + (0..time).filter(|&t| t * (time - t) > distance).count() as u64 +} + +fn part1(inputs: impl Iterator) -> u64 { + inputs + .map(|(time, distance)| brute_force(time, distance)) + .product::() +} + +fn main() { + let input_one = &[(61, 430), (67, 1036), (75, 1307), (71, 1150)]; + let input_two = (61677571, 430103613071150); + + println!("Part 1: {}", part1(input_one.iter().copied())); + println!("Part 2: {}", brute_force(input_two.0, input_two.1)); +} diff --git a/advent-of-code-2023/d06/src/main.rs b/advent-of-code-2023/d06/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/advent-of-code-2023/d06/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -}