Finally, the final day! From what I recall, the last problem is fairly easy compared to the last week or so of problems. The sun unfortunately went down just as a I finished. But I should be able to still finish with plenty of time left over today.
Oh this is annoying. I mean from a design perspective. It's just.... a really weird numbering system.
So first, parsing the numbers into decimal:
while (!input.eof())
{
uint64_t n = 0;
getline(input, line);
for (char c: line)
{
n *= 5;
switch(c)
{
case '0': break;
case '1': n += 1; break;
case '2': n += 2; break;
case '-': n -= 1; break;
case '=': n -= 2; break;
}
}
total += n;
}
Fairly simple. Now, to reverse the process...
string s;
while (total > 0)
{
switch (((total+2)%5)-2)
{
case -2: s.insert(s.begin(), '='); total += 2; break;
case -1: s.insert(s.begin(), '-'); total += 1; break;
case 0: s.insert(s.begin(), '0'); break;
case 1: s.insert(s.begin(), '1'); total -= 1; break;
case 2: s.insert(s.begin(), '2'); total -= 2; break;
}
total /= 5;
}
And that's the end! That was an enjoyable year, even if I stressed myself out by falling a week behind and wanting to cathc up. But it's done, and I feel accomplished!