summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--Cargo.toml6
-rw-r--r--LICENSE21
-rw-r--r--src/bin/day_1.rs18
-rw-r--r--src/lib.rs23
5 files changed, 71 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6aa1064
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+/target/
+**/*.rs.bk
+Cargo.lock
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..a723369
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "advent_of_code_2018"
+version = "0.1.0"
+authors = ["Justin Worthe <justin@worthe-it.co.za>"]
+
+[dependencies]
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d3e83ae
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2018 Justin Worthe
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/src/bin/day_1.rs b/src/bin/day_1.rs
new file mode 100644
index 0000000..7c9cdbf
--- /dev/null
+++ b/src/bin/day_1.rs
@@ -0,0 +1,18 @@
+extern crate advent_of_code_2018;
+use advent_of_code_2018::*;
+
+use std::error::Error;
+use std::path::PathBuf;
+
+// cargo watch -cs "cargo run --bin day_1"
+
+fn main() -> Result<(), Box<Error>> {
+ let input = read_file(&PathBuf::from("inputs/1.txt"))?;
+
+ println!("Input: {:?}", input);
+
+
+
+
+ Ok(())
+}
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..01d6242
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,23 @@
+use std::path::PathBuf;
+use std::io::BufReader;
+use std::io::prelude::*;
+use std::fs::File;
+
+/// Reads a specified file into a vector of strings, one line of the
+/// file per string. Fails if any part of reading the file fails.
+pub fn read_file(file: &PathBuf) -> Result<Vec<String>, std::io::Error> {
+ let file = File::open(file)?;
+ let file_reader = BufReader::new(file);
+ file_reader.lines()
+ .collect::<Result<Vec<_>, _>>()
+ .map(preprocess_file_lines)
+}
+
+/// Removes any empty lines and makes sure that lines don't have
+/// problematic whitespace.
+pub fn preprocess_file_lines(lines: Vec<String>) -> Vec<String> {
+ lines.iter()
+ .filter(|line| line.len() > 0)
+ .map(|line| line.trim_right().to_string())
+ .collect()
+}