Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: (golf) Collapse repetitions within a string

by Jasper (Chaplain)
on Jun 26, 2003 at 12:08 UTC ( [id://269205]=note: print w/replies, xml ) Need Help??


in reply to (golf) Collapse repetitions within a string

just golfing yours:
perl -nle'print$1?("$1 repeated ",length($&)/length$1," times"):$&whil +e/(\w+?)\1+|./g'
You don't need the brackets around the time(s), because any time it's less than two, you only print out one character. You were matching \w, so I didn't check for defined on $1, just $1, but it should give the same results.

I think that's 75, not including switches.

Jasper

Log In?
Username:
Password:

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

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

    No recent polls found