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

Re: [FWP] Puzzle thread on clpmod



RJK wrote:
> 
> You had asked about words containing any 5 consecutive letters that are
> also consecutive in the alphabet.  So, 8 of my 26 are for 'abcde', but the
> others are for 'bcdef', 'cdefg', 'defgh', etc.

Here's my solution in Perl. Interestingly, it only found one
word besides the two that my 'abcde'-only solution found.
/usr/dict/words must be poor indeed.

  my %consec_cache;
  sub consec {  # for 'a', return 'abcde', etc.
    my $c = shift;
    $consec_cache{$c} ||= join '', $c++, $c++, $c++, $c++, $c
  }

  open F, "< /usr/share/lib/dict/words" or die "open words file: $!\n";
  while (<F>) {
    while ( /.(?=.{4})/g ) {
      my @s = sort split //, substr $_, pos()-1, 5 ;
      join('',@s) eq consec($s[0])
        and print and last;
    }
  }
  close F;

John Porter


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