day7: part1
This commit is contained in:
52
src/day7.rs
52
src/day7.rs
@@ -1,16 +1,39 @@
|
||||
use std::collections::HashSet;
|
||||
use std::str::FromStr;
|
||||
|
||||
use aoc_runner_derive::{aoc, aoc_generator};
|
||||
use grid::{AsCoord2d, Grid};
|
||||
|
||||
#[aoc_generator(day7)]
|
||||
fn parse(input: &str) -> String {
|
||||
todo!()
|
||||
fn parse(input: &str) -> Grid<u8> {
|
||||
Grid::from_str(input).unwrap()
|
||||
}
|
||||
|
||||
//
|
||||
fn emit_beams(grid: &mut Grid<u8>, pos: impl AsCoord2d) -> u64 {
|
||||
match grid.get(&pos) {
|
||||
None | Some(b'|') => 0,
|
||||
Some(b'.') | Some(b'S') => {
|
||||
grid.set(&pos, b'|');
|
||||
emit_beams(grid, &(pos.x(), pos.y() + 1))
|
||||
}
|
||||
Some(b'^') => {
|
||||
grid.set(&pos, b'|');
|
||||
1 + emit_beams(grid, &(pos.x() - 1, pos.y()))
|
||||
+ emit_beams(grid, &(pos.x() + 1, pos.y()))
|
||||
}
|
||||
_ => panic!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[aoc(day7, part1)]
|
||||
fn part1(input: &str) -> u64 {
|
||||
0
|
||||
fn part1(input: &Grid<u8>) -> u64 {
|
||||
let mut grid = input.clone();
|
||||
emit_beams(&mut grid, input.find(&b'S').unwrap())
|
||||
}
|
||||
|
||||
#[aoc(day7, part2)]
|
||||
fn part2(input: &str) -> u64 {
|
||||
fn part2(input: &Grid<u8>) -> u64 {
|
||||
0
|
||||
}
|
||||
|
||||
@@ -18,11 +41,26 @@ fn part2(input: &str) -> u64 {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
const EXAMPLE: &str = "";
|
||||
const EXAMPLE: &str = ".......S.......
|
||||
...............
|
||||
.......^.......
|
||||
...............
|
||||
......^.^......
|
||||
...............
|
||||
.....^.^.^.....
|
||||
...............
|
||||
....^.^...^....
|
||||
...............
|
||||
...^.^...^.^...
|
||||
...............
|
||||
..^...^.....^..
|
||||
...............
|
||||
.^.^.^.^.^...^.
|
||||
...............";
|
||||
|
||||
#[test]
|
||||
fn part1_example() {
|
||||
assert_eq!(part1(&parse(EXAMPLE)), 0);
|
||||
assert_eq!(part1(&parse(EXAMPLE)), 21);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user