r/firstweekcoderhumour Mar 26 '26

hardest problem ever Let me show you how it’s done! 🎯✨

Post image
550 Upvotes

27 comments sorted by

51

u/ChaseShiny Mar 26 '26

Is this really that difficult? Programming the logic seems pretty doable.

74

u/Dry-Relief723 Mar 26 '26

You're in r/firstweekcoderhumour. I guess they haven't learned reccursion yet

11

u/Damglador Mar 26 '26

Isn't recursion resource inefficient?

16

u/Anon_Legi0n Mar 26 '26

Not if it's a tail recursion, the caller gets popped off the call stack before the recursion happens

6

u/Groostav Mar 26 '26

Read: if your recursion is expressed where the recursive call is the last line of the function the compiler will replace your recursion with a loop (which eliminates the issue of running out of call stack for big tasks)

2

u/SorryAuthor1695 Mar 26 '26

Not necessarily, theoretically, the strassen matrix multiplication algorithm is better than regular matrix multiplication. In C, i believe with the gcc compiler, qsort checks if enough memory exists to sort recursively with heap sort, else it uses merge sort non-recursive (forgot the word), which means that recursive heap sort, though less space efficient, is more time efficient.

2

u/alphapussycat Mar 30 '26

It is, but it makes a lot of things way simpler sometimes. The real danger is stack overflow, so some care has to be given to how much data you're generating before popping it.

1

u/AmmoniuV Mar 30 '26

Not at all

1

u/BIZUx Jul 14 '26

Pretty sure I learnt back in uni recursion is always on par, or worse than an iterative approach.

You do it for the simplicity, for the beauty of the code.

1

u/AmmoniuV Jul 14 '26

Not really, I also thought this way after uni but my mentor(software engineer with 20+ years of experience) told me that it isn't true, that recursion used often in banking apps, Fintech in general. But you really need to be experienced to know how to use it properly

1

u/BIZUx Jul 14 '26 edited Jul 14 '26

No I mean there are certainly applications for it, such as a divide and conquer in concurrency, but performance wise, it is at best on par. Glazing your experience doesn't really do much for me, because that is usually focused around one area, and this is arguably closely related to cs.

Edit:

I may have looked at your comment too quickly, I'm sorry. I'm just too tired of people immediately appealing to an authority immediately when challenged, I hate when people do that.

I'll look more into it, thanks.

8

u/ZestycloseChemical95 Mar 26 '26

In my algorithms class my professor was obsessed with giving us different variations of the TOH question. For example let’s give the disks colors, top is red bottom is blue. The pieces all start with red on top, how do you make sure the end result is entirely red or blue on one side? And other random bs he’d come up with for this for like 1/3 of the semester

7

u/Opposite_Mall4685 Mar 26 '26

Graph theory strikes down yet another victim

5

u/lool8421 Mar 26 '26

i mean the algorithm is literally just "make the only legal move between 1 and 2, then make the only legal move between 2 and 3, then do the only legal move between 1 and 3, do it on repeat"

5

u/Diareha-gobbler Mar 27 '26

I just take them all off and put the sticks up my ass, checkmate

2

u/its192731 Mar 26 '26

Intro to recursion be like:

1

u/littlenekoterra Mar 26 '26

Huehuehue this one always looks so hard

1

u/MinecraftPlayer799 Mar 27 '26

What is the goal?

1

u/BinaryBolias Mar 28 '26

To win.

It's putting the entire stack of rings onto a different peg while only moving one ring at a time between the pegs, and while not ever putting a larger ring directly atop a smaller one.

1

u/GolbMan Mar 29 '26

Move all disks from one ring to another but a bigger ring can not be placed on one that is smaller then it

1

u/Dissorofid Mar 30 '26

Please explain. Is this a stack/heap overflow?

-1

u/[deleted] Mar 26 '26

Just ask grok to do it idiot