Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
The following returns all the sets of 5 uniqe letters that agree with the rules (two and only two letters are common between the set of letters and each of the words). Note that I've also added a rule, that every set of letters must contain ONLY letters included in the input words.
use strict; use warnings; my (%l, @a, $bad, $w); my @w = ('bumps','seams','domes','shake','pokes','dukes'); for (@w) { $l{$_} = () for (split //, $_); } permute(5, '', \@a, sort keys %l); for $w (@a) { $bad = 0; for (@w) { if (both($_, $w) != 2) { $bad = 1; last; } } if (!$bad) { print "$w\n"; } } sub permute { my ($d, $w, $a, @l) = @_; if (!--$d) { push @$a, $w.$_ for @l; } else { permute($d, $w.$l[$_], $a, @l[($_+1)..$#l]) for (0..($#l-$d +)); } } sub both { my ($w1, $w2) = @_; my %l; my $c = 0; $l{$_} = () for split //, $w1; for (split //, $w2) { $l{$_} = 1 if exists $l{$_}; } for (values %l) { $c++ if $_; } return $c; }
Sloppy code in places probably, but it does the job. Returned values are:
abdep abeou adkmp akmou
Problem is, I can't see a way to arrange any of these into an english word, unless I'm missing a possibility on the first set. Obviously, some of the letters have to be used twice, or letters not in any of the original words have to be allowed. Back to the drawing board :\

EDIT: Ohhh, you changed the puzzle. Time to see if I can get this one to work...

Nope, doesn't work with the new puzzle either. I'd delete my post at this point, but I should leave it here in case someone can gain insight from my mistakes.


In reply to Re: Challenge: Mystery Word Puzzle by TedPride
in thread Challenge: Mystery Word Puzzle by Limbic~Region

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-18 01:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found