new files

This commit is contained in:
Ingy döt Net 2013-04-10 12:38:42 -07:00
parent 3af7344581
commit 86c034bb8b
1364 changed files with 21352 additions and 0 deletions

View file

@ -0,0 +1,13 @@
use 5.10.0; # for given ... when construct
sub balanced {
my $depth = 0;
for (split //, shift) {
when('[') { ++$depth }
when(']') { return if --$depth < 0 }
}
return !$depth
}
for (']', '[', '[[]', '][]', '[[]]', '[[]]]][][]]', 'x[ y [ [] z ]][ 1 ][]abcd') {
print balanced($_) ? "" : "not ", "balanced:\t'$_'\n";
}

View file

@ -0,0 +1,10 @@
use 5.10.0; # for '++' non-backtrack behavior
sub balanced {
my $_ = shift;
s/(\[(?:[^\[\]]++|(?1))*\])//g;
! /[\[\]]/;
}
for (']', '[', '[[]', '][]', '[[]]', '[[]]]][][]]', 'x[ y [ [] z ]][ 1 ][]abcd') {
print balanced($_) ? "" : "not ", "balanced:\t'$_'\n";
}