This year will be my second year doing Advent of Code in Gleam. Last year I was still learning the language, and in the past year I have used it much more and even made some small contributions to the compiler, the gleam_time package, and maintain a timezone database and utility package called tzif. Gleam is a simple language with a wonderful community. I encourage anyone interested in Gleam to take the language tour and use the playground.
To start a new day's problem use the command
gleam run new --day=1where 1 is the day number of the problem. This will create some starting
code in the src/day01 directory as well as a test in the test directory.
To run a day's problems use the command
gleam run -m day01/solutionTo run the unit tests for all the days run
gleam testFor some problems, setting the AOC_DEBUG environment variable outputs additional information.
-
This was an interesting problem, and I ended up learning a few new things. If you define a circuit as the set of all connected junctions, then you can find the union of the sets to which the two junction boxes you are connecting belong in order to find the new connected circuit. The difficulty is finding an efficient way to look up a set given one element from the set. In my initial solution I created a dict which had junction boxes as the key and sets of junction boxes as the values. This meant changing the values of all the elements in the dictionary that belonged to a set when a new union was made. In the Gleam Discord the disjoint-set data structure came up as a way to do this more efficiently, so I decided to try it and created a simple disjoint-set library. Using the new structure, and making a few other changes, the second part of my solution is roughly 3 times faster.
-
I ran into an issue doing part 2. I think it is that I am only checking if the corners are inside the figure. It may be that the corners are inside, but there is a line going through one of the walls. I ran out of time this morning to work on this and will pick it up later.
-
I tried doing part 2 a naive way with some memoization, but it seems like I still need to work on it. Code was getting very convoluted anyway, not pretty like the first several days.