Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
40
Task/Balanced-brackets/VBScript/balanced-brackets-2.vb
Normal file
40
Task/Balanced-brackets/VBScript/balanced-brackets-2.vb
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
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