1use crate::util::grid::*;
8use crate::util::point::*;
9
10type Input = (String, u32);
11
12pub fn parse(input: &str) -> Input {
13 let grid = Grid::parse(input);
14
15 let mut position = grid.find(b'|').unwrap();
16 let mut direction = DOWN;
17
18 let mut part_one = String::new();
19 let mut part_two = 0;
20
21 loop {
22 let next = grid[position];
23
24 match next {
25 b'+' => {
26 let left = direction.counter_clockwise();
27 let right = direction.clockwise();
28 direction = if grid[position + right] == b' ' { left } else { right };
29 }
30 b' ' => break,
31 _ if next.is_ascii_alphabetic() => part_one.push(next as char),
32 _ => (),
33 }
34
35 position += direction;
36 part_two += 1;
37 }
38
39 (part_one, part_two)
40}
41
42pub fn part1(input: &Input) -> &str {
43 input.0.as_str()
44}
45
46pub fn part2(input: &Input) -> u32 {
47 input.1
48}