|
|
|
@ -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()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|