Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. def all_diff(num: int) -> bool:
  2. """Checks, if all the digits are diffirent"""
  3. ans = True
  4. number = str(num)
  5. for i in range(0, len(number) - 1):
  6. for j in range(i + 1, len(number)):
  7. if number[i] == number[j]:
  8. ans = False
  9. return ans
  10.  
  11.  
  12. def can_be(bls: int, cws: int, given: str, our: str) -> bool:
  13. """Checks. if given number can be an answer"""
  14. bulls = 0
  15. cows = 0
  16. for i in range(0, 4):
  17. if our[i] == given[i]:
  18. bulls += 1
  19. elif our[i] in given:
  20. cows += 1
  21. return (bls == bulls and cws == cows)
  22.  
  23.  
  24. with open('input.txt') as in_f, open('output.txt', 'w') as out_f:
  25. nums = set()
  26. for num in range(1000, 10000):
  27. if all_diff(num):
  28. nums.add(str(num))
  29. for line in in_f:
  30. num, bls, cws = line.split()
  31. bls = int(bls)
  32. cws = int(cws)
  33. not_ok = set()
  34. for i in nums:
  35. if not can_be(bls, cws, num, i):
  36. not_ok.add(i)
  37. nums -= not_ok
  38. print(*nums, file=out_f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement