2020-12-05 23:10:59 -06:00
|
|
|
import streams, sets, strutils, sequtils
|
|
|
|
|
2020-12-05 23:34:12 -06:00
|
|
|
proc asGroups(s: Stream): seq[seq[string]] =
|
|
|
|
s.readAll.split("\n\n").mapIt it.split("\n").filterIt(it != "")
|
|
|
|
|
2020-12-05 23:10:59 -06:00
|
|
|
proc part1*(s: Stream): int =
|
2020-12-05 23:34:12 -06:00
|
|
|
s.asGroups.mapIt(it.foldl(a.union(b.toHashSet), initHashSet[char]()).len).foldl a + b
|
2020-12-05 23:10:59 -06:00
|
|
|
|
|
|
|
proc part2*(s: Stream): int =
|
2020-12-05 23:34:12 -06:00
|
|
|
s.asGroups.mapIt(it.foldl(a.intersection(b.toHashSet), toSeq('a'..'z').toHashSet).len).foldl(a + b)
|