Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,36 +0,0 @@
|
|||
For n = 1 To 10
|
||||
sequence = Generate_Sequence(n)
|
||||
WScript.Echo sequence & " is " & Check_Balance(sequence) & "."
|
||||
Next
|
||||
|
||||
Function Generate_Sequence(n)
|
||||
For i = 1 To n
|
||||
j = Round(Rnd())
|
||||
If j = 0 Then
|
||||
Generate_Sequence = Generate_Sequence & "["
|
||||
Else
|
||||
Generate_Sequence = Generate_Sequence & "]"
|
||||
End If
|
||||
Next
|
||||
End Function
|
||||
|
||||
Function Check_Balance(s)
|
||||
Set Stack = CreateObject("System.Collections.Stack")
|
||||
For i = 1 To Len(s)
|
||||
char = Mid(s,i,1)
|
||||
If i = 1 Or char = "[" Then
|
||||
Stack.Push(char)
|
||||
ElseIf Stack.Count <> 0 Then
|
||||
If char = "]" And Stack.Peek = "[" Then
|
||||
Stack.Pop
|
||||
End If
|
||||
Else
|
||||
Stack.Push(char)
|
||||
End If
|
||||
Next
|
||||
If Stack.Count > 0 Then
|
||||
Check_Balance = "Not Balanced"
|
||||
Else
|
||||
Check_Balance = "Balanced"
|
||||
End If
|
||||
End Function
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
option explicit
|
||||
|
||||
function do_brackets(bal)
|
||||
dim s,i,cnt,r
|
||||
if bal then s="[":cnt=1 else s="":cnt=0
|
||||
for i=1 to 20
|
||||
if (rnd>0.7) then r=not r
|
||||
if not r then
|
||||
s=s+"[" :cnt=cnt+1
|
||||
else
|
||||
if not bal or (bal and cnt>0) then s=s+"]":cnt=cnt-1
|
||||
end if
|
||||
next
|
||||
if bal and cnt<>0 then s=s&string(cnt,"]")
|
||||
if not bal and cnt=0 then s=s&"]"
|
||||
do_brackets=s
|
||||
end function
|
||||
|
||||
function isbalanced(s)
|
||||
dim s1,i,cnt: cnt=0
|
||||
for i=1 to len(s)
|
||||
s1=mid(s,i,1)
|
||||
if s1="[" then cnt=cnt+1
|
||||
if s1="]" then cnt=cnt-1
|
||||
if cnt<0 then isbalanced=false:exit function
|
||||
next
|
||||
isbalanced=(cnt=0)
|
||||
end function
|
||||
|
||||
function iif(a,b,c): if a then iif=b else iif=c end if : end function
|
||||
|
||||
randomize timer
|
||||
dim i,s,bal,bb
|
||||
for i=1 to 10
|
||||
bal=(rnd>.5)
|
||||
s=do_brackets(bal)
|
||||
bb=isbalanced(s)
|
||||
wscript.echo iif (bal,"","un")& "balanced string " &vbtab _
|
||||
& s & vbtab & " Checks as " & iif(bb,"","un")&"balanced"
|
||||
next
|
||||
Loading…
Add table
Add a link
Reference in a new issue