summary refs log tree commit diff homepage
path: root/2017/src/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2017-12-04 00:10:52 -0500
committerJune McEnroe <june@causal.agency>2020-11-22 00:14:25 -0500
commitf2de66c857cfad52cf52b056219c8db36f17062a (patch)
treef3b460554043b6e5902faaaeb764eba198c6c50a /2017/src/bin
parentDay 3, part 2 (diff)
downloadaoc-f2de66c857cfad52cf52b056219c8db36f17062a.tar.gz
aoc-f2de66c857cfad52cf52b056219c8db36f17062a.zip
Day 4
Diffstat (limited to '2017/src/bin')
-rw-r--r--2017/src/bin/day04.rs27
1 files changed, 27 insertions, 0 deletions
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::<HashSet<&str>>().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"));
+}