fork download
  1. @lines = <>;
  2.  
  3. $n=1000;
  4. $long = '';
  5. # generating one random sequence of length $n:
  6. while ($n--){
  7. $long .= qw<( )>[int (rand()*2) ]
  8. }
  9.  
  10. $m;
  11. $m = qr/\((?:|(??{$m})++)*\)/;
  12.  
  13. for (@lines, $long){
  14. undef %occ;
  15. map { ++$occ{(length)} } /$m+/g;
  16. $max = 0;
  17. $max < $_ and $max = $_ for keys %occ;
  18. print $max," ",$occ{$max} || 1,$/;
  19. }
Success #stdin #stdout 0.26s 3740KB
stdin
)((())))(()())
))(
()(())()
((((()(((
(()())()(())()()())())()((()(()(())()()())((()(())()(()()()()))()(())()(((()())()(()((())()(())(()))
stdout
6 2
0 1
8 1
2 1
28 1
662 1