1
0

day 14 part 2 removed hashset for loop check

This commit is contained in:
2024-12-15 17:30:17 +01:00
parent e135a6a349
commit d938e3a57c

View File

@@ -1,8 +1,4 @@
use std::{ use std::fs::read_to_string;
collections::HashSet,
fs::read_to_string,
// io::{self, BufRead},
};
use itertools::Itertools; use itertools::Itertools;
@@ -69,17 +65,16 @@ fn parse(input: &str) -> Vec<((i64, i64), (i64, i64))> {
} }
#[allow(unused)] #[allow(unused)]
fn part2(input: &str) -> RiddleResult { fn part2(input: &str) -> i64 {
let width = 101; let width = 101;
let height = 103; let height = 103;
let mut robots = parse(input); let mut robots = parse(input);
let mut seen = HashSet::new(); let max_seconds = width * height as i64;
for second in 0.. { for second in 0.. {
if seen.contains(&robots) { if second > max_seconds {
panic!("Loop after {second} rounds, but no christmas tree!"); panic!("Seen all combinations but no christmas tree. So sad!");
} }
let mut grid: Grid<u8> = Grid::from_default(101, 103); let mut grid: Grid<u8> = Grid::from_default(101, 103);
seen.insert(robots.clone());
robots.iter_mut().for_each(|((px, py), (vx, vy))| { robots.iter_mut().for_each(|((px, py), (vx, vy))| {
*px = (*px + width + *vx) % width; *px = (*px + width + *vx) % width;
*py = (*py + height + *vy) % height; *py = (*py + height + *vy) % height;