import itertools from collections import Counter import nltk 必要な辞書を初回のみDL…
- User
import itertools from collections import Counter import nltk
必要な辞書を初回のみDL
nltk.download('words') from nltk.corpus import words
元の文字セット
original_letters = "scratch" original_counter = Counter(original_letters)
英単語リストを取得(小文字&最大7文字までの単語)
word_list = [w.lower() for w in words.words() if set(w.lower()) <= set(original_letters) and len(w) <= len(original_letters)]
フィルター:その単語が original_letters から作れるかチェック
def can_form(word, available): return not (Counter(word) - available)
valid_words = [w for w in word_list if can_form(w, original_counter)]
多単語で全文字使い切る組合せを探索
def find_full_combinations(words, original_counter): results = []
# 最大5単語まで試す(必要なら調整可) for r in range(2, 6): for combo in itertools.combinations(words, r): total = Counter() for word in combo: total += Counter(word) if total == original_counter: results.append(combo) return resultsresults = find_full_combinations(valid_words, original_counter)
結果出力
if results: print("Found combinations that use all letters in 'scratch':\n") for combo in results: print(" + ".join(combo)) else: print("No exact combinations found.") ーーー これだと一文字の単語もでてくる
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.