advent-of-code/2020/src/day6.nim
2020-12-06 00:17:17 -06:00

11 lines
404 B
Nim

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.asGroups.mapIt(it.foldl(a.union(b.toHashSet), initHashSet[char]()).len).foldl a + b
proc part2*(s: Stream): int =
s.asGroups.mapIt(it.foldl(a.intersection(b.toHashSet), toSeq('a'..'z').toHashSet).len).foldl a + b