Last active
December 9, 2022 20:03
-
-
Save jpancoast/616c5d33384d5412919340a9591bea51 to your computer and use it in GitHub Desktop.
1089 3 digit number math trick in python
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
#!/usr/bin/env python | |
''' | |
Note: | |
must be three digit numbers. | |
no digits can repeat (so no 989, 889, etc.) | |
''' | |
import sys | |
def main(argv): | |
for i in range(100,999): | |
first_dig = int(str(i)[0]) | |
second_dig = int(str(i)[1]) | |
third_dig = int(str(i)[2]) | |
if first_dig != second_dig and second_dig != third_dig and first_dig != third_dig: | |
x = abs(i - int(str(i)[::-1])) | |
z = int(str(x)[::-1]) | |
if z < 100: | |
z = int(str(z) + '0') | |
y = x+z | |
print("i: " + str(i)) | |
print("x: " + str(x)) | |
print("z: " + str(z)) | |
print("y: " + str(y)) | |
print() | |
if __name__ == "__main__": | |
main(sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment