This commit is contained in:
2016-12-03 11:50:36 +01:00
parent 48ca0dc28f
commit 4042eaf9f0
4 changed files with 1698 additions and 0 deletions

4
2016/03/Cargo.lock generated Normal file
View File

@@ -0,0 +1,4 @@
[root]
name = "03"
version = "0.1.0"

6
2016/03/Cargo.toml Normal file
View File

@@ -0,0 +1,6 @@
[package]
name = "03"
version = "0.1.0"
authors = ["logaritmisk <anders.e.olsson@gmail.com>"]
[dependencies]

1635
2016/03/input.txt Normal file

File diff suppressed because it is too large Load Diff

53
2016/03/src/main.rs Normal file
View File

@@ -0,0 +1,53 @@
use std::io::{self, BufRead};
fn main() {
let stdin = io::stdin();
let input = stdin.lock()
.lines()
.filter_map(|line| line.ok())
.map(|line| {
line
.split_whitespace()
.filter_map(|x| x.parse::<i32>().ok())
.collect::<Vec<_>>()
})
.collect::<Vec<_>>();
let count_h = input
.iter()
.filter(|x| is_triangle(x[0], x[1], x[2]))
.count();
let count_v = input
.chunks(3)
.flat_map(|x| {
x[0]
.iter()
.zip(&x[1])
.zip(&x[2])
.map(|((x, y), z)| [x, y, z])
})
.filter(|x| is_triangle(*x[0], *x[1], *x[2]))
.count();
println!("count={}", count_h);
println!("count={}", count_v);
}
fn is_triangle(a: i32, b: i32, c: i32) -> bool {
a + b > c && b + c > a && c + a > b
}
#[cfg(test)]
mod tests {
use super::is_triangle;
#[test]
fn example_01() {
assert_eq!(false, is_triangle(5, 10, 25));
assert_eq!(false, is_triangle(10, 25, 5));
assert_eq!(false, is_triangle(25, 10, 5));
}
}