[2017][rust][2.0]

sorbet
Alpha Chen 7 years ago
parent 68c7b41fc6
commit 7d36ddd8fe

@ -0,0 +1,19 @@
use failure::*;
pub fn solve(input: &str) -> Result<String, Error> {
Ok(
input
.trim()
.split("\n")
.map(|row| {
let row: Vec<_> = row.split("\t")
.map(|x| x.parse::<usize>().unwrap())
.collect();
let min = row.iter().min().unwrap();
let max = row.iter().max().unwrap();
max - min
})
.sum::<usize>()
.to_string(),
)
}

@ -5,6 +5,7 @@ use std::io::{self, Read};
use failure::Error;
mod day_01;
mod day_02;
fn main() {
if let Err(e) = run() {
@ -16,7 +17,7 @@ fn run() -> Result<(), Error> {
let mut input = String::new();
io::stdin().read_to_string(&mut input)?;
let solution = day_01::solve(&input)?;
let solution = day_02::solve(&input)?;
println!("{}", solution);
Ok(())

Loading…
Cancel
Save