Skip to content

Instantly share code, notes, and snippets.

@sionide21
Created December 6, 2013 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sionide21/7824149 to your computer and use it in GitHub Desktop.
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
sqrtSums :: Double -> Int
sqrtSums x = length (takeWhile (<x) (scanl1 (+) (map sqrt [1..]))) + 1
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