Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Aha.. Never mind.
Please, please please, put some comments in your code if oh make it that complicated.. -
well it's just not the right tool for the job here. besides, it does make it easy to understand for humans/mathematicians
-
I think the recursive one is easier to understand here, but that's because you overuse python's line-saving tricks that harm readability to compress code (why is beyond me).
Generally speaking, recursive is good when you need a stack. So, depth first traversal, and not much more. -
SomeNone7135ySorry but I can't agree with your rage against recursion: it eats up stack only if it's not tail recursive (or if the language does not support tail recursion), and it is slow only if the algorithm is not optimized (which is the case for the naïve Fibonacci implementation). You can easily write a recursive implementation of your example using a for loop with range(). (Though I'm not into Python enough to give you an example in that language off the top of my head.)
-
SomeNone7135yAddendum to my previous comment: Here's an example in F#. Since text formatting sucks in the comments, I have two functions in the same scope but the helper function can easily be made local to the main function.
let rec fibloop n a b = if n > 0 then fibloop (n - 1) b (a + b) else b
let fibrec n = fibloop n 0 1 -
zen29d495y@SomeNone : I've used both the loop one and the recursive one... for small calculation recursive is okay... The recursive function doesn’t reduce to a smaller subproblem, so it doesn’t converges. Consider tower Hanoi eg: "Assuming the monks move discs at the rate of one per second, it would take them more than 5.8 billion centuries to solve the 64-disc problem."
Related Rants
-
ax1s15XBOX is short for XBox One X GNU is short for GNU Not Unix š²š± Recursive Definitions
-
lexxer5A: you need to learn how to figure out stuff yourself. B: how do i do that
-
iamgio3- Starts new project - "Wow, I'm coding it pretty well" - Hates it after two weeks, starts new project - "Wow,...
Who the fuck invented recursiveš”, it sucks in numerical computation, it takes excessive amount of memory, recomputation and fffffffuckš”. To calculate fibonacci of 50, it feels like MARK I. fuck they do nothing more than calling, like Peter calling Peter...š”
joke/meme
recursive
numerical
recursive_sucks