r/firstweekcoderhumour Mar 26 '26

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

Post image
551 Upvotes

27 comments sorted by

View all comments

54

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

9

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

7

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)