--- Day 6: Custom Customs ---
Needed some debugging to clear part2. I like the fact that I am doing it with standard bitsets and not HashSet. I did run into issues with carriage return (did not have it in example, have it in input)
type
Answer = char
AnsSet = set[char]
proc solve(text: string): (int, int) =
var text = text & "\n\n"
var
groupAny: AnsSet
groupEvery: AnsSet
groupNew = true
answers: AnsSet
answer: Answer
b: char
for c in text:
if c.isLowerAscii:
answer = c.Answer
answers.incl(answer)
elif b == '\n':
result[0] += groupAny.len
result[1] += groupEvery.len
groupAny = {}.AnsSet
groupEvery = {}.AnsSet
groupNew = true
elif c == '\n':
groupAny.incl(answers)
if groupNew:
groupEvery = answers
groupNew = false
else:
groupEvery = groupEvery * answers
answers = {}.AnsSet
else:
echo "ERROR parsing " & c.repr
b = c
echo solve(example)
echo solve(input)
(11, 6) (6437, 3229)
That's the right answer! You are one gold star closer to saving your vacation.
That's the right answer! You are one gold star closer to saving your vacation.