At 18:27 -0700 7/5/99, owner-fwp@technofile.org wrote: > I am sure everyone here reads clp.moderated--look at the puzzle there. Just in case some of you still don't read clp.mod (even though you now know it's in both Usenet and mailing list form :-), here's the puzzle: Newsgroups: comp.lang.perl.moderated Subject: This Week's Puzzle Solution Date: 4 Jul 1999 20:10:22 GMT This week's Weekend Edition Sunday Puzzle With Will Shortz on National Public Radio presents a problem of a class that can be defined as "match a substring of exactly n characters from the unordered set of discrete characters { c1, c2, ..., cn }". 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. (C) 1999 Will Shortz And here's my stab at a Perl 5 solution: #!/usr/local/bin/perl -w require 5.000; my $words = '/usr/share/dict/web2'; open WORDS, "<$words" or die "Cannot open file $words: $!"; while (<WORDS>) { print if (m/^[a-z]{7,8}\n$/ and m/([a-e])(?!\1) ([a-e])(?!\1|\2) ([a-e])(?!\1|\2|\3) ([a-e])(?!\1|\2|\3|\4) [a-e]/x); } Is there a better way (more succinct, more elegant, more efficient, whatever) to match this class of pattern? -- Jim Monty monty@primenet.com Tempe, Arizona USA -- -- |\ _,,,---,,_ Vicki Brown <vlb@cfcl.com> ZZZzz /,`.-'`' -. ;-;;,_ Journeyman Sourceror: Scripts & Philtres |,4- ) )-,_. ,\ ( `'-' P.O. Box 1269 San Bruno CA 94066 '---''(_/--' `-'\_) http://www.cfcl.com/~vlb http://www.macperl.com ==== Want to unsubscribe from Fun With Perl? Well, if you insist... ==== Send email to <fwp-request@technofile.org> with message _body_ ==== unsubscribe