Last active
December 29, 2015 05:39
-
-
Save johnholbrook/7623439 to your computer and use it in GitHub Desktop.
compares number of length n to the first n digits of sqrt(n). if they are identical, adds n to a list.
This file contains hidden or 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
| print "importing" | |
| from math import sqrt | |
| print "done importing" | |
| def compare(num, root): | |
| length = len(str(num)) | |
| print length | |
| part = root[:length] | |
| if part == num: | |
| return True | |
| else: | |
| return False | |
| numbers = [] | |
| highest = raw_input("How high?") | |
| current = 1 | |
| while current <= highest: | |
| result = compare(current, sqrt(current)) | |
| if result == True: | |
| numbers.append(current) | |
| current += 1 | |
| print "I found " + len(str(numbers)) + " such numbers below " + str(highest) | |
| print numbers[0:] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment