day_03 init

This commit is contained in:
2023-12-06 08:15:43 +01:00
parent 7987d3359f
commit e5fa6d3f7c
3 changed files with 42 additions and 0 deletions

8
day_03/Cargo.toml Normal file
View File

@@ -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]

0
day_03/input Normal file
View File

34
day_03/src/main.rs Normal file
View File

@@ -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<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
where
P: AsRef<Path>,
{
let file = File::open(filename)?;
Ok(io::BufReader::new(file).lines())
}