[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 04:27:11PM -0400, Michael G Schwern wrote:
> #!/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.
> 

I'm afraid that's a good sign your code has a bug.  As the puzzle text
states, these are both very common words.

In particular, your code requires the 5-letter sequence to be at the
beginning of the word, which it should not.

Ronald

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