1
0

Added AOC 2022 day 03

This commit is contained in:
2022-12-03 13:43:46 +01:00
parent 8fa2813711
commit 6139677289
5 changed files with 425 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
import std/strutils
import std/sequtils
proc run03_2(): string =
const input = staticRead"../input/day03.txt"
var res = 0
let lines = splitLines(input).filter(proc(p: string): bool = p != "")
for lineSet in lines.distribute(int(lines.len/3)):
let line1 = lineSet[0]
let line2 = lineSet[1]
let line3 = lineSet[2]
let badge = line1.toSeq().filter(proc(p: char): bool = line2.contains(p) and line3.contains(p))[0]
let prio = if int(badge) >= int('a'): int(badge) - int('a') + 1 else: int(badge) - int('A') + 27
# echo badge, " : ", prio
res += prio
return intToStr(res)
when not defined(js):
echo run03_2()
else:
proc js_run03_2(): cstring {.exportc.} =
return cstring(run03_2())