Balanced brackets: Difference between revisions
→{{header|Batch File}}: Improved code and new example
SqrtNegInf (talk | contribs) m (→Imperative Version: Fix link: Perl 6 --> Raku) |
Simple9371 (talk | contribs) (→{{header|Batch File}}: Improved code and new example) |
||
Line 1,147:
=={{header|Batch File}}==
Uses
<lang dos>:: Balanced Brackets Task from Rosetta Code
:: Batch File Implementation
Line 1,154:
setlocal enabledelayedexpansion
set "num_pairs=10"
set
:: the main thing
for /l %%
)
echo
pause
exit /b 0
::
:generate
set "string="
rem put %num_pairs% number of "[" in string
rem put %num_pairs% number of "]" in random spots of string
set "ctr=%num_pairs%"
▲ for /l %%x in (1,1,%numofpairs%) do (
for /l %%c in (1, 1, %num_pairs%) do (
)▼
set "left=!string:~0,%%x!"
set "right=!string:~%%x!"
▲ set /a rnd=%random%%%%j%+1
)
set "string=!left!]!right!"
▲ for /f "tokens=1-2" %%A in ("!rnd! !oppos!") do (
▲ set /a "j+=1","i+=1"
goto :add▼
)▼
goto :EOF
::
:check
set "new=%string%"
:check_loop
if "
) else if "%old%" equ "%new%" ( %== unchangeable already? ==%
set "changes=!input:[]=!"▼
goto check_loop▼
goto :EOF▼
▲echo.
rem apply rewrite rule "[]" -> null
▲echo %samp% is Balanced.
set "old=%new%"
▲goto :EOF
▲goto check_loop</lang>
▲echo.
▲echo %samp% is NOT Balanced.
{{out}}
▲[][][[]][][]]][][][[ is NOT Balanced.
[[[
]
]][][[
[[[]
[[[][[][]][
Press any key to continue . . .</pre>
|