There are two parts to this.

1) Find all unique sets of letters given an input of letters and wildcards
2) Calculate the number of words for each unique set

The maximum possible number of letter sets is 26**wildcards, which means that you can comfortably fit all the letter sets in memory up to 4 wildcards. Scrabble only has 2 blanks, so this isn't a problem. Calculating the number of words possible from each set is a simple factorial / letter count operation. The following is a rough but workable solution, which you can edit as necessary for various letter / wildcard combinations.

use strict; use warnings; my $letters = 'ABCDEF??'; my $length = length($letters); ## We'll be using factorials a lot, so it's best to pre-calculate my @factorial = (0,1); $factorial[$_] = $factorial[$_-1] * $_ for 2..$length; my ($blanks, @lsets, $lset, $nlset, $words, $twords); ## Find the number of blanks while ($letters =~ /[^A-Z]/) { $letters =~ s/[^A-Z]//; $blanks++; } ## Produce unique letter sets, given blanks @lsets = ($letters); while ($blanks--) { my %lsets; for $lset (@lsets) { for ('A'..'Z') { $nlset = join '', sort split //, $lset.$_; $lsets{$nlset} = (); } } @lsets = keys %lsets; } ## Calculate the number of words possible from each letter set for (@lsets) { $words = $factorial[$length]; my %lcount; $lcount{$_}++ for split //, $_; for (keys %lcount) { $words /= $factorial[$lcount{$_}] if $lcount{$_} > 1; } $twords += $words; } print $twords;

In reply to Re: Scrabble word arrangements with blank tiles by TedPride
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.