Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.
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
I don't think it will compile. You're passing a formula to a parm not defined as Value or Const.
A1: It will halt when the negative number won't fit into 10u0.
Chris Ringer