Find limit of recursion: Difference between revisions

From Rosetta Code
Content added Content deleted
(→‎Tcl: Added implementation)
(VBScript)
Line 38: Line 38:
This is depth 999
This is depth 999
</pre>
</pre>

=={{header|VBScript}}==

Haven't figured out how to see the depth. And this depth is that of calling the O/S rather than calling within.

<lang vb>
'mung.vbs
option explicit

dim c
if wscript.arguments.count = 1 then
c = wscript.arguments(0)
c = c + 1
else
c = 0
end if
wscript.echo "[Depth",c & "] Mung until no good."
CreateObject("WScript.Shell").Run "cscript Mung.vbs " & c, 1, true
wscript.echo "[Depth",c & "] no good."
</lang>

Revision as of 09:39, 20 April 2010

Task
Find limit of recursion
You are encouraged to solve this task according to the task description, using any language you may know.
Find limit of recursion is part of Short Circuit's Console Program Basics selection.

Find the limit of recursion.

Batch File

MUNG.CMD is a commandline tool written in DOS Batch language. It finds the limit of recursion possible using CMD /C.

<lang dos>@echo off set /a c=c+1 echo [Depth %c%] Mung until no good cmd /c mung.cmd echo [Depth %c%] No good set /a c=c-1</lang>

Result (abbreviated):

...
[Depth 259] Mung until no good
[Depth 260] Mung until no good
[Depth 261] Mung until no good
[Depth 261] No good
[Depth 260] No good
[Depth 259] No good
...

Tcl

<lang tcl>proc recur i {

   puts "This is depth [incr i]"
   catch {recur $i}; # Trap error from going too deep

} recur 0</lang> The tail of the execution trace looks like this:

This is depth 995
This is depth 996
This is depth 997
This is depth 998
This is depth 999

VBScript

Haven't figured out how to see the depth. And this depth is that of calling the O/S rather than calling within.

<lang vb> 'mung.vbs option explicit

dim c if wscript.arguments.count = 1 then c = wscript.arguments(0) c = c + 1 else c = 0 end if wscript.echo "[Depth",c & "] Mung until no good." CreateObject("WScript.Shell").Run "cscript Mung.vbs " & c, 1, true wscript.echo "[Depth",c & "] no good." </lang>