Advertisement
tod36

9.2.3. Bulls and cows

May 2nd, 2020
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.81 KB | None | 0 0
  1. secret_number = input()
  2. top_secret_number = secret_number
  3. numb_of_bulls = int(input())
  4. numb_of_cows = int(input())
  5. current_number = ''
  6. current_bulls = 0
  7. current_cows = 0
  8. flag_found = False
  9. for digit_1 in range(1, 10):
  10.     for digit_2 in range(1, 10):
  11.         for digit_3 in range(1, 10):
  12.             for digit_4 in range(1, 10):
  13.                 current_number = str(digit_1) + str(digit_2) + str(digit_3) + str(digit_4)
  14.                 for i in range(0, 4):
  15.                     for j in range(0, 4):
  16.                         if current_number[j] == top_secret_number[j]:
  17.                             current_bulls += 1
  18.                             symb = list(top_secret_number)
  19.                             symb[j] = '0'
  20.                             top_secret_number = "".join(symb)
  21.                             symb_cur = list(current_number)
  22.                             symb_cur[j] = 'z'
  23.                             current_number = "".join(symb_cur)
  24.                     for l in range(0, 4):
  25.                         if current_number[l] == top_secret_number[i]:
  26.                             current_cows += 1
  27.                             symb = list(top_secret_number)
  28.                             symb[i] = '0'
  29.                             top_secret_number = "".join(symb)
  30.                             symb_cur = list(current_number)
  31.                             symb_cur[l] = 'z'
  32.                             current_number = "".join(symb_cur)
  33.                  if current_bulls == numb_of_bulls and current_cows == numb_of_cows:
  34.                     flag_found = True
  35.                     print((str(digit_1) + str(digit_2) + str(digit_3) + str(digit_4)), end=' ')
  36.                 current_cows = 0
  37.                 current_bulls = 0
  38.                 top_secret_number = secret_number
  39. if not flag_found:
  40.     print('No')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement