Advertisement
FranzVuttke

find word random

Mar 25th, 2023 (edited)
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | Source Code | 0 0
  1. def findWord(aListChars, aWord, aTrialNum):
  2.     cnt = 1
  3.     words = []
  4.     found = False
  5.     while cnt < aTrialNum:
  6.         word = ""
  7.         buff = [e for e in aListChars]
  8.         while len(buff) > 0:
  9.             rnd = random.randrange(len(buff))
  10.             word += buff.pop(rnd)
  11.             if word == aWord:  #"chrząszcz"
  12.                 print("DBUG: Match: %s %d" % (word, cnt))
  13.                 found = True
  14.                 break
  15.         cnt += 1
  16.         if found:
  17.             break    
  18.         # DBUG    
  19.         # print(word)
  20.         # if not (word in words):
  21.         #     words.append(word)
  22.     return found
  23. l = ["z","z","s","r","c","h","c","z","ą"]
  24. w = "chrząszcz"
  25. print(find_word(l, w, 20000))
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement