From d938e3a57ca928d82f31c80e8c88d874bf0da033 Mon Sep 17 00:00:00 2001 From: Johannes Date: Sun, 15 Dec 2024 17:30:17 +0100 Subject: [PATCH] day 14 part 2 removed hashset for loop check --- src/day14.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/day14.rs b/src/day14.rs index c8e1fb8..95e38a1 100644 --- a/src/day14.rs +++ b/src/day14.rs @@ -1,8 +1,4 @@ -use std::{ - collections::HashSet, - fs::read_to_string, - // io::{self, BufRead}, -}; +use std::fs::read_to_string; use itertools::Itertools; @@ -69,17 +65,16 @@ fn parse(input: &str) -> Vec<((i64, i64), (i64, i64))> { } #[allow(unused)] -fn part2(input: &str) -> RiddleResult { +fn part2(input: &str) -> i64 { let width = 101; let height = 103; let mut robots = parse(input); - let mut seen = HashSet::new(); + let max_seconds = width * height as i64; for second in 0.. { - if seen.contains(&robots) { - panic!("Loop after {second} rounds, but no christmas tree!"); + if second > max_seconds { + panic!("Seen all combinations but no christmas tree. So sad!"); } let mut grid: Grid = Grid::from_default(101, 103); - seen.insert(robots.clone()); robots.iter_mut().for_each(|((px, py), (vx, vy))| { *px = (*px + width + *vx) % width; *py = (*py + height + *vy) % height;