Created
July 31, 2015 11:19
-
-
Save oskar-j/3571dc48ec9e21814f42 to your computer and use it in GitHub Desktop.
Find perfect squares in a range of (A,B) 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
import math | |
def solution(A, B): | |
bottom = int(math.ceil(math.sqrt(A))) | |
upper = int(math.floor(math.sqrt(B))) | |
# int should be enough | |
return upper - bottom + 1 | |
print solution(4, 17) # should print 3 | |
print solution(1000, 2000) # should print 13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment