From 86a3a036a0df7b43f14738e072e698db76244a24 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sat, 2 Dec 2017 16:11:24 -0800 Subject: [PATCH] [2017][rust][2.1] --- 2017/rust/src/day_02.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/2017/rust/src/day_02.rs b/2017/rust/src/day_02.rs index f8d495a..8c0da5c 100644 --- a/2017/rust/src/day_02.rs +++ b/2017/rust/src/day_02.rs @@ -17,7 +17,16 @@ pub fn solve(input: &str) -> Result { } fn checksum(row: &[usize]) -> usize { - let min = row.iter().min().unwrap(); - let max = row.iter().max().unwrap(); - max - min + // 1 + // let min = row.iter().min().unwrap(); + // let max = row.iter().max().unwrap(); + // max - min + + row.iter() + .flat_map(|x| row.iter().map(|y| (x, y)).collect::>()) + .filter(|&(a,b)| a != b) + .filter(|&(&a,&b)| (a as f64) % (b as f64) == 0.0) + .map(|(&a,&b)| a / b) + .next() + .unwrap() }