I like some direction and order in my life, or maybe I need it rather than like it, but either way Advent of Code is something that very much appeals to me as it gives us daily problems to solve and actually gets me coding and thinking.
This year, actually my first year, I will be attempting to solve each problem in XC=BASIC. The main advantage of using XC=BASIC is, of course, the modern IDE and the slightly more flexible way I can get data in. The way AoC works is they give you data inputs for the problems, and sometimes these are quite large amounts of data. XC=BASIC helps overcome some of the limitations of CBM Basic while still allowing it to compile down and be run on the Commodore 64.
So, to get me started and by way of a bit of a ‘toe dipping’ exercise, I am going back to AOC 2022 and completing the first few days. I’m not interested in leader boards or competing online. I will be taking my time with each problem and solving them in my own, no doubt incorrect and inefficient way.
This is day 1.
You can find the full text of the problem here and, obviously, if you want to try this out for yourself, stop reading now as the answer is given below!
The first part was relatively simple, define an array, add the data, then cycle through the values adding them up and comparing them to the last highest value, which gives us the elf carrying the most calories compared to its pals.
I replaced all the blank lines in the large dataset with a zero to indicate the end of one elf’s total calories and the start of the next.
So you can see each time a zero is encountered we can total up the calories and compare to the last elf.
You’ll see there I also set a LOW counter which is needed for part 2 of this challenge. It basically sets the first load of calories, in this case 53308, to LOW and uses that to compare against later, along with the HIGH value.
So, a relatively gentle one to start with but very glad I did it as I now have my XC=BASIC development flow set up again properly and I have reminded myself of the little foibles that the language has – I’m looking forward to starting 2023’s calendar!
Oh, and for what it’s worth, I got 2 gold stars for this problem 🙂
This is probably going to keep me busy until well into the new year, after which time I will be returning to adventuring! I’ll try and squeeze another 2022 problem in before the 1st….but no guarantees!
Thanks for reading.