diff --git a/day14/Cargo.lock b/day14/Cargo.lock index 230f69b..1217679 100644 --- a/day14/Cargo.lock +++ b/day14/Cargo.lock @@ -16,15 +16,31 @@ name = "day14" version = "0.1.0" dependencies = [ "glam", + "itertools", "regex", ] +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + [[package]] name = "glam" version = "0.29.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc46dd3ec48fdd8e693a98d2b8bafae273a2d54c1de02a2a7e3d57d501f39677" +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + [[package]] name = "memchr" version = "2.7.4" diff --git a/day14/Cargo.toml b/day14/Cargo.toml index af014a8..35e1cd1 100644 --- a/day14/Cargo.toml +++ b/day14/Cargo.toml @@ -5,4 +5,5 @@ edition = "2021" [dependencies] glam = "0.29.2" +itertools = "0.13.0" regex = "1.11.1" diff --git a/day14/src/main.rs b/day14/src/main.rs index bbc0eb0..30f4584 100644 --- a/day14/src/main.rs +++ b/day14/src/main.rs @@ -1,4 +1,5 @@ use glam::IVec2; +use itertools::Itertools; use regex::Regex; #[derive(Debug, Clone, Eq, PartialEq)] @@ -76,12 +77,13 @@ fn print_map(robots: &[Robot], dimensions: &IVec2) -> String { } fn has_tree(robots: &[Robot]) -> bool { - let check: Vec<_> = (0..16).map(|i| IVec2::new(i, 0)).collect(); - robots.iter().any(|p| { - check - .iter() - .all(|c| robots.iter().any(|p2| p2.position == p.position + c)) - }) + robots.len() == robots.iter().map(|r| r.position).unique().count() + // let check: Vec<_> = (0..16).map(|i| IVec2::new(i, 0)).collect(); + // robots.iter().any(|p| { + // check + // .iter() + // .all(|c| robots.iter().any(|p2| p2.position == p.position + c)) + // }) } fn part2(robots: &mut [Robot], dimensions: &IVec2) -> i32 {