We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d555f7a commit 3b09eb1Copy full SHA for 3b09eb1
src/year2017/day7/day7.rs
@@ -24,7 +24,7 @@ impl NodeId {
24
let digit = b'a' + (key % 26) as u8;
25
node.push(digit as char);
26
key /= 26;
27
- if key == 0 {
+ if key == 1 {
28
break;
29
}
30
@@ -35,10 +35,12 @@ impl NodeId {
35
impl From<&str> for NodeId {
36
fn from(value: &str) -> Self {
37
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)
40
value
41
.bytes()
42
.rev()
- .fold(0, |acc, d| acc * 26 + u64::from(d - b'a')),
43
+ .fold(1, |acc, d| acc * 26 + u64::from(d - b'a')),
44
)
45
46
0 commit comments