Blog

Advent of Code, day 12: Shooting for the moon

12 Dec, 2019
Xebia Background Header Wave

I won’t lie. I’m usually not the most competitive person out there. But when December nears, I’m getting a bit restless. And when I run into fellow players from previous year, the conversation quickly turns to the coming season of Advent of Code. "Will you be joining again this year?", "Have you started preparing yet?", "Which language will you use?" or "Going for the top position again this year?" are just some of the questions asked.

Friendly competition

Yes, that says 5:55 in the morning…

2016 was the first year I participated real-time. Even though I only started on day 6, I made it to a respectable 2nd place on our private leaderboard. I have to admit, the competition wasn’t as fierce back then. So just by completing all challenges, you would already end up near the top.

Then came the 2017 edition. There was some more buzz around it in the office. More players signed up for the private leaderboard, and I even set an alarm clock for 5:55 to make sure I got maximum chances for a good score (and I’m not the only one). And it worked! I got first place! True, it might have helped I was on parental leave, and probably had a bit more time to spare than my competitors. But a win is a win, and I even managed to score points for the global leaderboard. That felt good! Maybe there is a competitive side of me.

In 2018, the competition was even more fierce. More people were getting up before 6:00, and the internal Slack channel was more active than ever. People were comparing solutions and execution times, and overall having lots of fun. After day 24, there was a three-way tie for the top position. Bulat, Marcus and myself all had 1852 points. So it came down to the final day. Bulat ended up being the fastest to solve day 25, and although I ended on second place, we had a blast!

So close

Ranking the stars

But being competitive, also means you’re curious to see how you are doing compared to your peers. The leaderboard however, only gives you the ranking based on the total score on the private leaderboard, global leaderboard or total number of stars acquired. That doesn’t really give you an insight into how you are doing over time…

Luckily there is also an API. That gives you the times of every star acquired of every member on a private leaderboard. There must be something we can do with that, right? So in 2017, inspired by a post on creating F1 lap charts using d3.js, I started hacking together some python and javascript to parse the leaderboard json, and create a "lap chart" for Advent of Code. Which resulted in the chart below.

ranking

Updating the chart was manual work though, so I converted the python scripts to javascript, and made a browser extension out of it. I’ve added a couple of small features this year as well, like adding a sort by score per day. The extension is available for Chrome and Firefox, or on Github. And if you want to see our 2018 leaderboard, I use it as an interactive example. Yes, I’m User #35801.

To the moon and back

Today’s challenge was about tracking the moons of Jupiter. The first part was pretty straightforward, just tracking 4 objects over a limited amount of iterations. Earlier this week I said to a colleague, "Just wait until he [Eric Wastl] makes you do a trillion iterations". Boy was I wrong. And not by an off-by-one, but almost by a factor 400!

$ time pypy3 part2.py
Steps: 3.9E+14
pypy3 part2.py  0.28s user 0.03s system 94% cpu 0.323 total

Luckily python isn’t as slow as some would lead you to believe. 390 trillion steps in just 0.323s seconds. It got me first place today 🙂

Questions?

Get in touch with us to learn more about the subject and related solutions

Explore related posts