Skip to content

Commit

Permalink
perf(17/2024): add early returns, but still slow to slove for main input
Browse files Browse the repository at this point in the history
  • Loading branch information
manhunto committed Jan 12, 2025
1 parent eafec20 commit cad8919
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/solutions/year2024/day17.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ impl Solution for Day17 {
fn part_two(&self, input: &str) -> String {
let (_, program) = self.parse(input);

let mut i = 0;
loop {
for i in 0.. {
let mut register = RegisterBuilder::default().a(i).build();

if program.execute_and_watch(&mut register) {
return i.to_string();
}

i += 1;
println!("{}", i);
}

unreachable!()
}
}

Expand Down Expand Up @@ -113,9 +114,21 @@ impl Program {
&mut output,
);

if output.is_empty() {
continue;
}

if expected == output {
return true;
}

if expected.len() <= output.len() {
return false;
}

if expected[0..output.len()] != output {
return false;
}
}

false
Expand Down

0 comments on commit cad8919

Please sign in to comment.