day one part one
This commit is contained in:
commit
f0e5a71c84
6 changed files with 1037 additions and 0 deletions
1
one/.gitignore
vendored
Normal file
1
one/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
7
one/Cargo.lock
generated
Normal file
7
one/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 = "one"
|
||||
version = "0.1.0"
|
8
one/Cargo.toml
Normal file
8
one/Cargo.toml
Normal 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]
|
1
one/output
Normal file
1
one/output
Normal file
|
@ -0,0 +1 @@
|
|||
54304
|
20
one/src/main.rs
Normal file
20
one/src/main.rs
Normal 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}");
|
||||
}
|
Loading…
Reference in a new issue