From 94f5dfb200c6b89b3a4dbd5eb97e608a632e5c2f Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sun, 4 Dec 2016 14:39:35 -0800 Subject: [PATCH] [2016][rust][3.1] --- 2016/rust/src/day_03.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/2016/rust/src/day_03.rs b/2016/rust/src/day_03.rs index 4f9499c..f8b34b5 100644 --- a/2016/rust/src/day_03.rs +++ b/2016/rust/src/day_03.rs @@ -1,12 +1,21 @@ pub fn solve(input: &str) -> String { - let parsed = input.split_whitespace() - .map(str::parse) - .collect::, _>>() - .expect("unable to parse input"); + let parsed = input.lines() + .map(|line| { + line.split_whitespace().map(str::parse).collect::, _>>() + }) + .collect::, _>>() + .expect("couldn't parse input"); let count = parsed.chunks(3) - .map(|w| Triangle(w[0], w[1], w[2])) + .flat_map(|chunk| { + vec![ + Triangle(chunk[0][0], chunk[1][0], chunk[2][0]), + Triangle(chunk[0][1], chunk[1][1], chunk[2][1]), + Triangle(chunk[0][2], chunk[1][2], chunk[2][2]), + ] + }) .filter(Triangle::is_valid) .count(); + count.to_string() }