Assume that you started to store items in progressively expanding square location, like this for the first 9 numbers:

```
05 04 03
06 01 02
07 08 09
```

And like this for the expanding to include up to the first 25 numbers:

```
17 16 15 14 13
18 05 04 03 12
19 06 01 02 11
20 07 08 09 10
21 22 23 24 25
```

You might easily notice that the first - and innermost - layer containes only one number (`01`), the second one  - immediately around it - contains 8 numbers (number in the `02-09` range) and so on.

Your task is to create a function that given a number `n` simply returns the number of layers required to store up to `n` (included).

```python
layers(1) == 1
layers(5) == 2
layers(25) == 3
layers(30) == 4
layers(50) == 5
```

**Fair warning:** you will always and only get positive integers, but be ready for bigger numbers in the tests!

If you had fun with this, also try some follow up kata: [progressive spiral number branch](https://www.codewars.com/kata/progressive-spiral-number-branch/) and [progressive spiral number distance](https://www.codewars.com/kata/progressive-spiral-number-distance/).

*[Base idea taken from [here](http://adventofcode.com/2017/day/3)]*

Source: codewars | Difficulty: EASY
Tags: Number theory

Fundamentals

Mathematics

Starter code: def layers(n):
	

Solutions:
from math import ceil, sqrt

def layers(n):
	return ceil(sqrt(n)) // 2 + 1


def layers(n):
	return (1 + (n - 1) ** 0.5) // 2 + 1


def layers(n):
	i = 1
	r = 1
	while i * i < n:
		i += 2
		r += 1
	return r


import math

def layers(n):
	return math.ceil((n ** 0.5 + 1.0) * 0.5)


from math import ceil

def layers(n):
	return ceil((n ** 0.5 + 1) / 2)


from itertools import count

def layers(n):
	for i in count(1):
		if n <= (2 * i - 1) ** 2:
			return i


from math import ceil

def layers(n):
	r = ceil(n ** 0.5)
	return (r + (1 if r % 2 else 2)) // 2


from math import ceil
layers = lambda n: ceil(n ** 0.5) // 2 + 1


def layers(n):
	(level, i) = (1, 1)
	continuer = True
	while continuer:
		x = i * i
		if x < n:
			level += 1
			i += 2
		elif n <= x:
			return level