Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
53
Task/Balanced-brackets/Batch-File/balanced-brackets.bat
Normal file
53
Task/Balanced-brackets/Batch-File/balanced-brackets.bat
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
:: Balanced Brackets Task from Rosetta Code
|
||||
:: Batch File Implementation
|
||||
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
set "num_pairs=10"
|
||||
set "num_strings=10"
|
||||
|
||||
:: the main thing
|
||||
for /l %%s in (1, 1, %num_strings%) do (
|
||||
call :generate
|
||||
call :check
|
||||
)
|
||||
echo(
|
||||
pause
|
||||
exit /b 0
|
||||
|
||||
:: generate strings of brackets
|
||||
:generate
|
||||
set "string="
|
||||
rem put %num_pairs% number of "[" in string
|
||||
for /l %%c in (1, 1, %num_pairs%) do set "string=!string!["
|
||||
rem put %num_pairs% number of "]" in random spots of string
|
||||
set "ctr=%num_pairs%"
|
||||
for /l %%c in (1, 1, %num_pairs%) do (
|
||||
set /a "rnd=!random! %% (!ctr! + 1)"
|
||||
for %%x in (!rnd!) do (
|
||||
set "left=!string:~0,%%x!"
|
||||
set "right=!string:~%%x!"
|
||||
)
|
||||
set "string=!left!]!right!"
|
||||
set /a "ctr+=1"
|
||||
)
|
||||
goto :EOF
|
||||
|
||||
:: check for balance
|
||||
:check
|
||||
set "new=%string%"
|
||||
:check_loop
|
||||
if "%new%" equ "" (
|
||||
echo(
|
||||
echo(%string% is Balanced.
|
||||
goto :EOF
|
||||
) else if "%old%" equ "%new%" ( %== unchangeable already? ==%
|
||||
echo(
|
||||
echo(%string% is NOT Balanced.
|
||||
goto :EOF
|
||||
)
|
||||
rem apply rewrite rule "[]" -> null
|
||||
set "old=%new%"
|
||||
set "new=%old:[]=%"
|
||||
goto check_loop
|
||||
Loading…
Add table
Add a link
Reference in a new issue