Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
35 chars:
sub seq{!grep{$_[0]!~/\G.*?$_/g}split//,pop}

update: And now what everyone's been waiting for:

The longest word(s) with all letters in alphabetical order:

solaris /usr/dict/words:  almost biopsy
linux    /usr/dict/words:  abhors almost begins biopsy chintz

The longest word(s) with all letters in reverse alphabetical order:

sol:  sponge
lun:  sponged wronged

The word(s) with the most letters in alphabetical order:

sol: condemnatory 8
lun: administratively antidisestablishmentarianism behavioristic
        demonstratively incomprehensibility 8
shortest: behavioristic

update oopsdate: Removed words w/ most letters in order. It was wrong, though noone remarked on it (if you were being polite, thank you). Will re-post when, if I get it right. Anyone else care to try?
update 3: maybe the above are right now. The code is:
sub seq{ my @x=split"",pop; my $s=pop; my $cc=0; for my $k (0..$#x-1) { $c = seq1($cc, $s, @x[$k..$#x]); $cc = ($c, $cc)[ $c < $cc ] } $cc } sub seq1 { my($cc, $s, @x) = @_; my $c=pos($s)=0; my $op=0; my $cy=0; for my $k (0..$#x) { $s =~ /$x[$k]/gc or next; if ($cc <= @x - $k) { # what if we skip this char? my $cx = $c + seq1( $cy, substr($s, $op), @x[$k+1 .. $#x]); $cy = ($cx, $cy)[$cx < $cy]; } $op = pos($s); $c++; } $c = ($cy, $c)[ $cy < $c ]; }
Update the last:  Actually, this one can be done in 27 chars:
sub seq{!grep$_[0]!~/$_/g,pop=~/./g}
  ...or 30 with provision for strange_chars/newlines:
sub seq{!grep$_[0]!~/\Q$_/g,pop=~/./gs}
But see my trimming of japhy's above.

  p


In reply to Re: Golf: Embedded In Order by petral
in thread Golf: Embedded In Order by Masem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2024-04-19 15:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found