Last active
December 22, 2015 12:29
-
-
Save thejsj/6472637 to your computer and use it in GitHub Desktop.
Given any random number (even in this case), find the two closest integers divisible by 2, or the two integers closes to the square root divisible by 2
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
import math | |
import random | |
def calc(num): | |
resultFound = False | |
for i in range(1,100): | |
ii = math.pow(2, i) | |
s = math.sqrt(num) | |
r = int(round(s / ii) * ii) | |
if r > 0: | |
rr = int(num / r) | |
if r % 2 is 0 and rr % 2 == 0: | |
return r, rr | |
resultFound = True | |
break | |
if not resultFound: | |
return False | |
for i in range(100): | |
print calc(random.randrange(16,160,16)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment