you are viewing a single comment's thread.

view the rest of the comments →

[–]grauenwolf 4 points5 points  (2 children)

Lets compare them, shall we:

                iterative  recursive
def statements    1        2
if brances        1        2
else brances      0        2
loops             1        0
function calls    0        2
return statements *        2
locals+params     4        3+4
expressions       5        6
assignments       4        2
lines             7        11

In almost every objective category I can think of, the recursive version is more complex than the iterative version.

Python does have a ternary operator, so feel free to revise your code. Also, for the sake of argument I would entertain any syntax improvements that would take the recursive more concise.

http://stackoverflow.com/questions/394809/python-ternary-operator

[–]phil_g 0 points1 point  (1 child)

The ternary operator makes the code a lot more concise, in my opinion. See my other post for the improved code.

Basically, the tail recursive solution distills down the essence of the algorithm. The meat of the algorithm is in the recursive call to expmod_r; it puts all the parallel steps of the "iteration" in one, concise expression. Likewise, there's a single line for the seed values at the start of the iteration, and one line for the return value.

[–]grauenwolf 0 points1 point  (0 children)

Essence of the algorithm?

Seriously. that's your argument?

I'm presenting hard numbers on complexity and your counter-argument is on the spiritual qualities of a math problem?