summaryrefslogtreecommitdiff
path: root/src/lib.rs
blob: 9985bd8c1ff2bb0302531c27882dfd02ac258073 (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

pub fn read_file(day: u8) -> String {
    let filename = format!("inputs/day{}", day);
    std::fs::read_to_string(filename).unwrap()
}

pub fn read_all_lines(day: u8) -> Vec<String> {
    read_file(day).split('\n')
                  .map(String::from)
                  .collect()
}

pub fn read_lines(day: u8) -> Vec<String> {
    read_file(day).split('\n')
                  .filter(|n| !n.is_empty())
                  .map(String::from)
                  .collect()
}

pub fn read_numbers(day: u8) -> Vec<usize> {
    read_lines(day).iter()
                   .map(|n| n.parse::<usize>().unwrap())
                   .collect()
}