Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Number Guess by Rounin
def checkio(attempts):
possibilities = set(range(1, 101))
for attempt in attempts:
for possibility in possibilities.copy():
if possibility % attempt[1] != attempt[0]:
possibilities.remove(possibility)
return [min(filter(lambda divisor: divisor not in map(lambda attempt: attempt[1], attempts), range(2, 11))), list(possibilities)[0]]
if __name__ == '__main__':
#This part is using only for self-checking and not necessary for auto-testing
MAX_ATTEMPT = 8
def initial_referee(data):
data["attempt_count"] = 0
data["guess"] = 0
return data
def check_solution(func, goal, initial):
prev_steps = [initial]
for attempt in range(MAX_ATTEMPT):
divisor, guess = func(prev_steps[:])
if guess == goal:
return True
if divisor <= 1 or divisor > 10:
print("You gave wrong divisor range.")
return False
if guess < 1 or guess > 100:
print("You gave wrong guess number range.")
return False
prev_steps.append((goal % divisor, divisor))
print("Too many attempts.")
return False
assert check_solution(checkio, 47, (2, 5)), "1st example"
assert check_solution(checkio, 94, (3, 7)), "2nd example"
assert check_solution(checkio, 52, (0, 2)), "3rd example"
Aug. 5, 2017