Created
December 6, 2013 13:52
-
-
Save sionide21/7824149 to your computer and use it in GitHub Desktop.
sqrtSums | sum of the square root of the first natural numbers sqrtSums < x
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
sqrtSums :: Double -> Int | |
sqrtSums x = length (takeWhile (<x) (scanl1 (+) (map sqrt [1..]))) + 1 |
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
from math import sqrt | |
def sqrtSums(x): | |
n = acc = 0 | |
while acc < x: | |
n += 1 | |
acc += sqrt(n) | |
return n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment