Skip to content

Commit

Permalink
more day 13 stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
bozdoz committed Dec 14, 2023
1 parent 26c9105 commit 9a7967f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
15 changes: 15 additions & 0 deletions day-13/src/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#.##..##.
..#.##.#.
##......#
##......#
..#.##.#.
..##..##.
#.#.##.#.

#...##..#
#....#..#
..##..###
#####.##.
#####.##.
..##..###
#....#..#
28 changes: 21 additions & 7 deletions day-13/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ use lib::get_part;
/** identify the direction of the reflection, with the col/row */
enum Reflection {
Horizontal(usize),
Vertical(usize)
Vertical(usize),
None
}

#[derive(Debug, PartialEq)]
enum Item {
Ash,
Rock
Expand Down Expand Up @@ -39,14 +41,23 @@ impl Pattern {
Self { grid }
}

fn find_reflection_point() -> Reflection {
fn find_reflection_point(&self) -> Reflection {
// size 2 means we look for side-by-side matches first
dbg!(&self.grid);
for row in self.grid.windows(2) {
if row[0] == row[1] {
dbg!(row);
}
}

Reflection::Horizontal(0)
// we might not have any reflection
Reflection::None
}
}

fn part_one() -> usize {
0
fn part_one(patterns: &Vec<Pattern>) -> usize {
patterns[0].find_reflection_point();
1
}

fn part_two() -> usize {
Expand All @@ -58,9 +69,11 @@ fn main() {
let start = Instant::now();
let contents = fs::read_to_string("./src/input.txt").unwrap();

let patterns = contents.lines().map(Pattern::new).collect();

if one {
let now = Instant::now();
let ans = part_one();
let ans = part_one(&patterns);
println!("Part one: {:?} {:?}", ans, now.elapsed());
}

Expand All @@ -81,7 +94,8 @@ mod tests {

#[test]
fn test_part_one() {
let ans = part_one();
let patterns = EXAMPLE.split("\n\n").map(Pattern::new).collect();
let ans = part_one(&patterns);

assert_eq!(ans, 0);
}
Expand Down

0 comments on commit 9a7967f

Please sign in to comment.