Skip to content

Commit fbd11dd

Browse files
committed
Faster parsing
1 parent bbb7f9e commit fbd11dd

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pie
110110
| 19 | [Not Enough Minerals](https://adventofcode.com/2022/day/19) | [Source](src/year2022/day19.rs) | 407 |
111111
| 20 | [Grove Positioning System](https://adventofcode.com/2022/day/20) | [Source](src/year2022/day20.rs) | 5067 |
112112
| 21 | [Monkey Math](https://adventofcode.com/2022/day/21) | [Source](src/year2022/day21.rs) | 61 |
113-
| 22 | [Monkey Map](https://adventofcode.com/2022/day/22) | [Source](src/year2022/day22.rs) | 132 |
113+
| 22 | [Monkey Map](https://adventofcode.com/2022/day/22) | [Source](src/year2022/day22.rs) | 55 |
114114
| 23 | [Unstable Diffusion](https://adventofcode.com/2022/day/23) | [Source](src/year2022/day23.rs) | 2017 |
115115
| 24 | [Blizzard Basin](https://adventofcode.com/2022/day/24) | [Source](src/year2022/day24.rs) | 80 |
116116
| 25 | [Full of Hot Air](https://adventofcode.com/2022/day/25) | [Source](src/year2022/day25.rs) | 3 |

src/year2022/day22.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,19 @@ fn parse_grid(input: &str) -> Grid {
208208

209209
fn parse_moves(input: &str) -> Vec<Move> {
210210
let mut moves = Vec::new();
211+
let mut numbers = input.iter_unsigned();
212+
let mut letters = input.bytes().filter(u8::is_ascii_uppercase);
211213

212-
for token in input.replace('L', " L ").replace('R', " R ").trim().split(' ') {
213-
let next = match token {
214-
"L" => Move::Left,
215-
"R" => Move::Right,
216-
n => Move::Forward(n.unsigned()),
214+
loop {
215+
let Some(n) = numbers.next() else {
216+
break;
217217
};
218-
moves.push(next);
218+
moves.push(Move::Forward(n));
219+
220+
let Some(d) = letters.next() else {
221+
break;
222+
};
223+
moves.push(if d == b'L' { Move::Left } else { Move::Right });
219224
}
220225

221226
moves

0 commit comments

Comments
 (0)