diff --git a/wgamesolv.py b/wgamesolv.py index 4bf288b..5521825 100755 --- a/wgamesolv.py +++ b/wgamesolv.py @@ -86,8 +86,8 @@ def resolv_kl(liste, lettres): lettres = list(set(list(lettres))) MotsRestants = [] for mot in liste: - if len(set(lettres).intersection(mot)) == len(lettres): - MotsRestants.append(mot) + if len(set(lettres).intersection(mot)) == len(lettres): + MotsRestants.append(mot) return MotsRestants #if kl: @@ -103,24 +103,20 @@ def resolv_kl(liste, lettres): # if validate == len(kl): # klFilter.append(mot) -# Bad Letters : élimination des mots contenant des lettres invalidées (hors pattern) -#if bl: -# if klFilter: -# mots = klFilter -# elif patternFilter: -# mots = patternFilter -# else: -# mots = goodLen -# for mot in mots: -# invalidate = 0 -# for l in bl: -# if l in mot and l in pattern: -# if pattern.count(l) != mot.count(l): -# invalidate += 1 -# elif l in mot: -# invalidate += 1 -# if invalidate == 0: -# blFilter.append(mot) +def resolv_bl(liste, lettres): + # Bad Letters : élimination des mots contenant des lettres invalidées (hors pattern) + lettres = list(set(list(lettres))) + MotsSuppr = [] + for mot in liste: + for lettre in lettres: + if lettre in mot: + MotsSuppr.append(mot) + for mot in MotsSuppr: + try: + liste.pop(liste.index(mot)) + except: + pass + return liste if __name__ == "__main__": @@ -187,12 +183,6 @@ if __name__ == "__main__": print("Tu as merdé ta pattern petit scarabé !") exit(2) - # Known Letters - kl = args.knownLetters - - # Bad Letters - bl = args.badLetters - liste = load_dict(args.dictionary) liste = resolv_len(liste, args.nbLetters) liste = resolv_fl(liste, args.firstLetter) @@ -209,6 +199,8 @@ if __name__ == "__main__": exit(0) if args.knownLetters: liste = resolv_kl(liste, args.knownLetters) + if args.badLetters: + liste = resolv_bl(liste, args.badLetters) if len(liste) > 1: print(liste) print(f"Il y a {len(liste)} mots dans la liste")