Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Efficient run determination.

by Enlil (Parson)
on Nov 14, 2002 at 10:38 UTC ( [id://212812]=note: print w/replies, xml ) Need Help??


in reply to Efficient run determination.

Neat problem. Here is my initial crack at it:
use strict; use Data::Dumper; my $string =' aaaa bbbbccccccccbbbb aaaabbbbbcdddddddddddddddd +dddd'; my @bah; my $old_pos = 0; while ($string =~ /((.)\2*)/g) { push @bah, [$2,$old_pos,length($1)]; $old_pos = pos($string); } print Dumper(\@bah);
I am really interested as to how the benchmarking turns out. Let us know.

Update: It is late, but I just realized i would probably benchmark all the code that turns up on this post anyhow. Once again interesting problem.

Updated Again: Changed the \2+ to \2* or it would have failed when there was a series one character long.

-enlil

Replies are listed 'Best First'.
Re: Re: Efficient run determination.
by Enlil (Parson) on Nov 14, 2002 at 11:42 UTC
    Second Try. I am going off to bed after this, my benchmarking tells me this is faster than my previous try:
    use strict; use Data::Dumper; my $string =' aaaa bbbbccccccccbbbb aaaabbbbbcdddddddddddddddd +dddd'; my @bah; while ($string =~ /((.)\2*)/g) { push (@bah, [$2,$-[1],$+[1] - $-[1]]); } print Dumper(\@bah);

    Update Changed the \2+ to \2* or it would have failed when there was a series one character long.

    -enlil

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://212812]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-03-19 03:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found