MarkoK.dev

Advent of Code is fun

Sunday Dec 4th 2022
Marko
4 min read

This advent time the fun is provided from Advent of Code. I can't believe that I have not been participating previous years.

First, what is Advent of Code, direct quote from the Advent of Code site:

Advent of Code is an 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. People use them as interview prep, company training, university coursework, practice problems, a speed contest, or to challenge each other.

So basically you get a new puzzle each day and have to solve it by coding. Puzzle contains input and then you have to solve part 1 and part 2. Part 1 is the basic solution of the puzzle and then comes part 2 and hits with the curveball.

Advent of Code is fun exercise for everyone. Some people solves these with Excel and Google Sheets, others with calculators and old computers. Wizards with couple of minutes from the time that puzzle is published and some use even AI for solving the puzzle. It is good time to even watch others solutions. And visualizations of the puzzles. If you have not I suggest that you check out the Reddit community: r/adventofcode

But before checking out solutions I suggest you try to solve it by yourself first!

How I adventure in Advent of Code

I swear that 50 percentage of time I read advent as adventure. It can be an adventure. Try a new language or use the language you want. I chose PHP since I'm most familiar with it and I decided to use Laravel with it. Laravel has some cool things like collections built-in so it is quite nice starting point. I know PHP is not so popular among other Advent of Code participants but I use it daily. There seems to be a lot of Python and Rust users. This is my observation at least from Reddit.

Advent of Code Laravel project

As seen from the picture above I did a small site for me. I have also published my code on GitHub - you are welcome to come and laugh at my solutions or give some tips or just talke me about them. Some solutions are fast and some over engineered and most of the ugly as...

So how I solve dem puzzles

Over these four days I have made some tweaks to my project. Mostly to simplify some things.

First I run my php artisan make:day X command that makes DayX.php class, DayXTest.php Pest test file and dayX.txt file for input. Now I have some scaffolding for the day and I start reading the first puzzle. I have no rush since I'm not interested of speed running these. I just like to solve the puzzle.

What I have noticed that the puzzles have example input and then example result. I use that input and result for the tests. After I have entered input and example result to the test file I start coding the solution. When I have the solution and test passes for part 1 then I go to my aoc.test/day/X url to see what the answer is. I submit it and then if it is correct I move to solving part 2 and if not it is time to debug. Part 2 works just as part 1 - first test and then solution.

Random ramblings

At least four first puzzles have been quite easy but when I checked out older puzzles they were, well quite interesting. So more harder puzzles are coming and those might take more time to solve.

Depending of the day I do puzzles in the morning or after work. Puzzles are published at 7 am on my timezone (UTC+2) so it is not so bad but I have to be at work at 8 am. So sometimes I do them first thing on workday if I have suitable time but if not then after work.

Are you adventuring with Advent of Code? If yes, then have fun and maybe leave a comment in which language are you using?

Maybe I should do previous puzzles too...

Conversation

We use Mastodon to show our comments. You only need to post a reply for the corresponding toot. We cache our comments here so it may take a couple of minutes to show up here.
Join the conversation