input parsing 2022/22

This commit is contained in:
kageru 2022-12-22 15:10:00 +01:00
parent 1f10471413
commit 5a8c34ccf8
2 changed files with 266 additions and 0 deletions

202
2022/inputs/day22 Normal file

File diff suppressed because one or more lines are too long

64
2022/src/bin/day22.rs Normal file
View File

@ -0,0 +1,64 @@
#![feature(test)]
extern crate test;
use aoc2022::{
boilerplate,
common::*,
grid::{Grid, HashGrid, PositionND},
};
const DAY: usize = 22;
type Parsed = (HashGrid<bool, 2>, Vec<Instruction>);
#[derive(Copy, Clone, Debug)]
enum Instruction {
TurnLeft,
TurnRight,
Step(usize),
}
fn parse_input(raw: &str) -> Parsed {
let (maze, moves) = raw.split_once("\n\n").unwrap();
let grid = maze
.lines()
.zip(1..)
.flat_map(|(line, x)| line.bytes().zip(1..).filter(|(b, _)| *b != b' ').map(move |(b, y)| (PositionND::from([x, y]), b == b'#')))
.collect();
let moves = moves
.split_inclusive(['L', 'R'])
.map(|s| s.split_at(s.len() - 1))
.flat_map(|(n, d)| [Instruction::Step(parse_num(n)), if d == "L" { Instruction::TurnLeft } else { Instruction::TurnRight }])
.collect();
(grid, moves)
}
fn part1(parsed: &Parsed) -> usize {
unimplemented!()
}
fn part2(parsed: &Parsed) -> usize {
unimplemented!()
}
boilerplate! {
TEST_INPUT == "\
...#
.#..
#...
....
...#.......#
........#...
..#....#....
..........#.
...#....
.....#..
.#......
......#.
10R5L5R10L4R5L5",
tests: {
part1: { TEST_INPUT => 0 },
part2: { TEST_INPUT => 0 },
},
bench1 == 0,
bench2 == 0,
bench_parse: |(g, i): &Parsed| g.len() + i.len() => 19002,
}