π² - 2024 DAY 1 SOLUTIONS -π²
Day 1: Historian Hysteria
Megathread guidelines
- Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
- You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://blocks.programming.dev if you prefer sending it through a URL
FAQ
- What is this?: Here is a post with a large amount of details: https://programming.dev/post/22323136
- Where do I participate?: https://adventofcode.com/
- Is there a leaderboard for the community?: We have a programming.dev leaderboard with the info on how to join in this post: https://programming.dev/post/6631465
Haskell
Plenty of scope for making part 2 faster, but I think simple is best here. Forgot to sort the lists in the first part, which pushed me waaay off the leaderboard.
Uiua
For entertainment purposes only, I'll be trying a solution in Uiua each day until it all gets too much for me...
Nim
I've got my first sub-1000 rank today (998 for part 2). Yay!
Simple and straightforward challenge, very fitting for 1st day. Gonna enjoy it while it lasts.
Codeberg repo
Rust
Right IDs are directly read into a hash map counter.
Solution in C
Part 1 is a sort and a quick loop. Part 2 could be efficient with a lookup table but it was practically instant with a simple non-memoized scan so left it that way.
You are using some interesting techniques there. I never imaged you could use the result of == for adding to a counter.
But how did you handle duplicates in part 2?
Iβm not sure if I understand the question correctly but for every number in the left array I count in the right array. That means duplicate work but shrug π
Python
::: spoiler Part 1
::: ::: spoiler Part 2
:::
I am sure there were better ways to do this, this was just the first way in my head, in the order it appeared
Not going to push hard on these first days (fever being a reason), so I slept in quite a bit before looking at the problem. ::: spoiler C#
:::
Iβm quite inexperienced as a programmer, I learned most of the basic concepts from playing human resource machine and 7 billion humans. After mucking about writing some CLI utilities in Perl and python, Iβve decided to give rust a go.
Part 1
Part 2
Raku
I'm trying warm up to Raku again.
::: spoiler Solution github
:::
I'm happy to see that Lemmy no longer eats Raku code.
Kotlin
No π for Kotlin here?
I have another Kotlin (albeit similar) solution:
It's a bit more compact. (If you take out the part that actually calls the functions on the (test-)input.)
Thanks! I like the
Pairdestruction andzip().sumOf()approach. I'm relatively new to Kotlin, so this is a good learning experience. πI'm late to the party, as usual. Damned timezones. This year I'm going to tackle with a small handful of languages, but primarily Elixir and Gleam. This is my first time trying this languages in earnest, so expect some terrible, inefficient and totally unidiomatic code!
Here's day one:
Elixir
Smalltalk
python
I didn't realize it was december until this afternoon. I've generally chosen a new or spartan lang to challenge myself, but I'm going easy mode this year with python and just focusing on meeting the requirement.
::: spoiler solution
:::
Solution in ruby
This is my third program in ruby after the ruby tutorial and half of the rails tutorial, so don't expect anything too good from it.
Also i did this today since i had time, i will probably not comment every day.
fyi for lines 14-22 you an use
.absinstead of checking for negatives and.suminstead of doing it manually. Check my crystal solution to see what I meanThat is good to know, thank you.
Go
Crystal
TypeScript
This is for part #2 only.
Is it possible to get this more efficient? I would love a way that only required iterating over the list once, but I don't really have the focus to puzzle it out any less than
O(2n)(probably more than that, even, if you count reading in the data...).Haskell
JavaScript
After writing a procedural to-the-point version in C, tried a JavaScript solution too because it's just perfect for list comprehension. The part 2 search is inefficient but the data size is small.
::: spoiler Code
:::
https://github.com/sjmulder/aoc/blob/master/2024/js/day01.js
C#
Lua
Combined Solution
Rust
I'm doing it in Rust again this year. I stopped keeping up with it after day 3 last year, so let's hope I last longer this time around.
::: spoiler Solution Spoiler Alert
:::
I'm keeping my solutions up on GitHub.
Elixir
I've honestly forgotten how fucking cool the pipe operator is
Viml
I think viml is a very fun language, i like weird languages lol, so this year im doing it in viml while trying to use as many of the original ed/ex commands as i can (:d, :p, :a, :g, ...)
::: spoiler Part 1
:::
::: spoiler Part 2
:::
Uiua
Decided to try and use Uiua for each day this year. At least I'm not the only one to get this idea ^^
Run with example input here
Python
Lost a minute because I forgot about
abs.-.Factor
https://github.com/AndydeCleyre/aoc-2024
Elixir
Total noob, but it's fun to learn.
Zig