From a38fe82e85802ba9f66da8064a56badcc30b7c96 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sat, 3 Dec 2016 23:52:16 -0500 Subject: Day 3 --- src/bin/day03.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/bin/day03.rs (limited to 'src') diff --git a/src/bin/day03.rs b/src/bin/day03.rs new file mode 100644 index 0000000..8116acb --- /dev/null +++ b/src/bin/day03.rs @@ -0,0 +1,43 @@ +use std::io::{self, Read}; +use std::str::FromStr; + +struct Triangle(u32, u32, u32); + +impl Triangle { + fn valid(&self) -> bool { + self.0 + self.1 > self.2 + && self.1 + self.2 > self.0 + && self.0 + self.2 > self.1 + } +} + +impl FromStr for Triangle { + type Err = (); + fn from_str(s: &str) -> Result { + let mut iter = s.split_whitespace().map(str::parse); + match (iter.next(), iter.next(), iter.next()) { + (Some(Ok(a)), Some(Ok(b)), Some(Ok(c))) => Ok(Triangle(a, b, c)), + _ => Err(()), + } + } +} + +fn solve(input: &str) -> usize { + input.lines() + .map(str::parse) + .map(Result::unwrap) + .filter(Triangle::valid) + .count() +} + +fn main() { + let mut input = String::new(); + io::stdin().read_to_string(&mut input).unwrap(); + + println!("Part 1: {}", solve(&input)); +} + +#[test] +fn part1() { + assert_eq!(0, solve("5 10 25")); +} -- cgit 1.4.1 a>
Commit message (Collapse)Author
2024-06-16Update bioJune McEnroe
2024-06-15Add photo descriptions from June 12June McEnroe
2024-06-10Add first roll of film from June 8June McEnroe
2024-06-10Cope with not having an EXIF infoJune McEnroe
2024-06-10Resize using target pixel counts for consistencyJune McEnroe
This will resize film scans to about the same size as for the digital photos.
2024-06-10Add The Girl Who Was Convinced...June McEnroe
Not much there. The illustrations are very nice though.
2024-06-09Add photos from May 31June McEnroe
2024-06-09Use monospace on photo pagesJune McEnroe
2024-06-09Put lens and (future) film at the tops of photo pagesJune McEnroe
2024-05-22Remove use of sysexits.hJune McEnroe
2024-05-22Add photo descriptions from 05-03 and 05-06June McEnroe
2024-05-21Fix = precedence in whenJune McEnroe