Question about recursion
Published by: **Tom Daly** on 11 Feb 2014 view comments(1)

I came across this recently and thought it was pretty funny. The original was in C.

Q: Does this function halt or not halt?

P function B

D function PI 10u 0

D input 10u 0

If input = 0;

return input;

Else;

return function(input - 1);

EndIf;

P E

A1: Mathematician - It only halts for non-negative inputs. Negative inputs will loop infinitely as x approaches minus infinity.

A2: Computer scientist - It always halts due to the eventual stack overflow on a real machine.

A3: Computer scientist - It always halts due to the eventual integer wrap around on a real machine.

A4: Physicist - It always halts because running it infinitely would require more energy than exists in the universe.

Silly