[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] 4 Consecutive Letters



In message <20000814095836.A595478@linguist.dartmouth.edu>,
    Ronald J Kimball writes:

: Here's my first solution:
: 
:   perl -ne'@a=a..z;for$i(0..22){print,last if/@{[$a[$i]..$a[$i+3]]}/x}'
: 
: And a slightly shorter one:
: 
:   perl -ne'for$i(97..119){print,last if/@{[map chr,$i..$i+3]}/x}'

I'll probably lose my tour card, but

    sub inarow {
        my $word = lc(shift || '');
        my $cnt  = shift || 0;

        return unless $word && $cnt > 0;
        return unless length($word) >= $cnt;

        return 1 if $cnt == 1;

        my $code = q<
    do {
        study $word;
        my $a = "abcdefghijklmnopqrstuvwxyz";
        if (>;

        $code .= join ' || ',
                 map '$a =~ /' . $_ . '/',
                 map substr($word, $_, $cnt),
                 0 .. length($word)-$cnt;

        $code .= q<) { 1 }
        else { 0 }
    }>;

        #print $code, "\n";
        my $result = eval $code;
        die $@ if $@;

        $result;
    }

Greg

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe