diff options
| author | Reiner Herrmann <reiner@reiner-h.de> | 2024-12-01 12:58:43 +0100 |
|---|---|---|
| committer | Reiner Herrmann <reiner@reiner-h.de> | 2024-12-01 12:58:43 +0100 |
| commit | 62bbd3daa3083351a4e266e75f1b0afe12079f58 (patch) | |
| tree | 7a6b8ace6e6fc0b993ad39e73f8869b8d8915923 /src | |
| parent | 961d1bdb938a112c05e709b90b0ab8291fe8ba8c (diff) | |
Add helper lib
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>>() +} |
