diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..f0199c7 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,19 @@ +use std::str::FromStr; +use std::fmt::Debug; + +pub fn read_file(day: u8) -> String { + let filename = format!("inputs/day{}", day); + std::fs::read_to_string(filename).unwrap() +} + +pub fn read_lines(day: u8) -> Vec<String> { + read_file(day).split_terminator('\n') + .map(String::from) + .collect() +} + +pub fn read_numbers<T: FromStr>(day: u8) -> Vec<T> where <T as FromStr>::Err: Debug { + read_lines(day).iter() + .map(|n| n.parse::<T>().unwrap()) + .collect::<Vec<T>>() +} |
