From 576783c596fad672ad26d800635a5c4d6d72b3da Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Mon, 4 Dec 2017 00:10:52 -0500 Subject: Day 4 --- 2017/src/bin/day04.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 2017/src/bin/day04.rs (limited to '2017/src/bin') diff --git a/2017/src/bin/day04.rs b/2017/src/bin/day04.rs new file mode 100644 index 0000000..2d6ca52 --- /dev/null +++ b/2017/src/bin/day04.rs @@ -0,0 +1,27 @@ +use std::collections::HashSet; +use std::io::{self, Read}; + +fn solve1(input: &str) -> u32 { + let mut valid = 0; + for phrase in input.lines() { + let words = phrase.split_whitespace(); + if words.clone().count() == words.collect::>().len() { + valid += 1; + } + } + valid +} + +fn main() { + let mut input = String::new(); + io::stdin().read_to_string(&mut input).unwrap(); + + println!("Part 1: {}", solve1(&input)); +} + +#[test] +fn part1() { + assert_eq!(1, solve1("aa bb cc dd ee")); + assert_eq!(0, solve1("aa bb cc dd aa")); + assert_eq!(1, solve1("aa bb cc dd aaa")); +} -- cgit 1.4.1