From a73cbbc18cb365cfcb069cb712f55dc30325c974 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Mon, 4 Dec 2023 09:58:27 -0300 Subject: [WIP] day3 part1 --- 2023/day-03/.projectile | 0 2023/day-03/Cargo.lock | 7 +++++++ 2023/day-03/Cargo.toml | 8 ++++++++ 2023/day-03/src/main.rs | 38 ++++++++++++++++++++++++++++++++++++++ 2023/day-03/src/sample.txt | 10 ++++++++++ 5 files changed, 63 insertions(+) create mode 100644 2023/day-03/.projectile create mode 100644 2023/day-03/Cargo.lock create mode 100644 2023/day-03/Cargo.toml create mode 100644 2023/day-03/src/main.rs create mode 100644 2023/day-03/src/sample.txt (limited to '2023/day-03') diff --git a/2023/day-03/.projectile b/2023/day-03/.projectile new file mode 100644 index 0000000..e69de29 diff --git a/2023/day-03/Cargo.lock b/2023/day-03/Cargo.lock new file mode 100644 index 0000000..17695b0 --- /dev/null +++ b/2023/day-03/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "day-03" +version = "0.1.0" diff --git a/2023/day-03/Cargo.toml b/2023/day-03/Cargo.toml new file mode 100644 index 0000000..51cc795 --- /dev/null +++ b/2023/day-03/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "day-03" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2023/day-03/src/main.rs b/2023/day-03/src/main.rs new file mode 100644 index 0000000..43891cd --- /dev/null +++ b/2023/day-03/src/main.rs @@ -0,0 +1,38 @@ +#[derive(Debug)] +struct Number { + position: (usize, usize), + string: String, +} + +impl Number { +} + +fn main() { + let input = include_str!("./sample.txt"); + let v: Vec = input.lines() + .map(|line: &str| { + let numbers: Vec<&str> = line + .split(|c: char| { !c.is_alphanumeric() }) + .filter(|v| { v.len() > 0 }) + .collect(); + numbers.iter().enumerate().map(|(idx, number)| { + line.match_indices(number).map(|(pos, string)| -> &mut Number { + &mut Number { + position: (idx, pos), + string: String::from(string), + } + }).collect() + }).collect() + }) + .fold(vec!(), |acc: Vec, e| { acc.append(e) }); + dbg!(v); +} + +#[cfg(test)] +mod test { + use super::*; + + fn test_input() { + let _input = include_str!("./sample.txt"); + } +} diff --git a/2023/day-03/src/sample.txt b/2023/day-03/src/sample.txt new file mode 100644 index 0000000..b20187f --- /dev/null +++ b/2023/day-03/src/sample.txt @@ -0,0 +1,10 @@ +467..114.. +...*...... +..35..633. +......#... +617*...... +.....+.58. +..592..... +......755. +...$.*.... +.664.598.. -- cgit v1.2.3-70-g09d2