Skip to content

Commit fa76f11

Browse files
committed
Day 7
1 parent 68003ee commit fa76f11

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Solutions for [Advent of Code](https://adventofcode.com/) in [Rust](https://www.
1717
| [Day 4](./src/bin/04.rs) | `810.2µs` | `298.7µs` |
1818
| [Day 5](./src/bin/05.rs) | `67.7µs` | `184.5µs` |
1919
| [Day 6](./src/bin/06.rs) | `71.1µs` | `24.8ms` |
20-
| [Day 7](./src/bin/07.rs) | `2.2ms` | `130.7ms` |
20+
| [Day 7](./src/bin/07.rs) | `2.2ms` | `54.4ms` |
2121

22-
**Total: 161.18ms**
22+
**Total: 84.88ms**
2323
<!--- benchmarking table --->
2424

2525
---

src/bin/07.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,13 @@ impl EquationData {
5454
Op::Add => current_value + next_value,
5555
Op::Mul => current_value * next_value,
5656
Op::Concat => {
57-
let char_count = next_value.to_string().len() as u32;
58-
current_value * 10_u64.pow(char_count) + next_value
57+
let mut digit_count = 0;
58+
let mut n = next_value;
59+
while n > 0 {
60+
digit_count += 1;
61+
n /= 10;
62+
}
63+
current_value * 10_u64.pow(digit_count) + next_value
5964
}
6065
};
6166

0 commit comments

Comments
 (0)