summary refs log tree commit diff homepage
path: root/2017
diff options
context:
space:
mode:
Diffstat (limited to '2017')
-rw-r--r--2017/src/bin/day04.rs28
1 files changed, 27 insertions, 1 deletions
diff --git a/2017/src/bin/day04.rs b/2017/src/bin/day04.rs
index 2d6ca52..784a246 100644
--- a/2017/src/bin/day04.rs
+++ b/2017/src/bin/day04.rs
@@ -5,7 +5,23 @@ 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() {
+        if words.clone().count() == words.collect::<HashSet<_>>().len() {
+            valid += 1;
+        }
+    }
+    valid
+}
+
+fn solve2(input: &str) -> u32 {
+    let mut valid = 0;
+    for phrase in input.lines() {
+        let count = phrase.split_whitespace().count();
+        let words = phrase.split_whitespace()
+            .map(str::chars)
+            .map(Iterator::collect::<Vec<_>>)
+            .map(|mut v| { v.sort(); v })
+            .collect::<HashSet<_>>();
+        if count == words.len() {
             valid += 1;
         }
     }
@@ -17,6 +33,7 @@ fn main() {
     io::stdin().read_to_string(&mut input).unwrap();
 
     println!("Part 1: {}", solve1(&input));
+    println!("Part 2: {}", solve2(&input));
 }
 
 #[test]
@@ -25,3 +42,12 @@ fn part1() {
     assert_eq!(0, solve1("aa bb cc dd aa"));
     assert_eq!(1, solve1("aa bb cc dd aaa"));
 }
+
+#[test]
+fn part2() {
+    assert_eq!(1, solve2("abcde fghij"));
+    assert_eq!(0, solve2("abcde xyz ecdab"));
+    assert_eq!(1, solve2("a ab abc abd abf abj"));
+    assert_eq!(1, solve2("iiii oiii ooii oooi oooo"));
+    assert_eq!(0, solve2("oiii ioii iioi iiio"));
+}
ass='logmsg'> 2018-04-03Add House of LeavesJune McEnroe 2018-04-03Add ChromaticsJune McEnroe 2018-04-03Add those new Arcade Fire singlesJune McEnroe 2018-04-03Add SermonJune McEnroe 2018-04-03Add Pools of LightJune McEnroe 2018-04-03Add SteroidsJune McEnroe 2018-04-03Add A Common TruthJune McEnroe 2018-04-03Add new Colin Stetson albumJune McEnroe 2018-04-03Add ForgetJune McEnroe 2018-04-03Add ArcaJune McEnroe 2018-04-03Add new DMST and Joni VoidJune McEnroe 2018-04-03Add The Body LoversJune McEnroe 2018-04-03Add some albums from recentlyJune McEnroe 2018-04-03Add Saltland Light of MercyJune McEnroe 2018-04-03Add Jessica Moss GlaciersJune McEnroe 2018-04-03Add BNNY RBBTJune McEnroe 2018-04-03Add DepthsJune McEnroe 2018-04-03Add new Saltland previewJune McEnroe 2018-04-03Add BenjiJune McEnroe 2018-04-03Add Mouth MoodsJune McEnroe 2018-04-03Add Those Who Walk AwayJune McEnroe 2018-04-03Add Some TunesJune McEnroe 2018-04-03Add Pas pire popJune McEnroe 2018-04-03Add I Give You PowerJune McEnroe 2018-04-03Add Jenny GoGoJune McEnroe 2018-04-03Add KKB Fish BowlJune McEnroe 2018-04-03Add new Avec le soleil album previewJune McEnroe 2018-04-03Add Julien Baker as recent new musicJune McEnroe 2018-04-03Add recent new musicJune McEnroe