I have a production bug... it only happens on Saturdays ever our ops folks have no idea - this can be replicated on a test server that gets no traffic.
I've always hated recursion. It's always seemed like a cutesy programming trick that's not reliable in all conditions.
You could blow the stack in an edge case that you didn't think of. So it should never be a standard pattern. It's only good if you need to rewrite something for optimization and recursion is appropriate. But in many cases recursion is slower.
"Look at what I can do in 5 lines of code!" is for programming contests, not for anything important.
I didn't have to program this, thankfully. The code was used as an example of recursion but the explanation was lacking so I ended up writing out each frame by end until I understood it. Took a few pages and a couple of hours.
I am grateful that I learned what I did going through it but I'd rather not do it again.
I didn't know the answer either, but usually you can compose solution from solutions of smaller problems.
solution(0): There are no disks. Nothing to do.
solution(n): Let's see if I can use solution(n-1) here. I'll use solution(n-1) to move all but last disk A->B, just need to rename the pins. Then move the largest disk A->C. Then use solution(n-1) to move disks B->C by renaming the pins.
There we go, we have a stack based solution running in exponential time.
It's one of the easiest problem in algorithm design, but running the solution by hand would give you a PTSD.
Is this a hard problem to solve? I've not attempted it yet myself.
I seem to remember this was a problem in Advent of Code one year?
I'm imagining there are plenty of algorithms to solve this already, right? With varying numbers of towers and plates? A general solution for solvable amounts of each? Maybe?
This is not a hard problem once you wrap your head around it. It is the earliest that some programmers learn about recursion which has a lot of pitfalls and can be frustrating at times.
Ah okay, that's where the trauma comes from then, perhaps? 😅 Just being new to a concept and perhaps starting out with a problem that is a little too big while at the same time learning the concept?
It's an easy problem to solve... eventually - it's more annoying to solve optimally and that's what programmers usually get handed as a play problem within a year or two of starting to tinker.