summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorReiner Herrmann <reiner@reiner-h.de>2022-10-02 21:48:53 +0200
committerReiner Herrmann <reiner@reiner-h.de>2022-10-02 21:48:53 +0200
commitf3833dc637840fca55f253c9f362641499aa42be (patch)
treeda2a8001fe112d604e0a693946b4e29fcb84d9bb /src/lib.rs
parentf582b42c798f2f9f80e41e6bcc7ce4d637a239e7 (diff)
day17
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 501b2f7..f0199c7 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,3 +1,6 @@
+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()
@@ -8,3 +11,9 @@ pub fn read_lines(day: u8) -> Vec<String> {
.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>>()
+}