My entry into the pot works by starting with the smallest words and building to the largest, instead of the other way. On the word list from ITA, the answers are 16 letters long (Underestimations and indeterminations).
#!perl use strict; use Data::Dumper; $|++; my %WordTree = (); my %WordLengths = (); my $LongWordLength = 1; open (DATA, "Word.txt"); while (<DATA>) { chomp; my $Word = $_; my $Length = length($_); next if $Length < 3; $LongWordLength = $Length if ($LongWordLength < $Length); push (@{$WordLengths{$Length}}, $Word); } print "Finished reading Data\n"; close (DATA); for (my $CurrentLength = 3; $CurrentLength <= $LongWordLength; $Curren +tLength++) { print "Working on words of length $CurrentLength\n"; my ($Word) = ""; foreach $Word (@{$WordLengths{$CurrentLength}}) { my (@SortedLetters) = sort split //, $Word; if ($CurrentLength > 3) { my $TempWord = ""; my @SplicedLetters = ""; my $MatchFlag = 0; for (my $Splice = 0; $Splice <= $#SortedLetters; $Splice++ +) { @SplicedLetters = @SortedLetters; splice(@SplicedLetters, $Splice, 1); $TempWord = join '', @SplicedLetters; if (exists($WordTree{$#SortedLetters}->{$TempWord})) { if (! exists($WordTree{$CurrentLength}->{join '', +@SortedLetters})) { push (@{$WordTree{$CurrentLength}->{join '', @ +SortedLetters}}, $Word); push (@{$WordTree{$CurrentLength}->{join '', @ +SortedLetters}}, @{$WordTree{$CurrentLength - 1}->{join ' +', @SplicedLetters}}); } last; } } } else { if (! exists($WordTree{3}->{join '', @SortedLetters})) { push (@{$WordTree{3}->{join '', @SortedLetters}}, $Wor +d); } } } } my (@LongestMatch) = sort {$a<=>$b} keys %WordTree; my $NotFoundLongest = 1; while ($NotFoundLongest && $#LongestMatch > 1) { if (keys %{$WordTree{$LongestMatch[$#LongestMatch]}} > 0) { print "The longest length is $LongestMatch[$#LongestMatch]\n"; print Dumper $WordTree{pop @LongestMatch}; $NotFoundLongest = 0; } pop @LongestMatch; }

In reply to Re: Add-A-Gram Performance by dfog
in thread Add-A-Gram Performance by smgfc

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.