Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Sets solution in Clear category for Number Guess by HonzaKral
POSSIBLE_DIVS = set(range(2, 11))
POSSIBLE_GUESSES = set(range(1, 101))
def checkio(attempts):
# start with everything being a possibility
guesses = POSSIBLE_GUESSES
for rem, div in attempts:
# remove all invalid guesses
guesses -= guesses - set(range(rem, 101, div))
# get a divisor we haven't used yet
divs = POSSIBLE_DIVS - set(div for _, div in attempts)
return divs.pop(), guesses.pop()
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
checkio([(1, 5)]) # the number has a remainder 1
checkio([(1, 5), (1, 2)]) # the number has a remainder 1
checkio([(1, 5), (1, 2), (2, 3)]) # the number has a remainder 2
checkio([(1, 5), (1, 2), (2, 3), (5, 6)]) # the number has a remainder 5
checkio([(1, 5), (1, 2), (2, 3), (5, 6), (3, 4)]) # the number has a remainder 3
Dec. 22, 2013
Comments: