advent-of-code/2020/src/day6.nim

10 lines
390 B
Nim
Raw Normal View History

2020-12-05 23:10:59 -06:00
import streams, sets, strutils, sequtils
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)
proc part2*(s: Stream): int =
2020-12-05 23:20:53 -06:00
s.readAll().split("\n\n").mapIt(
it.split("\n").filterIt(it != "").foldl(a.intersection(b.toHashSet), "abcdefghijklmnopqrstuvwxyz".toHashSet()).len
).foldl(a + b)