Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. rules = [
  2. ('682', 1, 0),
  3. ('614', 0, 1),
  4. ('206', 0, 2),
  5. ('738', 0, 0),
  6. ('380', 0, 1)
  7. ]
  8.  
  9. def check(guess, correct):
  10.   right_in_place = 0
  11.   right_wrong_place = 0
  12.   for i in range(3):
  13.     if guess[i] in correct:
  14.       if guess[i] == correct[i]:
  15.         right_in_place += 1
  16.       else:
  17.         right_wrong_place += 1
  18.   return right_in_place, right_wrong_place
  19.  
  20. solutions = []
  21. for n in range(1000):
  22.   trial = "{:03d}".format(n)
  23.   valid = True
  24.   for guess, right_in_place, right_wrong_place in rules:
  25.     rp, rw = check(guess, trial)
  26.     if rp != right_in_place or rw != right_wrong_place:
  27.       valid = False
  28.       break
  29.   if valid:
  30.     solutions.append(trial)
  31.  
  32. print(solutions)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement