To clarify the problem, assume we are trying to arrange 7 tiles that already have been chosen.
ABCDEFG generates 7! = 5,040 unique permutations
ABCDEF? generates 115,920 unique permutations and not 6!*26=18,720
ABCDE?? <-- This is the stumper!

The keyword is "unique" permutations.

For example, permuting ABC? where ? represents a blank tile A..Z results in 624 arrangements but only 588 are unique permutations. Duplicate arrangements like AABC AABC AACB AACB ABAC ABAC ABBC ABBC ... must be culled to get the unique set.

Algorithm-Loops has a neat permute function which I used to check racks with one blank tile.
It generates the unique permutations that I am looking for.
Here is an example for a simple rack AB?:

use strict; use Algorithm::Loops qw( NextPermute );

my @list= sort ('A'..'B'); # Find unique permutations for AB? my $cnt; my @list1;

# $l represents one blank tile cycling thru all letter values for my $l ('A'..'Z') {

@list1 = sort(@list,$l); # Very important to sort print"@list1\n"; # Show what's happening

  do {

printf"%5d. ", ++$cnt; print"@list1\n"; # Display permutations } while( NextPermute( @list1 ) ); }

print"Counted $cnt unique permutations"; print $/;

prints:

A A B 1. A A B 2. A B A 3. B A A A B B 4. A B B 5. B A B 6. B B A A B C 7. A B C 8. A C B 9. B A C 10. B C A 11. C A B 12. C B A A B D 13. A B D 14. A D B 15. B A D 16. B D A 17. D A B 18. D B A ... ... ... Counted 150 unique permutations

Any suggestions on how to code this for 2 blank tiles without getting "Out of memory" failure?


In reply to Re^3: Scrabble word arrangements with blank tiles by Anonymous Monk
in thread Scrabble word arrangements with blank tiles by Anonymous Monk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.