Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Mod 9, 8, 7 solution in Uncategorized category for Number Guess by z_kro
reminders = [ [n%9,n%8,n%7] for n in range(1,101) ] # reminders by 9, 8, and 7
# 0 1 2 3
def checkio(attempts):
if len(attempts) < 4:
return [[9,8,7][len(attempts)-1],1]
else:
return [6,reminders.index([ a[0] for a in attempts[1:] ]) + 1]
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)), "1st example"
assert check_solution(checkio, 52, (0, 2)), "1st example"
March 3, 2014
Comments: