diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ada8be9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb \ No newline at end of file diff --git a/2023/01-trebuchet/input_test.txt b/2023/01-trebuchet/input_test.txt new file mode 100644 index 0000000..1ba8437 --- /dev/null +++ b/2023/01-trebuchet/input_test.txt @@ -0,0 +1,4 @@ +1abc2 +pqr3stu8vwx +a1b2c3d4e5f +treb7uchet \ No newline at end of file diff --git a/2023/01-trebuchet/src/main.rs b/2023/01-trebuchet/src/main.rs index e7a11a9..0584ac5 100644 --- a/2023/01-trebuchet/src/main.rs +++ b/2023/01-trebuchet/src/main.rs @@ -1,3 +1,6 @@ +mod part_one; + fn main() { - println!("Hello, world!"); + part_one::part_one(); + //part_two(); } diff --git a/2023/01-trebuchet/src/part_one.rs b/2023/01-trebuchet/src/part_one.rs new file mode 100644 index 0000000..c5553f1 --- /dev/null +++ b/2023/01-trebuchet/src/part_one.rs @@ -0,0 +1,49 @@ +// https://doc.rust-lang.org/stable/rust-by-example/std_misc/file/read_lines.html +use std::fs::File; +use std::io::{self, BufRead}; +use std::path::Path; + + +pub fn part_one() { + if let Ok(lines) = read_lines("./input.txt") { + + let mut result = 0; + + for line in lines { + result += parse_line(&line.unwrap()); + } + + println!("{}", result); + } +} + + + +fn read_lines
(filename: P) -> io::Result