Balanced brackets: Difference between revisions
Content added Content deleted
Simple9371 (talk | contribs) (Removed CALL SET and changed to the FOR method. Also, changed the sample output.) |
|||
Line 601: | Line 601: | ||
::The Main Thing... |
::The Main Thing... |
||
set numofpairs= |
set numofpairs=5 |
||
set howmanystrings=10 |
set howmanystrings=10 |
||
cls |
cls |
||
Line 624: | Line 624: | ||
set /a rnd=%random%%%%j%+1 |
set /a rnd=%random%%%%j%+1 |
||
set /a oppos=%j%-!rnd! |
set /a oppos=%j%-!rnd! |
||
::A new trick for substitution of delayed variables... |
|||
⚫ | |||
for /f "tokens=1-2" %%A in ("!rnd! !oppos!") do ( |
|||
⚫ | |||
set str2=!samp:~0,%%B! |
|||
) |
|||
set samp=!str2!%put2%!str1! |
set samp=!str2!%put2%!str1! |
||
set /a "j+=1","i+=1" |
set /a "j+=1","i+=1" |
||
Line 641: | Line 644: | ||
if "!currchar!"=="" ( |
if "!currchar!"=="" ( |
||
set /a prev=%counter%-1 |
set /a prev=%counter%-1 |
||
for %%A in ("!prev!") do set prevchar=!samp:~%%A,1! |
|||
if "!prevchar!"=="[" goto :notbal |
if "!prevchar!"=="[" goto :notbal |
||
goto :itsbal |
goto :itsbal |
||
Line 663: | Line 666: | ||
::/Check for Balance.</lang> |
::/Check for Balance.</lang> |
||
{{out}} |
{{out}} |
||
<pre> |
|||
[][][[]][][]]][][][[ is NOT Balanced. |
|||
[[[]][[ |
[[[[[]][[]][]][][]]] is Balanced. |
||
[[ |
[[[[[]]]]][][][]][][ is NOT Balanced. |
||
[[[ |
][[[[[[[]]][]]][][]] is NOT Balanced. |
||
[][[[[]]]][[[[]]]][] is Balanced. |
|||
[[ |
[[[][[[]][][]]]][][] is Balanced. |
||
[[][[]][[]]]]][][[[] is NOT Balanced. |
|||
[[[]][] |
[][][]][][]]][][][[[ is NOT Balanced. |
||
[[]][][][[ |
[[]][][][[][[[]]]][] is Balanced. |
||
[[[[[][[][[]]]]][]]] is Balanced. |
|||
Press any key to continue . . .</pre> |
Press any key to continue . . .</pre> |