summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorReiner Herrmann <reiner@reiner-h.de>2022-12-01 18:35:12 +0100
committerReiner Herrmann <reiner@reiner-h.de>2022-12-01 20:30:08 +0100
commit422145f1d54f4706e047fb6bfe3ea35ef30e4c3a (patch)
tree37216cc748d3e4da191eead9cccde26ab6b12d53 /src
Initialize project
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs19
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>>()
+}