day one part one

main
Zynh0722 2023-12-01 01:10:18 -08:00
commit f0e5a71c84
6 changed files with 1037 additions and 0 deletions

1
one/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

7
one/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 = "one"
version = "0.1.0"

8
one/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "one"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

1000
one/input Normal file

File diff suppressed because it is too large Load Diff

1
one/output Normal file
View File

@ -0,0 +1 @@
54304

20
one/src/main.rs Normal file
View File

@ -0,0 +1,20 @@
use std::io::{self, Read};
fn main() {
let mut buf = String::new();
io::stdin().read_to_string(&mut buf).unwrap();
let lines: Vec<String> = buf.lines().map(ToOwned::to_owned).collect();
let answer: Result<i32, _> = lines
.into_iter()
.map(|l| l.chars().filter(char::is_ascii_digit).collect())
.map(|s: String| [s.chars().next().unwrap(), s.chars().last().unwrap()].to_owned())
.map(String::from_iter)
.map(|s| s.parse::<i32>())
.sum();
let answer = answer.unwrap();
print!("{answer}");
}