8
votes
Day 15: Lens Library
Today's problem description: https://adventofcode.com/2023/day/15
Please post your solutions in your own top-level comment. Here's a template you can copy-paste into your comment to format it nicely, with the code collapsed by default inside an expandable section with syntax highlighting (you can replace python
with any of the "short names" listed in this page of supported languages):
<details>
<summary>Part 1</summary>
```python
Your code here.
```
</details>
Rank 674! Wow, that was easier than expected. I saved Python for last as I thought the problem would get progressively harder. If I know it was this easy I might have used C.
Python was my third language, after Visual Basic (that I didn't know how to use if or loops) and PHP. My code quality was getting very bad that I wrote my blog in a single PHP file, and with a lot of one line ifs. So, I thought I should learn a language that forcibly make you write readable code. The choice was either Python, or Ruby. And I picked Python as I thought Ruby's
end
make it inferior to Python. A decade and a half later, I think I made the right choice as Python is a lot more popular. Although I only see employers here asking for Ruby backend engineers and not Python where it get more used in data-related fields.And with that I've wrote & reminiscence all 15 languages I've written in all my life in AoC. Thanks for the trip down memory lane. After this, I don't know. Maybe I'll quit, maybe I'll write more Rust, C or C++ to get some practice in.
Part 1
Part 2
Noting that in your "lens add" case, you could have used the for..else Python idiom. No particular reason to, just pointing it out in case it was new to you.
not op but I had no idea about that, thanks for pointing it out! this seems super nice.
Thanks for the suggestion. I'm only familiar with for..empty in Django template so initially I thought that is what for..else is for.
Elixir
Very easy!
List.keystore/4
andList.keydelete/3
were perfect for the map-building operations.Parts 1 and 2
Squeezed down to 24 mostly-illegible lines, because I felt like it
Not my finest day. I did part 1 in 6 minutes, but part 2 took me another 30 minutes, mostly because I kept not understanding the statement of the problem. "it's just a hashmap" "yeah but uhh how does that work again...."
Part 1
Part 2
github
Surprisingly easy for day 15, though I wasn't quite as fast as I would've liked (I'm posting quite a bit later, but I finished in around 22 minutes or so). I expected the part 2 twist to be more difficult than it ended up being.
Solution
This was the first day I actually felt hampered by Haskell. I'm sure someone more comfortable with the language could accomplish this naturally, but I was just wishing for my familiar data structures.
I initially implemented everything with lists, but went back and updated the outer list to an Array as the original seemed wastefully slow. I could probably substitute the inner lists as well for something like OMap, but it's running reasonably quickly as is.
Haskell Solution
Golang solution
This seemed very (too?) straightforward. Not much more than implementing the algorithm as described. But go does have all the important primitives. I keep expecting to hit these big algorithmic scalability or complex search challenges that I remember from previous years.
Maybe I shouldn't be complaining, I remember some solutions from previous years taking me several days to crack. Maybe they are trying to make it more fun and less work.
It seemed a little weird to me as well for day 15, especially with how much they spelled out the instructions compared to past days from this year. Kind of a basic data structures problem.