[2016][rust][3.1]

profile
Alpha Chen 8 years ago
parent d93aff516a
commit 94f5dfb200

@ -1,12 +1,21 @@
pub fn solve(input: &str) -> String {
let parsed = input.split_whitespace()
.map(str::parse)
.collect::<Result<Vec<usize>, _>>()
.expect("unable to parse input");
let parsed = input.lines()
.map(|line| {
line.split_whitespace().map(str::parse).collect::<Result<Vec<usize>, _>>()
})
.collect::<Result<Vec<_>, _>>()
.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()
}

Loading…
Cancel
Save