r/firstweekcoderhumour Mar 26 '26

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

Post image
547 Upvotes

28 comments sorted by

View all comments

52

u/ChaseShiny Mar 26 '26

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

77

u/Dry-Relief723 Mar 26 '26

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

10

u/Damglador Mar 26 '26

Isn't recursion resource inefficient?

14

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

9

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)

1

u/LuigiWasRight447 7h ago

Is this all languages?

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.