Created
December 6, 2020 18:50
-
-
Save m3g4p0p/ccf07044835e30a0a5b3d06db6ddd368 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from itertools import product | |
class Hint: | |
def __init__( | |
self, | |
digits, | |
wrongly_placed=0, | |
well_placed=0 | |
): | |
self.digits = digits | |
self.wrongly_placed = wrongly_placed | |
self.well_placed = well_placed | |
def test(self, digits): | |
wrongly_placed = 0 | |
well_placed = 0 | |
for index, digit in enumerate(digits): | |
if digit == self.digits[index]: | |
well_placed += 1 | |
elif digit in self.digits: | |
wrongly_placed += 1 | |
return ( | |
wrongly_placed == self.wrongly_placed | |
and well_placed == self.well_placed | |
) | |
hints = ( | |
Hint((6, 8, 2), well_placed=1), | |
Hint((6, 1, 4), wrongly_placed=1), | |
Hint((2, 0, 6), wrongly_placed=2), | |
Hint((7, 3, 8)), | |
Hint((7, 8, 0), wrongly_placed=1), | |
) | |
for digits in product(range(0, 10), repeat=3): | |
if all(hint.test(digits) for hint in hints): | |
print(digits) | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment