Saturday, July 17, 2010

solving the word cube in voltron

In response to: http://programmingpraxis.com/2010/07/13/word-cube/


/* returns array of words found in the 9 letters provided */
function solveCube($letters) {
$words = newType(TFile, 'words.txt')->splitBy("\n");

return newType(TString, $letters)
->asArray
->powerSet('contains', $letters[4])
->map('permutations', I('asString')->in($words))
->map('join');
}

echo solveCube('ncbciune');


There are a few alternative ways that could be written and I am not sure if the idea of just having an optional filter as arguments to powerSet and permutations is entirely intuitive but the reality is that w/o the filter permutations will die on anything over 8 unless you crank the memory up in php.ini and thats just filthy.

Next post I will delve into iterative permutation and powerset internals on Array as that is obviously where the meat of that solution lies.

No comments: