Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -2,32 +2,40 @@
|
|||
#define system'routines.
|
||||
#define extensions.
|
||||
|
||||
#symbol randomBrackets = &&:aLength
|
||||
// --- RandomBrackets ---
|
||||
|
||||
#symbol randomBrackets = (:aLength)
|
||||
[
|
||||
#var aBrackets := Array new &type'length:aLength &function: &&:i[ CharValue new:91 ] + Array new &type'length:aLength &function: &&:i[ CharValue new:93 ].
|
||||
^ (0 == aLength)
|
||||
? [ emptyLiteralValue ]
|
||||
! [
|
||||
#var aBrackets := arrayControl new &length:(aLength int) &each: i[ CharValue new &short:91 ] + arrayControl new &length:(aLength int) &each: i[ CharValue new &short:93 ].
|
||||
|
||||
randomControl randomize:(aLength * 2) &array:aBrackets.
|
||||
randomControl randomize:(aLength * 2) &array:aBrackets.
|
||||
|
||||
^ Summing new:(String new) foreach:aBrackets Literal.
|
||||
^ Summing new:(String new) foreach:aBrackets literal.
|
||||
].
|
||||
].
|
||||
|
||||
#symbol isBalanced = &&:aLiteral
|
||||
#symbol isBalanced = (:aLiteral)
|
||||
[
|
||||
#var aCounter := Integer new:0.
|
||||
|
||||
control foreach:aLiteral &until: &&:aChar [ aCounter append:(aChar => "[" ? [ 1 ] "]" ? [ -1 ]) < 0 ].
|
||||
control foreach:aLiteral &until: aChar [ aCounter append:(aChar => "[" ? [ 1 ] "]" ? [ -1 ]) < 0 ].
|
||||
|
||||
^ (0 == aCounter).
|
||||
].
|
||||
|
||||
// --- Program ---
|
||||
|
||||
#symbol program =
|
||||
[
|
||||
control from:0 &till:10 &do: &&:aLength
|
||||
control forrange &int:0 &int:9 &do: (&int:aLength)
|
||||
[
|
||||
#var anStr := randomBrackets:aLength.
|
||||
#var balanced := isBalanced:anStr.
|
||||
|
||||
console write:"""" write:anStr write:"""" writeLine:(balanced => true ? [ " is balanced" ] false ? [ " is not balanced" ]).
|
||||
consoleEx writeLine:"""":anStr:"""":(balanced => true ? [ " is balanced" ] false ? [ " is not balanced" ]).
|
||||
].
|
||||
|
||||
console readChar.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue