Last active
July 6, 2018 00:28
-
-
Save P1n3appl3/a83ba10fccafd1d5edec42b9ab8d6143 to your computer and use it in GitHub Desktop.
Run it without reading it and see if you can solve the relation between the numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run with python 2 and try to guess the relationsihp between the numbers | |
def stringify(num): | |
result = "" | |
if num == 0: | |
return "zero" | |
if num < 0: | |
result += "negative " | |
num = -num | |
english = ("", "one", "two", "three", "four", "five", "six", "seven", | |
"eight", "nine") | |
teens = ("", "eleven", "twelve", "thirteen", "fourteen", "fifteen", | |
"sixteen", "seventeen", "eighteen", "nineteen") | |
tens = ("", "ten", "twenty", "thirty", "forty", "fifty", "sixty", | |
"seventy", "eighty", "ninety") | |
if num >= 1000: | |
if 11000 <= num < 20000: | |
result += teens[num // 1000 - 10] | |
else: | |
if num >= 10000: | |
result += tens[num // 10000] + ' ' | |
result += english[num % 10000 // 1000] | |
result += " thousand " | |
num %= 1000 | |
if num >= 100: | |
result += english[num // 100] + " hundred " | |
num %= 100 | |
if 11 <= num < 20: | |
result += teens[num - 10] | |
else: | |
if num >= 10: | |
result += tens[num // 10] + ' ' | |
result += english[num % 10] | |
return result | |
def sequence(num, showChain=False): | |
times = 0 | |
while True: | |
size = len(stringify(num).replace(' ', '')) | |
if num == size: | |
if showChain: | |
print num, "is perfect!" | |
return times | |
if showChain: | |
print num, "is", size | |
num = size | |
times += 1 | |
while True: | |
sequence(int(raw_input("Give me a number: ")), True) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment