Fun challenges (AdventOfCode)

See Advent of Code 2021

Every day you get to solve two puzzle, ideally by writing code. They always result in a simple answer that you’ll enter to advance to the next level.

It started Dec 1 and ends Dec 25.

Also, if you need a starter project, try this:

It lets you simply write one puzzle solving function after the other, and the rest of the code will automatically find and run them all, using Introspection. So, all you need to do is to add functions that take no argument and return the result as a String, name them “SolveXXY”, where XX is the day and Y either “a” or “b” for the first and second puzzle of that day.
The program will then list all results in a Listbox.

So, has anyone else picked up the challenges?

If so, are you interested in sharing solutions?

By Day 6 they’ve actually gotten a bit more tricky. Before that, they were all rather straight-forward to solve.

What do you need to run the starter project? Crashed on the latest Xojo

Admittedly I’m a social media Luddite, so a major stumbling block for me is:

To play, please identify yourself via one of these services:
[GitHub] [Google] [Twitter] [Reddit]

That rules me out.


No, there there are OutOfBoundsExceptions. 2 puzzles are lines of 0s and 1s but the handling of EndOfLine is missing.

if bit = "1" then
  countPerBit(pos-1) = countPerBit(pos-1) + 1
elseif bit.Trim = "" then '<-- line missing
  continue '<-- line missing
elseif bit <> "0" then
  raise new OutOfBoundsException // that's an input error
end if

What you see is the OutOfBoundException for the EndOfLine because the character is neither a 0 or a 1.

But the last line

return Val("&b"+oxygen(0)) * Val("&b"+scrubber(0))

also does an OutOfBoundsException because scrubber doesn’t have any values.

Oops, that’s a regression bug in Xojo, because when I run the project in RealStudio 2012, then it runs fine.

The issue is that the DataXX constants contain CRs as line delimiters but the Split(EndOfLine) function uses LF as line delimiter.

The fix is to add a ReplaceLineEndings call around the Split call, like this:


dim lines() as String = Data03.Split(EndOfLine)


dim lines() as String = ReplaceLineEndings(Data03,EndOfLine).Split(EndOfLine)

I’ve updated the starter project accordingly.

Of course, you’re not supposed to use my solutions but write your own :smiley:

Only my solutions crash (see my other post). The starter still works, if you write your own Solve functions starting with day 1 :slight_smile:

I’m a firm believer in solving problems only once. :sunglasses:


I’ve just updated the project again with all solutions up to day 14


I was today years old when I finished the December 2021 Advent of Code challenge!



I got stuck at Day 16. Anything 3-D transformations related always confused the hell out of me.

Care to share your code?

I think you mean day 19. I did that one last, and it was a bear.

I’ll put my project on github at some point.

I’m deeply disappointed in you. :sunglasses: :sunglasses:

Ah yes, Day 19 it was what kept me feeling clueless for days.

Glad to see you weren’t thinking it was easy, either :slight_smile:

I found the whole exercise… humbling. While I solved most of them myself, I needed outside help in the form of the Subreddit hints or discussion with another developer (@Jeremy_Cowgar ) to get past. (Day 24 stands out here.) And I wouldn’t call some of my solutions a model of coding or efficiency either.

So now I’m starting 2020. :slight_smile:

1 Like

Before Day 19, I only needed some help figuring out why my backtracking (dijkstray algo) didn’t work with the final data while it worked with the test data. All others I was able to figure out myself. Some of my solutions I actually find elegant, others are as quick-n-dirty as they can get to finish them quickly :slight_smile:

Still, I wonder if anyone else looking at my posted examples can figure out how they work.


1 Like

Looking at your Day19 code.

My difficulty is that, once I’ve found the 12 matches, I fail to re-orient them into the root’s coordinate if the scanner is not a direct peer of the root’s. Meaning I don’t get the “unwinding” right. I suspect I have to maintain a stack re-orientations for this step, but currently only have one. Getting this right in my head is what I’m failing to accomplish.

Using each beacon in turn as a starting point, I reoriented first, updated the absolute X, Y, and Z of the scanner and all beacons, then checked. If I could not find a match, I ran through each of the orientations, then moved onto the next beacon. If I could find the requisite matches, I left those settings in place since they’d be overwritten on the next check anyway.

Each scanner also maintains an array of the complete set of reoriented beacons so I only had to do it once per orientation. Even so, my code takes 10-15 minutes to complete.

No, this was not easy to visualize. I had to keep using my phone as a visual aid to get the 24 different orientations right.

1 Like

What keeps confusing me is that I never see the 24 in my code. I see 6 (for the various order of x,y,z) and each of them in positive or negative direction. No math I can think of comes to 24 from that. Possibly I consider orientations that can’t happen in 3D space, not sure.
So, basically, I’m trying to brute-force a 3D problem without understanding 3D operations.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.