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 (28)
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)
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!
I am also gonna be doing aoc this year. Here is my Python solution:
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)
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.
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
Python, why make it complicate if it is so siple?
My solution is the same but yours is also more slim!
Good job!
COBOL:
This is awesome! I'm so happy I get to add COBOL to the list 😁
Hey Y'all!!! I thought I'd actually try making this happen this year and I completed the first challenges today!! I think in later challenges I'll actually try importing the text file as it is, but I wanted to make it fun for myself. I did the solution this time in ruby, and its a program you'd run on irb, that asks for the expenses and the factor you need to group to find the magic number (2 or 3) and it prints out the number to enter at the end.
Here's the way I solved it:
Ooh filtering out numbers > 2020 is a really nice touch. I hadn’t thought of that 😁
Only just heard of this, have some catching up to do! Here's my day 1 - similar to a couple of others already posted. Weirdly the part 1 problem came up in an interview just a couple of weeks ago!
I wasn't even going to do AoC this year after a bit of burnout last year. But I have no self-control. I have done day 1 in Haskell, Rust and C to compare performance. Rust wins by a hair.
github.com/neilgall/advent-of-code...
Hi! A little bit late, I've start with AOC this year and waiting for tomorrow I've try the past event this is my solution in python for 2020 - DAY 1:
Very good content here Ryan!
Bit late to the party, here is my iterator focused solution in rust. input is a Vec, aka the parsed input data
Edit: solution 2, same concept, but more concise