Hello,
I've been playing with idea to make a script to generate 2-characters words from a given set of characters in my language. However, as I am not into re-inventing the wheel, do you know about such a script publicly available for C#?
Hello,
I've been playing with idea to make a script to generate 2-characters words from a given set of characters in my language. However, as I am not into re-inventing the wheel, do you know about such a script publicly available for C#?
I'm not sure if I understood your question correctly, but this might help:
List<string> GetWords(IEnumberable<char> characters) {
char[] chars = characters.Distinct().ToArray();
List<string> words = new List<string>(chars.Length*chars.Length);
foreach (char i in chars)
foreach (char j in chars)
words.Add(i.ToString() + j.ToString());
return words;
}
as I am not into re-inventing the wheel,
Bruwwwhahahahah. Let me guess, you're also not into doing homework? :)
Are you talking about finding real two-character words that can be made from any combination of a list of characters?
In which case, you need to write an algorithm that can work out all the possible combinations from the letters provided, and for each combination, try it (and the reverse) against an IDictionary that acts like a real dictionary of real two-letter words.
Untested code:
IDictionary<string, string> dictionary = GetRealTwoLetterWordDictionary();
char[] availableChars = new char[] { 'a', 's', 't' };
string[] combinations = GetAllCombinations(availableChars);
IList<string> results = new List<string>();
foreach (string combination in combinations)
{
if (dictionary.ContainsKey(combination)))
{
results.Add(combination);
}
string reversed = combination.Reverse();
if (dictionary.ContainsKey(reversed)))
{
results.Add(reversed);
}
}