This commit is contained in:
Daniel Flanagan 2021-12-09 23:25:33 -06:00
parent a5620c8197
commit 54d110bddb
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4

View file

@ -9,7 +9,6 @@ proc p1(s: seq[string]): int =
if p.hasKey(c): stack.add(p[c]) if p.hasKey(c): stack.add(p[c])
else: else:
if stack.pop() != c: result += t[c] if stack.pop() != c: result += t[c]
echo result
const v = {')': 1, ']': 2, '}': 3, '>': 4}.toTable() const v = {')': 1, ']': 2, '}': 3, '>': 4}.toTable()
proc p2(s: seq[string]): int = proc p2(s: seq[string]): int =
@ -24,16 +23,12 @@ proc p2(s: seq[string]): int =
score = -1 score = -1
break break
if score == -1: continue if score == -1: continue
echo stack
for l in stack.reversed(): for l in stack.reversed():
score *= 5 score *= 5
score += v[l] score += v[l]
echo score
scores.add(score) scores.add(score)
scores.sort() scores.sort()
echo scores
result = scores[(scores.len() div 2)] result = scores[(scores.len() div 2)]
echo result
doDay(10, (n) => n.loadInput(), doDay(10, (n) => n.loadInput(),
p1, p1,