rsFalse has asked for the wisdom of the Perl Monks concerning the following question:
@lines = <>; $n=1000; $long = ''; srand; # generating one random sequence of length $n: while ($n--){ $long .= qw<( )>[int (rand()*2) ] } $m; $m = qr/\((?:|(??{$m})++)*\)/; # main thing for (@lines, $long){ undef %occ; map { ++$occ{(length)} } /$m+/g; $max = 0; $max < $_ and $max = $_ for keys %occ; print $max," ",$occ{$max} || 1,$/; }
# Example input: )((())))(()()) ))( ()(())() ((((()((( (()())()(())()()())())()((()(()(())()()())((()(())()(()()()()))()(())( +)(((()())()(()((())()(())(())) # Example output: 6 2 0 1 8 1 2 1 28 1 662 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to speed up that dynamic regex?
by Athanasius (Archbishop) on Nov 04, 2014 at 13:42 UTC | |
by AnomalousMonk (Archbishop) on Nov 05, 2014 at 01:59 UTC | |
by rsFalse (Chaplain) on Nov 07, 2014 at 10:44 UTC | |
by rsFalse (Chaplain) on Nov 07, 2014 at 11:28 UTC | |
by rsFalse (Chaplain) on Nov 04, 2014 at 23:45 UTC | |
|
Re: how to speed up that dynamic regex?
by Eily (Monsignor) on Nov 04, 2014 at 12:20 UTC |