solve 2016 day 03

This commit is contained in:
fuckwit 2023-11-17 18:15:10 +01:00
parent 2e5fb4cf38
commit 96edd60a7c

View File

@ -1,13 +1,47 @@
use crate::util::parse::ParseExt;
pub fn part1(input: &str) -> impl std::fmt::Display {
//let vec: Vec<Vec<u32>> = input.lines().map(|s| s.u32s().collect());
fn valid_triangle(v: &[u32; 3]) -> bool {
v[0] + v[1] > v[2] && v[1] + v[2] > v[0] && v[0] + v[2] > v[1]
}
""
pub fn part1(input: &str) -> impl std::fmt::Display {
input
.lines()
.map(|s| {
s.u32s()
.fold(([0u32; 3], 0), |(mut a, i), v| {
a[i] = v;
(a, i + 1)
})
.0
})
.filter(valid_triangle)
.count()
}
pub fn part2(input: &str) -> impl std::fmt::Display {
""
fn get3<'a>(lines: &'a mut std::str::Lines<'_>) -> Option<(&'a str, &'a str, &'a str)> {
Some((lines.next()?, lines.next()?, lines.next()?))
}
let mut lines = input.lines();
let mut valid = 0;
while let Some((l1, l2, l3)) = get3(&mut lines) {
let l1: Vec<u32> = l1.u32s().collect();
let l2: Vec<u32> = l2.u32s().collect();
let l3: Vec<u32> = l3.u32s().collect();
if valid_triangle(&[l1[0], l2[0], l3[0]]) {
valid += 1;
}
if valid_triangle(&[l1[1], l2[1], l3[1]]) {
valid += 1;
}
if valid_triangle(&[l1[2], l2[2], l3[2]]) {
valid += 1;
}
}
valid
}
#[test]