If you’re thinking of writing n lines of code with calls to alert(), it doesn’t work because you have to submit a constant-sized program before you see n. Otherwise please email me this trivial solution because I may have overlooked it.
Actually the brainfart was on my part. I’d forgotten that a common instruction doesn’t exist in Javascript, though that hasn’t kept some folks from implementing one, as a workaround. (The mind boggles.)
You’ll need to specify which version of Javascript to target, since some slightly less obvious solutions may involve version-dependent features.
You can use recursive calls to implement this with the same asymptotic space requirements as a simple loop, the trick is algorithmic, not in smuggling in a disguised loop.
If you’re thinking of writing n lines of code with calls to alert(), it doesn’t work because you have to submit a constant-sized program before you see n. Otherwise please email me this trivial solution because I may have overlooked it.
Actually the brainfart was on my part. I’d forgotten that a common instruction doesn’t exist in Javascript, though that hasn’t kept some folks from implementing one, as a workaround. (The mind boggles.)
You’ll need to specify which version of Javascript to target, since some slightly less obvious solutions may involve version-dependent features.
You can use recursive calls to implement this with the same asymptotic space requirements as a simple loop, the trick is algorithmic, not in smuggling in a disguised loop.
My current solution is 12 lines long and uses only recursion and function calls and addition and variable assignments.