Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Golf: Embedded In Order

by japhy (Canon)
on Apr 27, 2001 at 18:01 UTC ( #76095=note: print w/ replies, xml ) Need Help??


in reply to Golf: Embedded In Order

Here's mine. It's très cool.

# 37 chars (between the {...}) sub seq{shift=~join'.*',map"\Q$_",split//,pop}
Update -- after seeing chipmunk's code, which beats mine, I offer one minor adjustment:
sub seq{($t=pop)=~s/./$&.*/sg;pop=~/$t/s}
Although, should the $t by my()ed? I'm all for strict-compliant golf. Anyway, I changed the @_ access to pop, and added a needed /s modifier to both regexes. It makes it longer than chipmunk's, but doesn't break on cases involving newlines.

japhy -- Perl and Regex Hacker


Comment on Re: Golf: Embedded In Order
Select or Download Code
Re: Re: Golf: Embedded In Order
by chipmunk (Parson) on Apr 30, 2001 at 09:08 UTC
    Since the goal of Perl Golf is to make the code as short as possible, it seems to me that making the code strict-compliant is a waste of characters. Especially since one could just do something like:
    sub seq{ ($~=pop)=~s/./$&.*/sg;pop=~/$~/s }
    :)

    I do try to avoid warnings in my Golf solutions, though.

Re: Re: Golf: Embedded In Order
by petral (Curate) on May 26, 2001 at 01:41 UTC
    But you don't need the $t! 27 chars:
    seq{shift=~join".*",split//,pop}
    Or 25 using /./g:
    seq{shift=~join".*",pop=~/./g}
    Or 33 with pathological protection:
    seq{shift=~join"\E.*\Q","",pop=~/./gs}
      p

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2014-12-22 02:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (110 votes), past polls