Created
December 24, 2014 06:02
-
-
Save danlamanna/565f414e364ae803ebb8 to your computer and use it in GitHub Desktop.
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
| n = 12427281805225 # 3525235 | |
| # brute force, ~.5s | |
| for i in xrange(1, n): | |
| if i**2 == n: | |
| print i | |
| break | |
| # binary search.. ~.06s | |
| def find_sq_root(n, lower=1, upper=n): | |
| m = (lower + upper) / 2 | |
| if m**2 == n: | |
| return m | |
| if m**2 > n: | |
| return find_sq_root(n, lower, m) | |
| else: | |
| return find_sq_root(n, m, upper) | |
| print find_sq_root(n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment