Summary for those just joining us:
Advent of Code is an annual Christmas themed coding challenge that runs from December 1st until christmas. Each day the coding problems get progressively harder. We have a leaderboard and pretty good turnout, so feel free to hop in at any time and show your stuff!
Whether you have a single line monstrosity or a beautiful phone book sized stack of OOP code, you can export it in a nice little image for sharing at https://carbon.vercel.app
What did you think about today's problem?
Our Code is 2416137-393b284c (No need to share your profile, you have the option to join anonymously if you don't want us to see your github)
Jump in the discussion.
No email address required.
One thing I learned (from comparing my code to Snakes'), it's actually good to not abstract away directions to an enum or something, but to decide that they are integers that go around like so, so that you can turn them 90 degrees etc with simple math.
Jump in the discussion.
No email address required.
Jump in the discussion.
No email address required.
Also visited should be global for all beams. You should be able to type
in your sleep.
Jump in the discussion.
No email address required.
No, visited checks that beams haven't entered a loop, I have an energized variable for the tiles.
I can type that in my sleep, that's why I'm doing it in Nim.
Jump in the discussion.
No email address required.
The trick is to have
(x, y, dir)
as a key for your visited set, then compress it to an(x, y)
-set for the answer. Also it looks like you didn't do the former for your beams and got lucky that it didn't blow up in your face.Jump in the discussion.
No email address required.
Why would I be lucky? It's functionally equivalent.
Jump in the discussion.
No email address required.
I can't see the rest of your code, but from your data structure it seems that a beam that goes like this
will stop instead of continuing upwards.
Jump in the discussion.
No email address required.
lmao you're right! I didn't run this code, it's my post-star refactoring. In the initial one I had a table of beams and directions rather than a per beam sequence.
Jump in the discussion.
No email address required.
dis is da way.
Also btw, I had a useful runner for my code that downloads the input but also, importantly, maintains an answer database (a dict dumped into a json file). I did that specifically so that I can rewrite the code, especially after getting the first star and realizing that it's too slow for the second star, and still know that it gives the correct answer for part 1. Also when for when I change some utility function, then rerun all problems to see that they all still work. Highly recommend.
Jump in the discussion.
No email address required.
More options
Context
More options
Context
More options
Context
More options
Context
More options
Context
More options
Context
More options
Context
That's what I'm talking about, yeah. Bite the bullet and the code is way shorter and more understandable and debuggable. Like, look at your
-, |
nonsense, it's asymmetrical! Also memorizing what your 4 directions mean builds character.Jump in the discussion.
No email address required.
Agree to disagree, it's not intuitive to represent the direction as anything other than an Enum or a tuple of deltas. The -, | nonsense is easy, you just start the second beam with the opposite direction as the incident one.
Jump in the discussion.
No email address required.
0 points right, then you go clockwise (or counterclockwise is more traditional actually). Then you can do math modulo 4, +/- 1 turns it ninety degrees, +2 does a 180.
There is some time required to familiarize yourself with the encoding until you intuitively understand that 2 points left etc, I agree, but the ability to do the math above is well worth unabstracting it like that.
Jump in the discussion.
No email address required.
More options
Context
More options
Context
More options
Context
More options
Context
More options
Context
For part2 is just part 1, but for every possible starting value. It runs in ~600ms. I then tried to add some logic that says if I already passed through a starting point with the same movement vector, I can just skip checking that starting point. That increased my time needed by 50% to 900ms.
using boost::unordered_flat_set instead of std::set to prevent looping, improves this to 160ms.
So anyone has a non brute force solution?
Jump in the discussion.
No email address required.
A recursive/DP solution where you cache the set of cells which get energized when you hit a deflector with certain direction should be fast. If you use 1 bit per cell there might be a clever way to bitwise OR the 2 sets of energized cells together.
Jump in the discussion.
No email address required.
I'm surprised he didn't force people to do that given it's day 16.
Jump in the discussion.
No email address required.
More options
Context
More options
Context
More options
Context
yall on some other shit i can't keep up
to learn list:
enums ?wtf are thos?
hash .. map???
memoization
u guys are frickin nerds
I got the light beam going around but because of how I worded it it's now tricky figuring out how to handle closed loops
Jump in the discussion.
No email address required.
More options
Context
Another quality-of-life feature of Nim: arrays can be indexed by enum values. This is because arrays can be indexed by any ordinal type, and enums are one of them.
@SleighOut
Jump in the discussion.
No email address required.
That's wild I've never seen that syntax before. Doesn't seem to be in the docs and I'm getting
Error: invalid order in array constructor
when I try to mess with it. Where did you read about it?Jump in the discussion.
No email address required.
I found it through a quick search, but it's also in the Nim manual. You're getting that error because the indices have to be in the same order as the enum.
Also, apparently the syntax gets even better:
[Up: Down, Up, Right, Left][dir]
will also work. "If an index is left out,succ(lastIndex)
is used as the index value."Jump in the discussion.
No email address required.
More options
Context
More options
Context
More options
Context
This felt straight-forward but I did manage to anticipate and work around a few issues that would have bogged me down 2 weeks ago. So I guess I am learning a bit from this. If I ever need to implement complicated algorithms in my next React CRUD I should handle it no problem
Jump in the discussion.
No email address required.
More options
Context
ngl bros today was hacky as shit
Jump in the discussion.
No email address required.
More options
Context
This is really gross but it works
Copied the advice to not use an enum and got a much simpler result. Confused why everyone is using a deque
Jump in the discussion.
No email address required.
More options
Context
I couldn't be assed checking all four sides, so I just did the top row (25% chance) and got lucky first time lmao
Jump in the discussion.
No email address required.
More options
Context
many such cases
Jump in the discussion.
No email address required.
More options
Context
I thought it would give me that option when I joined the leaderboard but nope it slapped me into the rdrama leaderboard with my real name. I can't be bothered to make a second AoC login and submit all the answers twice so I guess I'm staying anonymous.
I thought today's problem was pretty bad. Eric's been talking about reflections and mirrors and pipes and lenses a lot but they're not tying together. Really lazy pt 2. This felt like a day 6 problem.
Jump in the discussion.
No email address required.
I also handled this one without much difficulty, but I can see how it'd be a nightmare for someone not comfortable with arrays and vectors. Difficulty is subjective depending on a codecel's skillset.
Jump in the discussion.
No email address required.
Sure but it's day 16. Anyone who got this far can already do arrays. The only difficulty here is that you need to account for direction as well as coordinate, but that's been done 100x before in past years. I'm not particularly good at DFS/BFS because I only do them once a year for AoC but this was as vanilla as it gets.
Jump in the discussion.
No email address required.
I'd say there was a fair bit more complexity in figuring out how to represent the state due to the forking feature. Add the possibility of loops and there's some extra handling to do.
I think the bottom line is that people have got good at solving these kinds of tasks precisely due to AoC. It gets easier each year as people get better.
Jump in the discussion.
No email address required.
More options
Context
More options
Context
More options
Context
More options
Context
Snapshots:
https://carbon.vercel.app:
ghostarchive.org
archive.org
archive.ph (click to archive)
https://adventofcode.com/2023:
ghostarchive.org
archive.org
archive.ph (click to archive)
Jump in the discussion.
No email address required.
More options
Context