Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Efficient run determination.

by Enlil (Parson)
on Nov 14, 2002 at 10:38 UTC ( #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
Node Status?
node history
Node Type: note [id://212812]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2019-07-23 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If you were the first to set foot on the Moon, what would be your epigram?






    Results (24 votes). Check out past polls.

    Notices?