Initial Commit
This commit is contained in:
commit
bbdab23098
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
input.txt
|
||||||
|
target
|
11
Cargo.lock
generated
Normal file
11
Cargo.lock
generated
Normal 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
7
Cargo.toml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
[workspace]
|
||||||
|
|
||||||
|
resolver = "2"
|
||||||
|
members = [
|
||||||
|
"d01t1",
|
||||||
|
"d01t2",
|
||||||
|
]
|
7
d01t1/Cargo.lock
generated
Normal file
7
d01t1/Cargo.lock
generated
Normal 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
8
d01t1/Cargo.toml
Normal 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
16
d01t1/src/main.rs
Normal 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
7
d01t2/Cargo.lock
generated
Normal 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
8
d01t2/Cargo.toml
Normal 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
26
d01t2/src/main.rs
Normal 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}");
|
||||||
|
}
|
Loading…
Reference in a new issue