From 4bda1f89ef5c5108de853003c6ed88a764fc8859 Mon Sep 17 00:00:00 2001 From: calcu1on Date: Sun, 30 Mar 2025 12:56:36 -0400 Subject: [PATCH] Adding gitignore updates, changing around day4 to add directional based handling. --- .gitignore | 2 ++ 2024/rust/src/day4.rs | 35 +++++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 97c1023..ea20ab0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /target 2016/twenty16/target 2024/rust/target +2023/rust/target +*/target diff --git a/2024/rust/src/day4.rs b/2024/rust/src/day4.rs index 234ada9..d92cca3 100644 --- a/2024/rust/src/day4.rs +++ b/2024/rust/src/day4.rs @@ -2,17 +2,32 @@ use crate::Solution; use std::fs; use std::process; +struct Direction { + x: i32, + y: i32, +} + pub fn run_day_4() -> Solution { let file = fs::read_to_string("./inputs/day4test.txt").expect("Unable to parse file"); let search_map = build_search_map(&file); - // @here you are Dan - // this is now creating a vector which you can iterator over - // will need to work out logic to go through each letter - // and detect if it is part of a match or now - // somehow keeping track of past matches - // need to do in all directions and backwards - // this is...complicated. - dbg!(search_map[0][2]); + let directions: Vec<(i32, i32)> = vec![ + (0,1), // N + (0,-1), // S + (1,0), // E + (-1,0), // W + (1,1), // NE + (-1,1), // NW + (1,-1), // SE + (-1,-1), // SW + ]; + + // idea 3.0 + // iterate over each letter in the word search + // for each letter, build all possible words around it + // we know the character length is 4 (XMAS, SAMX) + // so if we have a given point, i.e. (3,4) + + dbg!(directions[0].0); // Return the solution let solution = Solution { @@ -23,6 +38,7 @@ pub fn run_day_4() -> Solution { solution } +// Builds a searchable map. fn build_search_map(row: &str) -> Vec> { let mut search_map: Vec> = vec!(); for line in row.lines() { @@ -32,8 +48,7 @@ fn build_search_map(row: &str) -> Vec> { search_map } - +// converts a line into a vectory of chars fn line_to_chars(row_line: &str) -> Vec { row_line.chars().collect() } -