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

Re: Block Search

by meetraz (Hermit)
on Oct 04, 2002 at 20:18 UTC ( [id://202883]=note: print w/replies, xml ) Need Help??


in reply to Block Search

My golf solution for this:
$s1 = 'abbbcddddfegrgrgddeeeeedd'; print"$s1\n\n";($s2=$s1)=~s/((.)\2*)/$1,/g;map{$i=index($s1,$_);$l=len +gth;print '-'x$i,$_,'-'x(length($s1)-$i-$l),"\n";substr($s1,$i,$l,','x$l);}sort{ +length$b <=>length$a}split(/,/,$s2);
update: shorter now

Replies are listed 'Best First'.
Re2: Block Search
by blakem (Monsignor) on Oct 04, 2002 at 21:22 UTC
    fore! 136 chars
    #!/usr/bin/perl -wT use strict; my $s1 = 'abbbcddddfegrgrgddeeeeedd'; # 1 2 3 4 5 6 #2345678901234567890123456789012345678901234567890123456789012345678 print$s1.$/x2;push(@;,[$+[0]-$+[1],"-"x($+[1]-1).$&."-"x(length($s1) -$+[0])])while$s1=~/(.)\1*/g;print$$_[1].$/for sort{$$b[0]-$$a[0]}@;

    -Blake

      wow! ++blakem ... Can you break it down for me?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-25 20:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found