From e5fa6d3f7ce5bb4cb69b33629f356c6e18aa55b4 Mon Sep 17 00:00:00 2001 From: Christian Nachtigall Date: Wed, 6 Dec 2023 08:15:43 +0100 Subject: [PATCH] day_03 init --- day_03/Cargo.toml | 8 ++++++++ day_03/input | 0 day_03/src/main.rs | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 day_03/Cargo.toml create mode 100644 day_03/input create mode 100644 day_03/src/main.rs diff --git a/day_03/Cargo.toml b/day_03/Cargo.toml new file mode 100644 index 0000000..08ffcb3 --- /dev/null +++ b/day_03/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "day_03" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/day_03/input b/day_03/input new file mode 100644 index 0000000..e69de29 diff --git a/day_03/src/main.rs b/day_03/src/main.rs new file mode 100644 index 0000000..9f91d18 --- /dev/null +++ b/day_03/src/main.rs @@ -0,0 +1,34 @@ +use std::fs::File; +use std::io::{self, BufRead}; +use std::path::Path; + +fn main() { + // File input must exist in the current path + if let Ok(lines) = read_lines("./input") { + let mut total_part_1: u64 = 0; + let mut total_part_2: u64 = 0; + + // Consumes the iterator, returns an (Optional) String + for line in lines { + if let Ok(mut l) = line { + // Part 1 + + // Part 2 + + } + } + + println!("Total of part 1 is {}", total_part_1); + println!("Total of part 2 is {}", total_part_2); + } +} + +// The output is wrapped in a Result to allow matching on errors +// Returns an Iterator to the Reader of the lines of the file. +fn read_lines

(filename: P) -> io::Result>> +where + P: AsRef, +{ + let file = File::open(filename)?; + Ok(io::BufReader::new(file).lines()) +}