Jack and Jill are playing a game. They have balls numbered from `0` to `n - 1`. Jack looks the other way and asks Jill to reverse the position of the balls, for instance, to change the order from say, `0,1,2,3` to `3,2,1,0`. He further asks Jill to reverse the position of the balls `n` times, each time starting from one position further to the right, till she reaches the last ball. So, Jill has to reverse the positions of the ball starting from position `0`, then from position `1`, then from position `2` and so on. At the end of the game, Jill will ask Jack to guess the final position of any ball numbered `k`. 

You will be given `2` integers, the first will be `n`(balls numbered from `0` to `n-1`) and the second will be `k`. You will return the position of the ball numbered `k` after the rearrangement.

```Perl
solve(4,1) = 3. The reversals are [0,1,2,3] -> [3,2,1,0] -> [3,0,1,2] -> [3,0,2,1]. => 1 is in position 3.
```

More examples in the test cases. Good luck!

Source: codewars | Difficulty: EASY
Tags: Mathematics

Ad-hoc

Starter code: def solve(n,k):
	

Solutions:
def solve(count, ball_number):
	assert isinstance(count, int)
	assert isinstance(ball_number, int)
	balls = list(range(count))
	for idx in range(count):
		balls = balls[:idx] + balls[idx:][::-1]
	return balls.index(ball_number)


solve = lambda n, k: 2 * (n - k - 1, k + 0.5)[k < n // 2]


def solve(n, k):
	res = list(range(n))
	for i in range(n):
		res = res[:i] + res[i:][::-1]
	return res.index(k)


def solve(n, k):
	second_half = k >= n // 2
	return (-1) ** second_half * 2 * k + second_half * (n * 2 - 3) + 1


def solve(n, k):
	arr = []
	for i in range(n % 2 + n // 2):
		arr += [n - i - 1] + [i]
	return arr.index(k)


def solve(n, k):
	a = list()
	for i in range(int(n / 2) + 1):
		a += [n - 1 - i, i]
	return a.index(k)


def solve(n, k):
	return 2 * k + 1 if k <= n // 2 - 1 else 2 * (n - k - 1)


def solve(n, k):
	list1 = list(range(n))
	list1_values = list(list1)
	ball = list1[k]
	counter = 0
	final_list = []
	for i in range(n):
		list1.reverse()
		final_list.append(list1.pop(0))
	position = final_list.index(ball)
	return position


def solve(n, k):
	result = {}
	(index, start, end) = (0, 0, n - 1)
	while start <= end:
		result[end] = index
		index += 1
		if start != end:
			result[start] = index
		index += 1
		start += 1
		end -= 1
	return result[k]