From bbdab230987b4d74e3ffa3678892205d0af2ea4f Mon Sep 17 00:00:00 2001 From: BlackDemonFire Date: Fri, 1 Dec 2023 09:56:57 +0100 Subject: [PATCH] Initial Commit --- .gitignore | 2 ++ Cargo.lock | 11 +++++++++++ Cargo.toml | 7 +++++++ d01t1/Cargo.lock | 7 +++++++ d01t1/Cargo.toml | 8 ++++++++ d01t1/src/main.rs | 16 ++++++++++++++++ d01t2/Cargo.lock | 7 +++++++ d01t2/Cargo.toml | 8 ++++++++ d01t2/src/main.rs | 26 ++++++++++++++++++++++++++ 9 files changed, 92 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 d01t1/Cargo.lock create mode 100644 d01t1/Cargo.toml create mode 100644 d01t1/src/main.rs create mode 100644 d01t2/Cargo.lock create mode 100644 d01t2/Cargo.toml create mode 100644 d01t2/src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ef46287 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +input.txt +target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..44615a6 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,11 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "d01t1" +version = "0.1.0" + +[[package]] +name = "d01t2" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..a055adb --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,7 @@ +[workspace] + +resolver = "2" +members = [ + "d01t1", + "d01t2", +] diff --git a/d01t1/Cargo.lock b/d01t1/Cargo.lock new file mode 100644 index 0000000..e5e8e59 --- /dev/null +++ b/d01t1/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "d01t1" +version = "0.1.0" diff --git a/d01t1/Cargo.toml b/d01t1/Cargo.toml new file mode 100644 index 0000000..7b16af1 --- /dev/null +++ b/d01t1/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "d01t1" +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/d01t1/src/main.rs b/d01t1/src/main.rs new file mode 100644 index 0000000..e0196f2 --- /dev/null +++ b/d01t1/src/main.rs @@ -0,0 +1,16 @@ +fn main() { + let input = include_str!("../input.txt"); + let result = input + .lines() + .map(|line| { + let digits = line + .chars() + .filter(|c| c.is_ascii_digit()) + .collect::>(); + let mut num_str = digits.first().unwrap().to_string(); + num_str.push(*digits.last().unwrap()); + num_str.parse::().unwrap() + }) + .sum::(); + println!("d01t1: {result}"); +} diff --git a/d01t2/Cargo.lock b/d01t2/Cargo.lock new file mode 100644 index 0000000..6b79282 --- /dev/null +++ b/d01t2/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "d01t2" +version = "0.1.0" diff --git a/d01t2/Cargo.toml b/d01t2/Cargo.toml new file mode 100644 index 0000000..b6fc1a9 --- /dev/null +++ b/d01t2/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "d01t2" +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/d01t2/src/main.rs b/d01t2/src/main.rs new file mode 100644 index 0000000..e84c966 --- /dev/null +++ b/d01t2/src/main.rs @@ -0,0 +1,26 @@ +fn main() { + let input = include_str!("../input.txt"); + let translated = input + .replace("one", "o1e") + .replace("two", "t2o") + .replace("three", "t3e") + .replace("four", "f4r") + .replace("five", "f5e") + .replace("six", "s6x") + .replace("seven", "s7n") + .replace("eight", "e8t") + .replace("nine", "n9e"); + let result = translated + .lines() + .map(|line| { + let digits = line + .chars() + .filter(|c| c.is_ascii_digit()) + .collect::>(); + let mut num_str = digits.first().unwrap().to_string(); + num_str.push(*digits.last().unwrap()); + num_str.parse::().unwrap() + }) + .sum::(); + println!("d01t2: {result}"); +}