diff --git a/.gitignore b/.gitignore index 6769e21..00209f6 100644 --- a/.gitignore +++ b/.gitignore @@ -157,4 +157,19 @@ cython_debug/ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ \ No newline at end of file +#.idea/ + +# 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/Day01/coordinates.txt b/Day01/input.txt similarity index 100% rename from Day01/coordinates.txt rename to Day01/input.txt diff --git a/Day01/part1.py b/Day01/part1.py index 56b4798..9eeedb6 100644 --- a/Day01/part1.py +++ b/Day01/part1.py @@ -45,6 +45,6 @@ def sum_calibration_values(filename): # Main execution if __name__ == "__main__": - filename = "coordinates.txt" + filename = "input.txt" total_calibration_value = sum_calibration_values(filename) print(f"Total Sum of Calibration Values: {total_calibration_value}") diff --git a/Day01/part2.py b/Day01/part2.py index a23433b..f2043d5 100644 --- a/Day01/part2.py +++ b/Day01/part2.py @@ -47,6 +47,6 @@ def sum_calibration_values(file_path): # Main execution if __name__ == "__main__": import sys - filename = sys.argv[1] if len(sys.argv) > 1 else "coordinates.txt" + filename = sys.argv[1] if len(sys.argv) > 1 else "input.txt" total_calibration_value = sum_calibration_values(filename) print(f"Total Sum of Calibration Values: {total_calibration_value}") diff --git a/Day01/rust/Cargo.toml b/Day01/rust/Cargo.toml new file mode 100644 index 0000000..6ecc1cd --- /dev/null +++ b/Day01/rust/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "rust_solution_01" +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/Day01/rust/src/main.rs b/Day01/rust/src/main.rs new file mode 100644 index 0000000..b005cf2 --- /dev/null +++ b/Day01/rust/src/main.rs @@ -0,0 +1,97 @@ +use std::fs::File; +use std::io::{self, BufRead}; +use std::path::Path; + +fn main() { + let path = Path::new("../input.txt"); + match read_lines(path) { + Ok(lines) => { + let mut total = 0; + for line in lines { + if let Ok(ip) = line { + let value = extract_calibration_value(&ip); + println!("Line: '{}', Calibration Value: {}", ip, value); + total += value; + } + } + println!("Total Calibration Value: {}", total); + } + Err(e) => println!("Error: {}", e), + } +} + +// Function to read lines from a file +fn read_lines
(filename: P) -> io::Result