diff options
author | Matias Linares <matias@deprecated.org> | 2023-12-04 09:58:27 -0300 |
---|---|---|
committer | Matias Linares <matias@deprecated.org> | 2023-12-04 09:58:27 -0300 |
commit | a73cbbc18cb365cfcb069cb712f55dc30325c974 (patch) | |
tree | 54738c0ae78e31a2bf6030cf51b37eddc43c4aa9 /2023/day-03/src | |
parent | a4e55ef3c10e2de2fd47e2b8b0042e7db790d937 (diff) | |
download | advent-of-code-a73cbbc18cb365cfcb069cb712f55dc30325c974.tar.gz |
Diffstat (limited to '2023/day-03/src')
-rw-r--r-- | 2023/day-03/src/main.rs | 38 | ||||
-rw-r--r-- | 2023/day-03/src/sample.txt | 10 |
2 files changed, 48 insertions, 0 deletions
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<Number> = 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<Number>, 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.. |