Ask HN: Is it OK to look at AoC solutions?

6 points - yesterday at 12:59 PM


I'm yet again attempting AoC. I've never completed one yet. Mostly I get too busy on the run up to Christmas but sometimes I just get stuck.

This brings me to my question. If you are stuck is it OK to just look at a solution?

For me, I got stuck on Day 1 Part 2. No amount of hints worked, so I just found a solution. I managed to get the code to produce the correct answer. I still don't understand why, I'm not good at maths. AI can't ELI5 either.

So is it good to see how others solved the problem? Or just remain stuck, and not understanding why?

Personally I feel better about knowing a solution to the problem even if I didn't solve it myself, mostly because not knowing is worse.

Comments

Jtsummers yesterday at 6:38 PM
Yes, it's ok to look. I generally don't until I've solved it, and then mostly to find hints on faster ways to solve it.

Instead of hints, try asking for, or finding, test cases. Several of us posted additional test cases that found most people's problems in part 2. Once you have a test case (with a small input size, so you can easily step through it by hand) you can usually identify the particular problems in your solution. This will also help you understand why it works.

If that still doesn't work, then find working solutions and try to understand them. Some people's solutions get really clever, don't worry about those. If it's not even remotely clear to you what's happening in it, it's not a solution you need to study yet. Find the simplest, brute force solutions first. Then find ones that look similar but are optimized in some way.

tomalaci yesterday at 2:17 PM
I usually give myself 30-60 mins to solve. If I can't do it by then I will look up solutions and -study- them (also break it piece by piece and see if I can generalize it for future problems). I would look at solutions even after solving it by myself.

I find that to be the best balance between challenge and learning something new. You will mentally burn yourself out if you keep bashing against the wall for hours or more, not quite a healthy thing to do :)

Meanwhile, people who actually try to compete on this stuff have already developed rich library of specialized algorithms to leap ahead of average programmer. Well, I guess nowadays a lot of it is LLM assisted too.

vismit2000 today at 3:50 AM
https://github.com/norvig/pytudes/tree/main/ipynb Look at Norvig's solution - which are a good learning point for even those who are able to solve everything!
weavie yesterday at 1:50 PM
The more you struggle at something the more you will learn. That works up to the point where the struggle is beyond your capacity for struggle - then you just get stuck. So ideally (assuming you are doing this because you want to learn something) you want to reduce the amount of struggle to just below your capacity.

Just copying someone else's solution, or getting an LLM to fix it for you will be very low struggle, so you won't learn much.

To add some struggle, maybe look up a solution in a different language and translate to your language? You could choose a solution in a language similar to your language, so if you are solving in C, perhaps look up a C# solution or to make it harder look up a solution in a different paradigm. Find a Haskell solution or a Prolog one and see if that gives you enough hints.

red_Seashell_32 yesterday at 1:14 PM
It’s better to look at other solutions, analyze and understand them to learn something new rather than giving up and not learning something new
brudgers today at 1:04 AM
Not being flippant.

You would probably learn more vibe coding a solution than just reading code.

Because your engagement would be active, you would practice useful technique, and have an opportunity to iterate.

Good luck.