September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,44 +1,45 @@
|
|||
#define system.
|
||||
#define system'routines.
|
||||
#define extensions.
|
||||
import system'routines.
|
||||
import extensions.
|
||||
|
||||
#symbol randomBrackets =
|
||||
randomBrackets =
|
||||
{
|
||||
new : aLength
|
||||
= (0 == aLength)
|
||||
? [ emptyLiteralValue ]
|
||||
! [
|
||||
#var aBrackets :=
|
||||
Array new &length:(aLength int) set &every: (&index:i) [ #91 ]
|
||||
[
|
||||
if (0 == aLength)
|
||||
[ ^emptyLiteralValue ];
|
||||
[
|
||||
var aBrackets :=
|
||||
Array new length:(aLength int); populate(:i)($91)
|
||||
+
|
||||
Array new &length:(aLength int) set &every: (&index:i)[ #93 ].
|
||||
Array new length:(aLength int); populate(:i)($93).
|
||||
|
||||
aBrackets randomize:(aLength * 2).
|
||||
aBrackets := aBrackets randomize:(aLength * 2).
|
||||
|
||||
^ aBrackets summarize:(String new) literal.
|
||||
].
|
||||
^ aBrackets summarize:(String new); literal
|
||||
]
|
||||
]
|
||||
}.
|
||||
|
||||
#class(extension)op
|
||||
extension op
|
||||
{
|
||||
#method isBalanced
|
||||
isBalanced
|
||||
[
|
||||
#var aCounter := Integer new:0.
|
||||
var aCounter := Integer new:0.
|
||||
|
||||
self seek &each:aChar [ (aCounter += (aChar => #91 ? [ 1 ] #93 ? [ -1 ])) < 0 ].
|
||||
self seekEach(:aChar)(aCounter append((aChar==$91)iif (1,-1)) < 0).
|
||||
|
||||
^ (0 == aCounter).
|
||||
^ (0 == aCounter)
|
||||
]
|
||||
}
|
||||
|
||||
#symbol program =
|
||||
program =
|
||||
[
|
||||
0 to:9 &doEach: (:aLength)
|
||||
0 to:9 do(:aLength)
|
||||
[
|
||||
#var anStr := randomBrackets new:aLength.
|
||||
var anStr := randomBrackets new:aLength.
|
||||
|
||||
console writeLine:"""":anStr:"""":((anStr isBalanced) => true ? [ " is balanced" ] false ? [ " is not balanced" ]).
|
||||
console printLine("""",anStr,"""",anStr isBalanced; iif(" is balanced"," is not balanced"))
|
||||
].
|
||||
|
||||
console readChar.
|
||||
console readChar
|
||||
].
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue