Initial Commit

This commit is contained in:
BlackDemonFire 2023-12-01 09:56:57 +01:00
commit bbdab23098
Signed by: lucy
SSH key fingerprint: SHA256:5NG0Um+vQQHuWkYn+Vd84YFm10edFBJiOIpOuHjl8UE
9 changed files with 92 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
input.txt
target

11
Cargo.lock generated Normal file
View file

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

7
Cargo.toml Normal file
View file

@ -0,0 +1,7 @@
[workspace]
resolver = "2"
members = [
"d01t1",
"d01t2",
]

7
d01t1/Cargo.lock generated Normal file
View file

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

8
d01t1/Cargo.toml Normal file
View file

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

16
d01t1/src/main.rs Normal file
View file

@ -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::<Vec<char>>();
let mut num_str = digits.first().unwrap().to_string();
num_str.push(*digits.last().unwrap());
num_str.parse::<u32>().unwrap()
})
.sum::<u32>();
println!("d01t1: {result}");
}

7
d01t2/Cargo.lock generated Normal file
View file

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

8
d01t2/Cargo.toml Normal file
View file

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

26
d01t2/src/main.rs Normal file
View file

@ -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::<Vec<char>>();
let mut num_str = digits.first().unwrap().to_string();
num_str.push(*digits.last().unwrap());
num_str.parse::<u32>().unwrap()
})
.sum::<u32>();
println!("d01t2: {result}");
}