Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
One line solution in Uncategorized category for The Good Radix by PositronicLlama
def checkio(number):
"""
Given a number in an unknown radix, return radix k such that (k-1) | number.
Return 0 if such a radix does not exist.
"""
return next((k for k in range(max(2, 1 + int(max(number), 36)), 37) if not int(number, k) % (k-1)), 0)
if __name__ == '__main__':
assert checkio("18") == 10, "Simple decimal"
assert checkio("1010101011") == 2, "Any number is divisible by 1"
assert checkio("222") == 3, "3rd test"
assert checkio("A23B") == 14, "It's not a hex"
Aug. 26, 2013
Comments: