3 ms·
Hmm. How is this recursion? Maybe I don't understand what the word recursion means, but I thought that you'd have to call yourself directly or indirectly.
by bbcbasic 11y ago
Hmm. How is this recursion?
Maybe I don't understand what the word recursion means, but I thought that you'd have to call yourself directly or indirectly.
- ScottBurson 11y agoYou're right. This isn't recursion by any definition I know. Cute, though.
- bbcbasic 11y agoYes from the answers it seems it is recursion, as long as you stretch the definition of recursion to mean making subroutine calls, or code that can be refactored into a recursive solution. By these definitions, all but the most trivial code is recursive.
- LesZedCB 11y agoIt's not recursion in the sense that it calls itself. However, it does divide the problem into smaller (though explicitly defined) chunks, which is still recursion. You could state it that the multiple by a power of two is the sum of the multiples of one order of magnitude base 2 lower.
- sgustard 11y agoIt's equivalent to this recursive function, just change x2(n) to x(n, 2) and so on. // e is a power of two int mult(x, e) return e==1 ? x : mult(x, e/2) + mult(x, e/2) end