Skip to content

Instantly share code, notes, and snippets.

@m3g4p0p
Created December 6, 2020 18:50
Show Gist options
  • Save m3g4p0p/ccf07044835e30a0a5b3d06db6ddd368 to your computer and use it in GitHub Desktop.
Save m3g4p0p/ccf07044835e30a0a5b3d06db6ddd368 to your computer and use it in GitHub Desktop.
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