Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def all_diff(num: int) -> bool:
- """Checks, if all the digits are diffirent"""
- ans = True
- number = str(num)
- for i in range(0, len(number) - 1):
- for j in range(i + 1, len(number)):
- if number[i] == number[j]:
- ans = False
- return ans
- def can_be(bls: int, cws: int, given: str, our: str) -> bool:
- """Checks. if given number can be an answer"""
- bulls = 0
- cows = 0
- for i in range(0, 4):
- if our[i] == given[i]:
- bulls += 1
- elif our[i] in given:
- cows += 1
- return (bls == bulls and cws == cows)
- with open('input.txt') as in_f, open('output.txt', 'w') as out_f:
- nums = set()
- for num in range(1000, 10000):
- if all_diff(num):
- nums.add(str(num))
- for line in in_f:
- num, bls, cws = line.split()
- bls = int(bls)
- cws = int(cws)
- not_ok = set()
- for i in nums:
- if not can_be(bls, cws, num, i):
- not_ok.add(i)
- nums -= not_ok
- print(*nums, file=out_f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement