*This kata is based on [Project Euler Problem 539](https://projecteuler.net/problem=539)*

##Object

Find the last number between 1 and `n` (inclusive) that survives the elimination process

####How It Works

Start with the first number on the left then remove every other number moving right until you reach the the end, then from the numbers remaining start with the first number on the right and remove every other number moving left, repeat the process alternating between left and right until only one number remains which you return as the "last man standing"


##Example

    given an input of `9` our set of numbers is `1 2 3 4 5 6 7 8 9`

    start by removing from the left    2   4   6   8
                                     1   3   5   7   9
    

    then from the right                2       6
                                           4       8


    then the left again                        6
                                       2


    until we end with `6` as the last man standing


**Note:** due to the randomness of the tests it is possible that you will get unlucky and a few of the tests will be really large, so try submitting 2 or 3 times.

As allways any feedback would be much appreciated

Source: codewars | Difficulty: EASY
Tags: Data structures

Mathematics

Starter code: def last_man_standing(n):
	

Solutions:
def last_man_standing(n):
	(dir, lst) = (-1, range(2, n + 1, 2))
	while len(lst) != 1:
		lst = lst[len(lst) % 2 or dir == 1::2]
		dir = -dir
	return lst[0]


from math import log

def last_man_standing(n):
	return 1 + sum(((n >> i | i + 1) % 2 << i for i in range(int(log(n, 2)))))


def last_man_standing(n):
	arr = list(range(1, n + 1))
	while len(arr) > 1:
		odd = []
		for (i, j) in enumerate(arr):
			if i % 2 == 0:
				continue
			odd.append(j)
		arr = odd[::-1]
	return arr[0]


def last_man_standing(n):
	l = range(1, n + 1)
	while len(l) > 1:
		l = l[1::2][::-1]
	return l[0]


def last_man_standing(n):
	r = range(1, n + 1)
	while len(r) > 1:
		r = r[1::2][::-1]
	return r[0]


last_man_standing = l = lambda n: n == 1 or 2 * (n < 4) or 4 * l(n // 4) - 2 * (n % 4 < 2)


last_man_standing = l = lambda n, left=True: n == 1 or 2 * l(n // 2, not left) - (not (n % 2 or left))


def last_man_standing(n):
	l = []
	l.extend(range(1, n + 1))

	def doer(t):
		w = []
		return t[1::2]
	while len(l) > 1:
		l = doer(l)
		l.reverse()
	return l[0]