Skip to content

Commit 3b09eb1

Browse files
committed
fix a nasty bug
1 parent d555f7a commit 3b09eb1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/year2017/day7/day7.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl NodeId {
2424
let digit = b'a' + (key % 26) as u8;
2525
node.push(digit as char);
2626
key /= 26;
27-
if key == 0 {
27+
if key == 1 {
2828
break;
2929
}
3030
}
@@ -35,10 +35,12 @@ impl NodeId {
3535
impl From<&str> for NodeId {
3636
fn from(value: &str) -> Self {
3737
Self(
38+
// add 1 as unit digit to manage id with 0 as unit
39+
// without this trick as_string() will fail to add the last digit (0)
3840
value
3941
.bytes()
4042
.rev()
41-
.fold(0, |acc, d| acc * 26 + u64::from(d - b'a')),
43+
.fold(1, |acc, d| acc * 26 + u64::from(d - b'a')),
4244
)
4345
}
4446
}

0 commit comments

Comments
 (0)