Skip to content

Commit af92f31

Browse files
committed
Solve both parts of day 11 in a single pass.
Weirdly, this has substantially increased the average runtime. I've occasionally gotten down to the 18 ms mark with this build, but more often I get around 36. Not entirely sure what's going on there, but I have to assume that more runs of the previous iteration would also have shown this higher average, and I just got lucky the first time. Still, this does now take a single pass over the input, and the best recorded time was precisely equal to the only recorded time of the two-pass solution, so I have to assume that the bulk of the runtime had to do not with walking the hex positions but with parsing the input. Fair enough. $ cargo check && cargo build --release && time target/release/day11 && wc -c input.txt Compiling day11 v0.1.0 (file:///mnt/d/Users/coriolinus/Documents/Projects/adventofcode.com/adventofcode-2017/day11) Finished dev [unoptimized + debuginfo] target(s) in 0.58 secs Finished release [optimized] target(s) in 0.0 secs Dist to origin: 720 Max dist to origin: 1485 real 0m0.037s user 0m0.000s sys 0m0.016s 21533 input.txt
1 parent 24ea7ad commit af92f31

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

day11/src/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ fn main() {
1313
.collect()
1414
}).expect("Problem parsing input")
1515
{
16-
let position: HexPosition = directions.iter().sum();
17-
println!("Dist to origin: {}", position.min_steps_to_origin());
18-
1916
let mut position = HexPosition::new();
2017
let mut max_dist = 0;
2118
for direction in directions.iter() {
2219
position = position + direction;
2320
max_dist = max(max_dist, position.min_steps_to_origin());
2421
}
22+
println!("Dist to origin: {}", position.min_steps_to_origin());
2523
println!("Max dist to origin: {}", max_dist);
2624
}
2725
}

0 commit comments

Comments
 (0)