It's back! It's finally back! One of my favorite things on the internet is the yearly Advent of Code challenge. It's a programming challenge that runs from December 1st to December 25th. Each day, a new two-part puzzle is released. There is usually a plain text file input provided, and you have to write some code in any language you want to process it in some way. If you submit the correct answer to their question, you get a star. If you solve both parts correctly, you get two stars! The goal is to get 50 stars by Christmas day.
There are a bunch of people who get super-competitive and try to finish it as soon after midnight (when the puzzles are released) as possible. Personally, I just try to keep up and not get overwhelmed, since the second parts are usually pretty hard and require some algorithmic cleverness. (Or... and hear me out... some GPU compute. Just throw 1000 computers at the problem! 🙃)
In any case, what we usually do here on DEV is have a post here every day where members of the community can post their solutions so you can see how a bunch of different people approached it in a bunch of different languages. So, when you've solved that day's puzzle, please join in and comment with your solution. And, if you're not ready for spoilers yet, stay away from the comments section!
Every year there is a theme, and this year, you're going on vacation! The stars are currency that you need to pay for your room at the end of your stay. I'm sure nothing bad will happen. It rarely does on these Advent of Code adventures.
The Puzzle
Here's today's puzzle: apparently your trip expense report isn't adding up! You are tasked with hunting through your expense entries to find the two that add up to 2020 exactly. The answer is the result of multiplying those two values together. A nice warm-up puzzle to get us back into the groove this year.
The Leaderboard
If anyone is interested, I've generated a leaderboard code for a little less globally competitive DEV leaderboard.
It's not an officially sponsored DEV thing, just a leaderboard that some DEV peeps have used over the last couple of years. There's still quite a bit of room, so feel free to jump in if you'd like using this code:
Ryan's Leaderboard: 224198-25048a19
If you want to generate your own leaderboard and signal boost it a little bit, send it to me either in a DEV message or in a comment on one of these posts and I'll add it to the list above.
Previous Day's Languages
Last year, they made an effort to keep track of how many people used each language for their solutions for the previous day. I'll try to do that as time allows. I could imagine a bot that could poll each thread daily and update the following day's count. But that may be outside of what I have time for as well. If anybody wants to come up with something like that, I'm all for integrating it into the process. Otherwise, I'll do my best.
Merry Coding!
Top comments (27)
Hey!! So excited that it's this time again here is my code. I would have just done loops without sets but the servers were down when I was trying to get my full input so I just went ahead and did a tiny optimization :).
Oooh! That's a really slick way to drop out a level of nesting. I like it!
Hi! It was also my first time in Advent of Code.
There is my solution for the first day in Elixir: click, GitHub
Except input setup the code looks like:
SQL works for me. Easy and fast ;)
Get this table naming 'day1':
1.2. Solution
Here is my solution in rust (minus all the code required to grab the input and parse it)
Hey - I'm working on the problems in Rust this year, too! I'm putting all mine in Github, but will share here, too.
(I found a cool cargo plugin that provides helpful macros and makes doing AoC stuff easier - cargo-aoc)
I am also gonna be doing aoc this year. Here is my Python solution:
Yep, this'll be another year fighting the urge to pre-optimise xmas code 🤦
Anyway, here's a nice efficient implementation in JS... (linear for part one, which is nice. Square for part two which could be improved but, like, why?)
I'm liking Ryan's idea of using this to practice new languages and get out of the comfort zone (though JS is just so comfy now 😌 )
Plan is to make myself a twister-style spinner with 5 or so languages, and force myself to use whichever one the arrow lands on on the day.
I'm going to try to do my solutions in C. C is something I'm learning, so if anybody has any pointers (LOL), please don't hesitate to critique my code.
I didn't do anything crazy today. I just threw loops at it to see if it was fast enough. It solved before I could blink, so I'm not going to work any harder at improving speed.
I'm also doing it in C this year! I'm also fairly new to the language and pretty much the only thing I've done differently is use
fscanf
instead offgets
in conjunction withatoi
(+ I've optimised a little bit to do both parts in the same loop)
Python, why make it complicate if it is so siple?
My solution is the same but yours is also more slim!
Good job!
Hi !
Here is my solution in PHP.
I try to make a generic function that can handle 2, 3 or more number in the expense report.
Full size here : Advent of Code - Day 1
COBOL:
This is awesome! I'm so happy I get to add COBOL to the list 😁