Day Two is done! Finished code here.

Part One

This time around, we just had to do some simple plug and chug of numbers. I took advantage of character arithmetic and lookup tables to get part one sorted out. In .NET, performing arithmetic operations on characters gives you an integer, because of reasons. It was simply a matter of checking if the round was a win or a loss with a lookup table (A Dictionary<char, char>), and then adding together some numbers.

Part Two

Part two was a little more interesting. I created an enum for the different types of game results (Win, Lose, Draw) and then made another lookup table for the types of results. I also realized I’d be better served with a “reverse” lookup table for the correct “losing” option, which was simply a matter of reversing the existing dictionary. All we had to do was check if we won, lost or drew, used the appropriate lookup table to get the right move for us, and then did more or less the same math from the previous part.

Conclusion

Wow, this ended up being a short post, despite the actual process of solving the problem taking longer! This problem was easy to solve for simply because there were so few outcomes; the modeling of the problem was complete with just a few lookup tables. In this case, there wasn’t much of a downside of pre-modeling the entire problem space, since it was so small. Then, I just let the computer do what it’s good at: Chewing through a bunch of memory locations and doing some integer math.

I’m kind of annoyed with myself that I didn’t take the time and only loop through the problem once, but it was quicker for me to solve it this way and let the computer take twice as long to compute things than it would have been to figure out how to do it in one loop.