Write a function getNumberOfSquares that will return how many integer (starting from 1, 2...) numbers raised to power of 2 and then summed up are less than some number given as a parameter.


E.g 1: For n = 6 result should be 2 because 1^2 + 2^2 = 1 + 4 = 5 and 5 < 6
E.g 2: For n = 15 result should be 3 because 1^2 + 2^2 + 3^2 = 1 + 4 + 9 = 14 and 14 < 15

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def get_number_of_squares(n):
	

Solutions:
def get_number_of_squares(n):
	k = 1
	while k * (k + 1) * (2 * k + 1) / 6 < n:
		k += 1
	return k - 1


def get_number_of_squares(n):
	(s, i) = (0, 0)
	while s < n:
		i += 1
		s += i ** 2
	return i - 1


def get_number_of_squares(n):
	sm = 0
	i = 0
	while n > sm:
		i += 1
		sm += i ** 2
	return i - 1


get_number_of_squares = g = lambda n, i=1: i * i < n and -~g(n - i * i, i + 1)


def get_number_of_squares(limit):
	total = 1
	for n in range(2, limit + 2):
		if total >= limit:
			return n - 2
		total += n ** 2


def get_number_of_squares(n):
	(i, j, k) = (1, 1, 1)
	while k < n:
		i += 2
		j += i
		k += j
	return i >> 1


def get_number_of_squares(n):
	sum = 0
	c = 0
	for i in range(1, n + 1):
		sum += i * i
		c += 1
		if sum >= n:
			return c - 1
	return 0


def get_number_of_squares(n):
	(res, i) = (0, 0)
	while res < n:
		res += i ** 2
		i += 1
	return i - 2


def get_number_of_squares(n):
	return int((n * 3) ** (1.0 / 3.0) - 0.5)