Skip to content

Commit 6000e3f

Browse files
committed
fix(01/2016): fix bug with exiting inner loop
1 parent 940a551 commit 6000e3f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787

8888
| Day | Solved | Part 1 time (ms) | Part 2 time (ms) |
8989
|-----------------------------------------------------------------|:------:|-----------------:|-----------------:|
90-
| [Day 1: No Time for a Taxicab](src/solutions/year2016/day01.rs) | | 0.058 | - |
90+
| [Day 1: No Time for a Taxicab](src/solutions/year2016/day01.rs) | | 0.058 | 0.159 |
9191

9292
# 2015
9393

src/solutions/year2016/day01.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl Solution for Day01 {
3030
let mut visited = HashSet::new();
3131
visited.insert(start);
3232

33-
for (rotation, distance) in self.parse(input.trim()) {
33+
'outer: for (rotation, distance) in self.parse(input.trim()) {
3434
vector = match rotation {
3535
RotationDirection::Right => vector.rotate_cw(),
3636
RotationDirection::Left => vector.rotate_ccw(),
@@ -41,7 +41,7 @@ impl Solution for Day01 {
4141

4242
let position = vector.position();
4343
if visited.contains(&position) {
44-
break;
44+
break 'outer;
4545
}
4646

4747
visited.insert(position);
@@ -88,4 +88,9 @@ mod tests {
8888
fn part_two_example() {
8989
assert_eq!("4", Day01.part_two("R8, R4, R4, R8"));
9090
}
91+
92+
#[test]
93+
fn part_two_bug_break_just_inner_loop() {
94+
assert_eq!("0", Day01.part_two("R1, R1, R1, R1, R100"));
95+
}
9196
}

0 commit comments

Comments
 (0)