class Program { static void Main() { // Read all words from the input.txt file and store them in a hash set for quick lookup var words = new List(File.ReadAllLines("input.txt")); var wordSet = new HashSet(words); // Find all combinations that form a 6-letter word var filteredWords = words.Where(w => w.Length <= 6).ToList(); var combos = new HashSet(); Parallel.ForEach(filteredWords, word => { FindCombinations(word, filteredWords, new List { word }, word.Length, wordSet, combos); }); // Print out all found combinations foreach (var combo in combos) { Console.WriteLine(combo); } } static void FindCombinations(string currentWord, List words, List currentCombination, int currentLength, HashSet wordSet, HashSet combos) { // Check if the current combination forms a valid 6-letter word if (currentLength == 6) { string combinedWord = string.Join("", currentCombination); if (wordSet.Contains(combinedWord)) { string result = $"{string.Join("+", currentCombination)}={combinedWord}"; lock (combos) // Ensure thread-safe access to combos { if (combos.Add(result)) // Add to the set and check for uniqueness { Console.WriteLine(result); // Echo out the found combination } } } return; } // Try adding each word to the current combination foreach (var word in words) { // Skip if adding the word would exceed 6 characters if (currentLength + word.Length > 6) { continue; } // Avoid duplicate combinations if (currentCombination.Contains(word)) { continue; } // Add the word to the current combination and recurse var newCombination = new List(currentCombination) { word }; FindCombinations(currentWord, words, newCombination, currentLength + word.Length, wordSet, combos); } } }