From 0956d914c7e3fac27d6716fc20dfade652ba4170 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Sat, 5 Dec 2020 23:34:12 -0600 Subject: [PATCH] Cleaned up day 6 --- 2020/src/day6.nim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/2020/src/day6.nim b/2020/src/day6.nim index 2e698d6..40d18dd 100644 --- a/2020/src/day6.nim +++ b/2020/src/day6.nim @@ -1,9 +1,10 @@ import streams, sets, strutils, sequtils +proc asGroups(s: Stream): seq[seq[string]] = + s.readAll.split("\n\n").mapIt it.split("\n").filterIt(it != "") + proc part1*(s: Stream): int = - s.readAll().split("\n\n").mapIt(it.split("\n").foldl(a.union(b.toHashSet), initHashSet[char]()).len).foldl(a + b) + s.asGroups.mapIt(it.foldl(a.union(b.toHashSet), initHashSet[char]()).len).foldl a + b proc part2*(s: Stream): int = - s.readAll().split("\n\n").mapIt( - it.split("\n").filterIt(it != "").foldl(a.intersection(b.toHashSet), "abcdefghijklmnopqrstuvwxyz".toHashSet()).len - ).foldl(a + b) + s.asGroups.mapIt(it.foldl(a.intersection(b.toHashSet), toSeq('a'..'z').toHashSet).len).foldl(a + b)