Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,39 @@
/*REXX program checks for balanced brackets [ ] ─── some fixed, others random.*/
parse arg seed . /*obtain optional argument from the CL.*/
if datatype(seed,'W') then call random ,,seed /*if specified, then use as RANDOM seed*/
@.=0; yesNo.0= right('not OK', 50) /*for bad expressions, indent 50 spaces*/
yesNo.1= 'OK' /* [↓] the 14 "fixed" ][ expressions*/
q= ; call checkBal q; say yesNo.result '«null»'
q= '[][][][[]]' ; call checkBal q; say yesNo.result q
q= '[][][][[]]][' ; call checkBal q; say yesNo.result q
q= '[' ; call checkBal q; say yesNo.result q
q= ']' ; call checkBal q; say yesNo.result q
q= '[]' ; call checkBal q; say yesNo.result q
q= '][' ; call checkBal q; say yesNo.result q
q= '][][' ; call checkBal q; say yesNo.result q
q= '[[]]' ; call checkBal q; say yesNo.result q
q= '[[[[[[[]]]]]]]' ; call checkBal q; say yesNo.result q
q= '[[[[[]]]][]' ; call checkBal q; say yesNo.result q
q= '[][]' ; call checkBal q; say yesNo.result q
q= '[]][[]' ; call checkBal q; say yesNo.result q
q= ']]][[[[]' ; call checkBal q; say yesNo.result q
#=0 /*# additional random expressions*/
do j=1 until #==26 /*gen 26 unique bracket strings. */
q=translate( rand( random(1,10) ), '][', 10) /*generate random bracket string.*/
call checkBal q; if result==-1 then iterate /*skip if duplicated expression. */
say yesNo.result q /*display the result to console. */
#=#+1 /*bump the expression counter. */
end /*j*/ /* [↑] generate 26 random "Q" strings.*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
?: ?=random(0,1); return ? || \? /*REXX BIF*/
rand: $=copies(?()?(),arg(1)); _=random(2,length($)); return left($,_-1)substr($,_)
/*──────────────────────────────────────────────────────────────────────────────────────*/
checkBal: procedure expose @.; parse arg y /*obtain the "bracket" expression. */
if @.y then return -1 /*Done this expression before? Skip it*/
@.y=1 /*indicate expression was processed. */
!=0; do j=1 for length(y); _=substr(y,j,1) /*get a character.*/
if _=='[' then !=!+1 /*bump the nest #.*/
else do; !=!-1; if !<0 then return 0; end
end /*j*/
return !==0 /* [↑] "!" is the nested ][ counter.*/

View file

@ -0,0 +1,67 @@
/*REXX program to check for balanced brackets [] **********************
* test strings and random string generation copied from Version 1
* the rest restructured (shortened) to some extent
* and output made reproducible (random with a seed)
* 10.07.2012 Walter Pachl
**********************************************************************/
yesno.0 = 'unbalanced'
yesno.1 = ' balanced'
done.=0 /* memory what's been done */
n=0 /* number of tests */
Call testbal '[][][][[]]' /* first some user written tests */
Call testbal '[][][][[]]]['
Call testbal '['
Call testbal ']'
Call testbal '[]'
Call testbal ']['
Call testbal '][]['
Call testbal '[[]]'
Call testbal '[[[[[[[]]]]]]]'
Call testbal '[[[[[]]]][]'
Call testbal '[][]'
Call testbal '[]][[]'
Call testbal ']]][[[[]'
Call testbal ']'
Call testbal '['
/* then some random generated ones */
Call random 1,2,12345 /* call random with a seed */
/* makes test reproducible */
do Until n=30 /* up to 30 tests */
s=rand(random(1,8)) /* a 01 etc. string of length 4-32 */
q=translate(s,'[]',01) /* turn digits into brackets */
if done.q then /* string was already here */
iterate /* don't test again */
call testbal q /* test balance */
End
exit
testbal: /* test the given string and show result */
n=n+1 /* number of tests */
Parse Arg q /* get string to be tested */
done.q=1 /* mark as done */
call checkBal q /* test balance */
lq=format(length(q),2)
say right(n,2) lq yesno.result q/* show result and string */
Return
/*-----------------------------------PAND subroutine-----------------*/
pand: p=random(0,1); return p || \p
/*-----------------------------------RAND subroutine-----------------*/
rand: pp=pand(); pp=pand()pp; pp=copies(pp,arg(1))
i=random(2,length(pp)); pp=left(pp,i-1)substr(pp,i)
return pp
checkBal: procedure /*check for balanced brackets () */
Parse arg y
nest=0;
do While y<>''
Parse Var y c +1 y /*pick off one character at a time */
if c='[' then /* opening bracket */
nest=nest+1 /* increment nesting */
else do /* closing bracket */
if nest=0 then /* not allowed */
return 0; /* no success */
nest=nest-1 /* decrement nesting */
end
end
return nest=0 /* nest=0 -> balanced */

View file

@ -0,0 +1,21 @@
/*REXX program checks for around 125,000 generated balanced brackets expressions [ ] */
bals=0
#=0; do j=1 until L>20 /*generate lots of bracket permutations*/
q=translate( strip( x2b( d2x(j) ), 'L', 0), "][", 01) /*convert ──► ][*/
L=length(q)
if countStr(']', q) \== countstr('[', q) then iterate /*not compliant?*/
#=#+1 /*bump legal Q's*/
!=0; do k=1 for L; parse var q ? 2 q
if ?=='[' then !=!+1
else do; !=!-1; if !<0 then iterate j; end
end /*k*/
if !==0 then bals=bals+1
end /*j*/ /*done all 20─character possibilities? */
say # " expressions were checked, " bals ' were balanced, ' ,
#-bals " were unbalanced."
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
countStr: procedure; parse arg n,h,s; if s=='' then s=1; w=length(n)
do r=0 until _==0; _=pos(n,h,s); s=_+w; end; return r