Cleaned up day 6
This commit is contained in:
parent
f2d593837e
commit
0956d914c7
1 changed files with 5 additions and 4 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue