Advent of Code

293 readers
1 users here now

Advent of Code is an annual Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.

https://adventofcode.com

founded 2 years ago
MODERATORS
26
 
 

As a warmup for this year's Advent of Code, I'm re-reading and posting my solutions to last year's challenges. You can read, run and edit today's solution by following the post link.

Today we had to build a set of buckets from the given spec, and observe the behaviour of sand grains as they fell into them. I found this a really satisfying challenge, and enjoyed the visualisations that many people wrote for their solutions.

27
5
AoC 2023 Goals (self.adventofcode)
submitted 1 year ago by hal9001 to c/adventofcode
 
 

Does anyone have any goals they are hoping to achieve this year?

I'm planning to try and learn Raku but probably not use it as my primary solution language. I always prefer to do a secondary implementation in the new language so I'm not stuck on syntax and how to solve the problem.

As always my goal is to finish all the stars โœจ๐ŸŒŸโœจ

28
 
 

As a warmup for this year's Advent of Code, I'm re-reading and posting my solutions to last year's challenges. You can read, run and edit today's solution by following the post link.

Today we had to build and compare tree structures. I used Petitparser to parse the input and build the tree, and some questionable logic for the comparison, but it gave the right answer and quickly enough, so ship it!

29
 
 

As a warmup for this year's Advent of Code, I'm re-reading and posting my solutions to last year's challenges. You can read, run and edit today's solution by following the post link.

Continuing the ramp up in difficulty, today's challenge asked us to do some literal (virtual) hill-climbing, but with the added constraint of not allowing too large a step. I was able to re-use an existing Graph class I had built along with an implementation of Dijkstra search.

30
0
submitted 1 year ago* (last edited 1 year ago) by mykl to c/adventofcode
 
 

As a warmup for this year's Advent of Code, I'm re-reading and posting my solutions to last year's challenges. You can read, run and edit today's solution by following the post link.

Proving that the jump in difficulty yesterday wasn't a fluke, today's challenge required careful interpretation of the instructions, as well as parsing a complicated input describing how a bunch of monkeys update and pass values between them. I had originally (ab)used the incredible Petitparser package for this, and was surprised to see this is supported in DartPad so no rewrite was needed. Part two increased the number of rounds dramatically, so using the Least Common Multiple kept numbers under control without moving to BigInts.

31
 
 

As a warmup for this year's Advent of Code, I'm re-reading and posting my solutions to last year's challenges. You can read, run and edit today's solution by following the post link.

Today's challenge felt like a massive jump in the complexity of the problem statement. Fortunately this resolved into a reasonably simple solution. The one fly in the ointment was that part 2 required you to 'read' what letters were displayed on the 'screen'. As there seems to be one puzzle each year that requires this, I had a simple OCR solution available from a previous year.

32
 
 

As a warmup for this year's Advent of Code, I'm re-reading and posting my solutions to last year's challenges. You can read, run and edit today's solution by following the post link.

Today we had to drag a segmented worm's head around a grid according to a given set of directions and count how many cells the tail visited. For part 2, the worm got longer. Solving this felt much easier than yesterday's challenge. That must mean tomorrow will be tricky...

33
 
 

As a warmup for this year's Advent of Code, I'm re-reading and posting my solutions to last year's challenges. You can read, run and edit today's solution by following the post link.

I remember really enjoying this challenge. We were asked to determine visibility across a grid of variable height trees, first looking in, then looking out. What was easy to describe turned out to be quite tricky to implement (for me at least!). As so many AOC problems involve navigating around grids, I had a handy Grid class availalble to help me. Perhaps a bit OTT for this use, but when you have a hammer...

34
 
 

As a warmup for this year's Advent of Code, I'm re-reading and posting my solutions to last year's challenges. You can read, run and edit today's solution by following the post link.

Quite a jump in difficulty today, requiring us to reconstruct and query a notional filesystem based on the results of a series of cd and ls commands. Building a simple graph revealed the required information.

35
1
submitted 1 year ago* (last edited 1 year ago) by mykl to c/adventofcode
 
 

As a warmup for this year's Advent of Code, I'm re-reading and posting my solutions to last year's challenges. You can read, run and edit today's solution by following the post link.

Another simple challenge today, requiring us to look for (and avoid) repeating characters in a given run of characters. I suspect the authors hoped we would write clever code that noted the locations of any repeated characters and then skipped forward to avoid them, but the source text and key lengths were so small that none of that was necessary. Just mashing every successive run of test candidates into a Set to test for uniqueness ran all tests and the full solution in 65ms.

36
 
 

As a warmup for this year's Advent of Code, I'm re-reading and posting my solutions to last year's challenges. You can read, run and edit today's solution by following the post link.

After a few days of gentle introductory challenges, things ramped up a little today. Not due to the difficulty of the puzzle itself, but the unhelpful way in which the input data was formatted :-). Given that increase in difficulty, I think a lot of people were expecting part 2 to be a Towers of Hanoi challenge, but no, it was just a simple change to part 1.

37
3
submitted 1 year ago* (last edited 1 year ago) by mykl to c/adventofcode
 
 

As a warmup for this year's Advent of Code, I'm re-reading and posting my solutions to last year's challenges. You can read, run and edit today's solution by following the post link.

This challenge required us to identify overlapping ranges. One of my first programming jobs many years ago involved writing a maintenance scheduling system, and I still remember the 'Aha!' moment when I realised how much simpler the checks could be than the convoluted rules that were my first attempt.

Anyway, this time round I just re-used a class from a previous year to model the ranges. Much easier :-)

38
3
submitted 1 year ago* (last edited 1 year ago) by mykl to c/adventofcode
 
 

As a warmup for this year's Advent of Code, I'm re-reading and posting my solutions to last year's challenges. You can read, run and edit today's solution by following the post link.

This challenge was about rucksack packing but, rather than the classic computer science problem, it only required finding the common character between different strings. I chose to simply drop the strings into Sets and find the intersection.

39
4
submitted 1 year ago* (last edited 1 year ago) by mykl to c/adventofcode
 
 

As a warmup for this year's Advent of Code, I'm re-reading and posting my solutions to last year's challenges. You can read or run today's solution by following the link above.

Day 2 involved playing Rock Paper Scissors following a strategy guide. I solved part one by building a simple look-up table encoding the provided score values. Solving part two just required building a second lookup table to key into that first table.

40
0
submitted 1 year ago* (last edited 1 year ago) by mykl to c/adventofcode
 
 

As 2023 Advent of Code is approaching fast, I thought I'd revisit my 2022 entries, and I realised a good focus would be to post one a day during November. No guarantees as to the quality of the algorithms used, but hopefully people will find the code readable and interesting. If anyone has questions or ideas for improvement, I'd love to hear them.

They were all written in Dart, and I will modify each one to allow it to run online in the browser. Some of the code may look a little odd as I had to inline the functionality from some libraries that I used as DartPad doesn't support them all.

Anyway, here's the core of my response to Day 1. The full code can be read and run by following the link above.

int part1(String lines) => totalCalories(lines).first;
int part2(String lines) => totalCalories(lines).take(3).sum;

Iterable totalCalories(String lines) => lines
    .split('\n\n')
    .map((e) => e.split('\n').map(int.parse).sum)
    .sorted(descending);
41
 
 

Time to start practicing and catching up on prior missed stars. โ˜ƒ๏ธ

42