diff --git a/2019/Cargo.lock b/2019/Cargo.lock new file mode 100644 index 0000000..4389501 --- /dev/null +++ b/2019/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "advent-of-code" +version = "0.1.0" + diff --git a/2019/Cargo.toml b/2019/Cargo.toml new file mode 100644 index 0000000..847bb75 --- /dev/null +++ b/2019/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "advent-of-code" +version = "0.1.0" +authors = ["Wesley Moore "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2019/input/day1.txt b/2019/input/day1.txt new file mode 100644 index 0000000..e5a5062 --- /dev/null +++ b/2019/input/day1.txt @@ -0,0 +1,100 @@ +90903 +135889 +120859 +137397 +56532 +92489 +87979 +149620 +137436 +62999 +71672 +61022 +139765 +69690 +109513 +67615 +77803 +146519 +96432 +129440 +67912 +143886 +126992 +129921 +122339 +61684 +149706 +52779 +106421 +145896 +145977 +76585 +136021 +63976 +97063 +114899 +118570 +102196 +129126 +98521 +136186 +68054 +72452 +92433 +145851 +98487 +149980 +114477 +125479 +62351 +131559 +115553 +129371 +147164 +83125 +146200 +68621 +55982 +79131 +64907 +95570 +132347 +76889 +96461 +123627 +128180 +113508 +70342 +139386 +131234 +140377 +119825 +80791 +52090 +62615 +101366 +138512 +113752 +77912 +64447 +146047 +94578 +82228 +116731 +123488 +103839 +120854 +54663 +129242 +51587 +149536 +71096 +110104 +145155 +139278 +78799 +62410 +64645 +112849 +60402 diff --git a/2019/src/bin/day1.rs b/2019/src/bin/day1.rs new file mode 100644 index 0000000..a4ec704 --- /dev/null +++ b/2019/src/bin/day1.rs @@ -0,0 +1,15 @@ +use std::io; + +use advent_of_code::input; + +fn main() -> io::Result<()> { + // Specifically, to find the fuel required for a module, take its mass, divide by three, round down, and subtract 2. + let result: i32 = input::read_number_list("input/day1.txt")? + .into_iter() + .map(|module_mass| (module_mass as f64 / 3.).floor() as i32 - 2) + .sum(); + + println!("Result: {}", result); + + Ok(()) +} diff --git a/2019/src/input.rs b/2019/src/input.rs new file mode 100644 index 0000000..31a06e6 --- /dev/null +++ b/2019/src/input.rs @@ -0,0 +1,19 @@ +use std::fs::File; +use std::io; +use std::io::{BufRead, BufReader}; +use std::path::Path; + +pub fn read_number_list>(path: P) -> io::Result> { + let input = BufReader::new(File::open(path)?); + let mut output = Vec::new(); + + for line in input.lines() { + let line = line?; + output.push( + line.parse() + .map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err))?, + ) + } + + Ok(output) +} diff --git a/2019/src/lib.rs b/2019/src/lib.rs new file mode 100644 index 0000000..7839bc5 --- /dev/null +++ b/2019/src/lib.rs @@ -0,0 +1 @@ +pub mod input;