From 1aa91374c7d13c69ef25569d8a2a6334edad4be2 Mon Sep 17 00:00:00 2001 From: calcu1on Date: Sat, 29 Mar 2025 22:08:18 -0400 Subject: [PATCH] Adding initial processing of file into a searchable map. --- 2024/rust/src/day4.rs | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/2024/rust/src/day4.rs b/2024/rust/src/day4.rs index ef8b0da..234ada9 100644 --- a/2024/rust/src/day4.rs +++ b/2024/rust/src/day4.rs @@ -1,15 +1,39 @@ use crate::Solution; +use std::fs; +use std::process; 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]); - // Lets solve day 4 here! - + // Return the solution let solution = Solution { day: 4, answer_1: "test".to_string(), answer_2: "another".to_string(), }; - solution - } + +fn build_search_map(row: &str) -> Vec> { + let mut search_map: Vec> = vec!(); + for line in row.lines() { + let char_vec: Vec = line_to_chars(&line); + search_map.push(char_vec.clone()); + } + search_map +} + + +fn line_to_chars(row_line: &str) -> Vec { + row_line.chars().collect() +} +