blob: b72c777c897fee95cfb146c42cc986e4e72d4d4e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#!/usr/bin/env perl
use strict;
use warnings;
use POSIX qw<round>;
my $maxLength=$ARGV[0]//20; #If no max on command line use 20
while () {
my $str="";
#make a random length string of up to $maxLength long
$str.=chr round rand()+40 for 0..int rand $maxLength;
my $v=0;
for (split "",$str) {
$v+=(ord($_)-40)*-2+1;
last unless $v >=0;
}
if($v==0) {
print("balanced: $str\n");
sleep 1;
next;
}
print("unbalanced: $str\n");
}
|