Advent of Code 2022 Day 2

By | 29 November 2023

Continuing my prep for AoC 2023, I have completed Day 2 from last year.

Again, a spoiler warning, if you want to try the challenge first go here – the answer will be given below.

I really like these challenges – they seem really simple at first but always contain little gotchas. The main thing I have learned is to read everything thoroughly!

So, in this one we have to play Rock, Paper, Scissors with the elves. We’re given a secret guide with what each elf will play, either A(Rock), B(Paper) or C (Scissors) and the corresponding move we should play, X, Y or Z respectively. The task is to work out the total score at the end based on which of the three choices you have played, and if you have won, lost or drawn the round.

Fairly straight forward – and again I just pasted the data into Visual Studio Code and ended up with a horrible looking 2500 lines of separate DATA statements. But hey – it works and it was the easiest way to do it.

You will see if you do follow these little XC=BASIC run throughs that ‘Hey, it works’ is very much my coding approach. I’m doing it for fun and I absolutely know there will be better ways to achieve the same end result. This approach did, after all, get me through many a computer science degree module!

OK so data ingestion method done, the logic for part 1 is relatively straight forward. Using standard XCB string functions I read in the left and right characters into the elf’s and my own ‘hand’

The ‘Locate’ statement returns the cursor to just after the “Now playing game number :” printed line so it counts up the number of games being played. You can see that in action further below.

So now we can compare the two values and work the score out easily enough.

Part 2 was a little trickier as the strategy guide the elf gave us was explained in more detail.

The Elf finishes helping with the tent and sneaks back over to you. “Anyway, the second column says how the round needs to end: X means you need to lose, Y means you need to end the round in a draw, and Z means you need to win. Good luck!”

The total score is still calculated in the same way, but now you need to figure out what shape to choose so the round ends as indicated.

advent of code, day 2 part 2

It just made it all a little more complicated, but actually all I needed to do was add an additional bit of code before the score comparisons, and jump out to a GOTO label when it works out what we are supposed to play.

I only needed to cater for 2 scenarios, the other one being a victory or defeat in both categories, and the draw was then easy to code. I did make the mistake of not jumping out to the results section on my first few tries for part 2 which gave me incorrect results – just forgot the GOTOs which was so obvious when you look back it it. And that was pretty much it.

That will probably do now until the 1st day of the 2023 AoC which, people, is in just 2 days time!!

Performance was ok – play the video to see it cycle through the 2500 games of Rock, Paper, Scissors.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.