day one part one
commit
f0e5a71c84
|
@ -0,0 +1 @@
|
|||
/target
|
|
@ -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"
|
|
@ -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]
|
|
@ -0,0 +1 @@
|
|||
54304
|
|
@ -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 New Issue