aboutsummaryrefslogtreecommitdiff
path: root/2023/day-03/src/main.rs
blob: 43891cd8f5b3c5810b7429a7b8310795d0c719ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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");
    }
}