For those of you who have seen the popular daytime TV show Countdown, you will know that the contestants are given 9 randomly selected letters and must then find the longest word they can in 30 seconds.
Your challenge is, given a string of 9 letters, to find the longest word that is an anagram of the largest subset of input letters, this means that you don't have to use all of the letters in the input string.
Input/output can be stdin/stdout, or whatever the equivalent in your language is.
Rules
- Input will always a 9 letter string, all lower-case
- You can use as few or as many of the letters from the input string
- A word is allowed if it is found in the specified dictionary file, the dictionary file containing all the allowed words can be found here (note: I didn't compile this, credit goes to the github uploader). The file is is a .txt file which contains ~101,000 words with each word on a new line - approx 985kB.
- You must use the dictionary file specified above, this is to ensure that all fairness across all the entries, e.g. so everyone has the same chance of finding the longest word.
- You are allowed to manipulate the dictionary file in such a way that none of the words are edited in any way and no new ones are added, for example copying all the words to an array, making all words comma separated or copying the whole contents of the file to another file would be allowed.
- Inputs may contain any number of vowels and consonants, e.g. 9 vowels or 8 consonants and 1 vowel
- If there are multiple words with the same length, then you must output all of them (up to a limit of 5 - to prevent long lists of 5/6 letter words). Multiple words must be delimited, but this can be done in any way - comma, space etc.
Test Cases
Input: mhdexaspo
Output: hexapods, mopheads
Input: iesretmng
Output: regiments
Input: cmilensua
Output: masculine calumnies
Input: floiufhyp
Output: huffily puffily
Input: frtuasmjg
Output: frusta,jurats,jumars,tragus,grafts
This is code-golf, so shortest code wins!
==
to a<=
, and adds some post-processing to sort by length. I haven't voted to close as a dupe, but I did consider it. \$\endgroup\$