summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
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>>()
+}