From e43a0367881740a48ba67e42e1a6699f28619bd8 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Sat, 5 Dec 2020 23:10:59 -0600 Subject: [PATCH] Day 6 part 1 --- 2020/src/aoc2020.nim | 2 +- 2020/src/day6.nim | 8 ++++++++ 2020/src/day_loader.nim | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 2020/src/day6.nim diff --git a/2020/src/aoc2020.nim b/2020/src/aoc2020.nim index 4d5052a..282435e 100644 --- a/2020/src/aoc2020.nim +++ b/2020/src/aoc2020.nim @@ -9,4 +9,4 @@ proc solve_for_day(n: int) {.used.} = when isMainModule: # solve_all() - solve_for_day(5) + solve_for_day(6) diff --git a/2020/src/day6.nim b/2020/src/day6.nim new file mode 100644 index 0000000..2b903c8 --- /dev/null +++ b/2020/src/day6.nim @@ -0,0 +1,8 @@ +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)).len + 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 = + 9 diff --git a/2020/src/day_loader.nim b/2020/src/day_loader.nim index e6fc2b4..12cf9de 100644 --- a/2020/src/day_loader.nim +++ b/2020/src/day_loader.nim @@ -3,7 +3,7 @@ import input_requestor, os, macros, strformat, tables macro loadDays(): untyped = var solver_str = "var solvers = {\n" result = newStmtList() - for day in 1..5: + for day in 1..6: let module = fmt"day{day}" if fileExists joinPath("src/", &"{module}.nim"): result.add parseStmt fmt"from {module} import nil"