parent
2b7b747ca5
commit
d93aff516a
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,24 @@
|
||||
pub fn solve(input: &str) -> String {
|
||||
let parsed = input.split_whitespace()
|
||||
.map(str::parse)
|
||||
.collect::<Result<Vec<usize>, _>>()
|
||||
.expect("unable to parse input");
|
||||
let count = parsed.chunks(3)
|
||||
.map(|w| Triangle(w[0], w[1], w[2]))
|
||||
.filter(Triangle::is_valid)
|
||||
.count();
|
||||
count.to_string()
|
||||
}
|
||||
|
||||
struct Triangle(usize, usize, usize);
|
||||
impl Triangle {
|
||||
fn is_valid(&self) -> bool {
|
||||
self.0 + self.1 > self.2 && self.0 + self.2 > self.1 &&
|
||||
self.1 + self.2 > self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_triangle() {
|
||||
assert!(!Triangle(5, 10, 25).is_valid());
|
||||
}
|
@ -1,2 +1,3 @@
|
||||
pub mod day_01;
|
||||
pub mod day_02;
|
||||
pub mod day_03;
|
||||
|
Loading…
Reference in new issue