Skip to content

Commit a7d5112

Browse files
committed
base day6
1 parent 6b21e80 commit a7d5112

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

inputs/2024/day6_test.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
....#.....
2+
.........#
3+
..........
4+
..#.......
5+
.......#..
6+
..........
7+
.#..^.....
8+
........#.
9+
#.........
10+
......#...

src/aoc2024/day6.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
use crate::aoc2024::Aoc2024;
2+
use crate::grid::Grid;
3+
use crate::traits::days::Day6;
4+
use crate::traits::ParseInput;
5+
use crate::traits::Solution;
6+
7+
impl ParseInput<Day6> for Aoc2024 {
8+
type Parsed = (Grid<bool>, usize, usize);
9+
10+
fn parse_input(input: &str) -> Self::Parsed {
11+
let mut sx = 0;
12+
let mut sy = 0;
13+
let grid = Grid::parse(input, |c| c);
14+
15+
let mut bgrid = Grid::new(grid.width, grid.height, false);
16+
grid.iter().for_each(|(x, y, &c)| {
17+
let val = match c {
18+
'#' => true,
19+
'.' => false,
20+
'^' => {
21+
sx = x;
22+
sy = y;
23+
false
24+
}
25+
_ => unreachable!(),
26+
};
27+
bgrid.set(x, y, val);
28+
});
29+
(bgrid, sx, sy)
30+
}
31+
}
32+
33+
impl Solution<Day6> for Aoc2024 {
34+
type Part1Output = u32;
35+
type Part2Output = u32;
36+
37+
fn part1((grid, sx, sy): &(Grid<bool>, usize, usize)) -> u32 {
38+
let (mut x, mut y) = (*sx, *sy);
39+
let (mut dx, mut dy) = (0, -1);
40+
41+
loop {
42+
let (nx, ny) = (x.offset(dx), y.offset(dy));
43+
}
44+
}
45+
46+
fn part2(_input: &(Grid<bool>, usize, usize)) -> u32 {
47+
todo!()
48+
}
49+
}
50+
51+
fn offset_pair(grid: &Grid<bool>, x: usize, y: usize, dx: isize, dy: isize) -> Option<(usize, usize)> {
52+
let nx = offset(x, dx, grid.width) else { return None };
53+
let ny = offset(y, dy,grid.height) else { return None };
54+
(nx, ny)
55+
}
56+
57+
fn offset(base: usize, offset: isize, max: usize) -> Option<usize> {
58+
let res = base as isize + offset;
59+
60+
if res < 0 || res >= max as isize {
61+
return None;
62+
}
63+
64+
Some(res as usize)
65+
}

src/aoc2024/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub mod day2;
88
pub mod day3;
99
pub mod day4;
1010
pub mod day5;
11+
pub mod day6;
1112

1213
pub fn run_solution_for_day(day: u32, input: &str, results: Option<Results>) -> Option<TimingData> {
1314
let r = results
@@ -20,6 +21,7 @@ pub fn run_solution_for_day(day: u32, input: &str, results: Option<Results>) ->
2021
3 => run::<Aoc2024, Day3>(input, r),
2122
4 => run::<Aoc2024, Day4>(input, r),
2223
5 => run::<Aoc2024, Day5>(input, r),
24+
6 => run::<Aoc2024, Day6>(input, r),
2325
_ => return None,
2426
};
2527
Some(elapsed)

0 commit comments

Comments
 (0)