Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Challenge: Mystery Word Puzzle

by BrowserUk (Pope)
on Jan 12, 2005 at 23:21 UTC ( #421820=note: print w/ replies, xml ) Need Help??


in reply to Re: Challenge: Mystery Word Puzzle
in thread Challenge: Mystery Word Puzzle

Updated: to comply with all the revised rules.

Here's cleaner version of the above that also deals with (all?) of the edge cases.

#! perl -slw use strict; sub uniq { my %x; @x{@_} = (); keys %x } my $len = shift @ARGV; my $re ; my $re_ex; my $cap = 1; my $cap_ex = 1; my $hints_uniq; for my $i ( 0 .. $#ARGV ) { my( $word, $common ) = split ':', $ARGV[ $i ]; my $uniq = join'', uniq( split '', $word ); $hints_uniq .= $uniq; if( $common <= length $word ) { $re_ex .= "\n\t(?= (?: .*? (?: [^$uniq] | (?: ([$uniq])(?= + .* \\" . $cap_ex++ . ") ) ) ){" . ( $len - $common ) . "} )" } if( $common >= 2 ) { $re .= "\n\t(?=.*?([$word]).*?(?!\\$cap)"; if( $common > 2 ) { my $base = $cap; for my $n ( 1 .. $common-2 ) { $re .= "([$word]).*?(?!" . join('|', map{ '\\' . $_ } $base .. ++$cap ) . ")"; } } $cap++; $re .= "[$word])"; } elsif( $common == 1 ) { $re .= "\n\t(?=.*[$word].*)" } } $hints_uniq = join '', uniq split'', $hints_uniq; my $re_covered = qr[^[$hints_uniq]+$]; $re = qr[^$re]x; $re_ex = qr[$re_ex]x; my %w; open W, '<', 'words' or die $!; m[^[a-z]+$] and push @{ $w{ length() } }, $_ while chomp( $_ = <W>||'' ); close W; my @m = grep{ $_ =~ $re_covered and $_ =~ $re_ex and $_ =~ $re } @{ $ +w{ $len } }; print ~~@m; print for @m;

Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.


Comment on Re^2: Challenge: Mystery Word Puzzle
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://421820]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (19)
As of 2014-10-20 18:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (85 votes), past polls