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

Re: [FWP] Weekend Edition Sunday Puzzle (from c.l.p.mod)



On Fri, Jul 16, 1999 at 12:24:05PM -0700, Vicki Brown wrote:
> Here's the puzzle:
> 
>    Take the 9-letter-word SUBDEACON (the name of a church official).
>    The word contains the first 5 letters of the alphabet, ABCD and E
>    consecutively inside it, although not in alphabetical order. This
>    is a two-part challenge: 
>
>    first, can you think of a common 8-letter
>    word that has ABCDE consecutively inside it, not necessarily in
>    alphabetical order; 
>    second, can you think of a common 7-letter word
>    with the same property? Both answers are uncapitalized words that
>    are familiar to everyone.

#!/usr/bin/perl -nwl

# A mapping of the letters we're looking for.
BEGIN { %orig_chrs = map { (uc $_,1) } qw(a b c d e); }

chomp;

# No capitalized words, must be length 7 or 8, must have
# ABCDE consecutively (the ABCDE check is just a measure to weed out
# obvious non-matches)
next unless !tr/A-Z// && (length ==7 || length == 8) && /[ABCDE]{5}/i;

# Make a copy of the mappping for this run.
%chrs = %orig_chrs;

@chrs = split "";

foreach my $pos (0..$#chrs) { 
        my $chr = $chrs[$pos];
        my $start_pos;

        if(!keys %chrs)  # Found them all!
        {
                print; 
                last; 
        } 
        elsif(exists $chrs{uc $chr}) {  # Found a matching character.
		# Note that we've already found this one,
		# this is to prevent eeeee from matching.
                delete $chrs{uc $chr};
                next; 
        } 
        else { 	# Sequence broken, start over.
                %chrs = %orig_chrs; 
                next; 
        }
}

Run /usr/dict/words through that and it should give you answers.  I
found the answer to the 7 letter one (I'm not going to give it away
:P) but no 8 letter.



-- 

Michael G Schwern                                           schwern@pobox.com
                    http://www.pobox.com/~schwern
     /(?:(?:(1)[.-]?)?\(?(\d{3})\)?[.-]?)?(\d{3})[.-]?(\d{4})(x\d+)?/i

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