There's a waiting room with N chairs set in single row. Chairs are consecutively numbered from 1 to N. First is closest to the entrance (which is exit as well).
 
For some reason people choose a chair in the following way

1. Find a place as far from other people as possible
2. Find a place as close to exit as possible

All chairs must be occupied before the first person will be served

So it looks like this for 10 chairs and 10 patients




Chairs
1
2
3
4
5
6
7
8
9
10




Patients
1
7
5
8
3
9
4
6
10
2




Your task is to find last patient's chair's number. 

Input - N - integer greater than 2 - number of chairs.
Output should positive integer too - last patient's chair's number

Have fun :)

Difficulty: introductory

Starter code:

def last_chair(n):
	

Solutions:
def last_chair(n):
    return n - 1

def last_chair(n):
    # Propn:
    #   Given there are n seats, n >= 2. The (n-1)th seat is always the
    #   last to be taken (taken in iteration n).
    # Proof:
    #   Suppose that, for some n >= 2, the (n-1)th seat is taken on
    #   iteration i > 2. The nth seat is already taken, since the 2nd
    #   iteration will always claim it. Therefore i must sit beside
    #   at least one person (the occupant of seat n).
    #   Additionally, the (n-2)th seat must also already be taken.
    #   If it were not taken, (n-2) would have a free seat at (n-1)
    #   and would be closer to the exit, and so would rank higher
    #   than (n-1) in the choice algorithm.
    #   Therefore (n-1) will only be chosen when (n-2) and (n) are
    #   both taken.
    #   Also, all other seats must also be taken, since
    #   otherwise i would taken them, having at most as many people
    #   around as seat (n-1) and being closer to the exit.
    #   Therefore (n-1) is the last seat to be taken.
    return n - 1

last_chair = lambda n: n - 1

def last_chair(n):
    return n if n<3 else n-1

def last_chair(n):
    if n < 3:
        return n
    return n - 1

def last_chair(n):
    # Last chair will allways be the 2nd to the last chair
    return n - 1  

def last_chair(n):
    if n == 1 or n == 2:
        return n
    else:
        return n - 1

def last_chair(n):
    # The secret is, that it's always the next to last seat!
    return n-1
    
    # Actual simulation for fun :)
    # dist to e, used, nearest l, nearest r, nearest, spaces
    spots = [[i, False, None, None, None, None] for i in range(n)]

    clean = lambda n, d=0: n if n is not None else d
    live = lambda s: not s[1]
    position = lambda s: s[0]
    near = lambda s: s[4]
    spaces = lambda s: s[5]

    while any(filter(live, spots)):
        nearest = None
        for i in range(n):
            if spots[i][1]:
                nearest = 0
            elif nearest is not None:
                nearest += 1
            spots[i][2] = nearest

        nearest = None
        for i in range(n-1, -1, -1):
            if spots[i][1]:
                nearest = 0
            elif nearest is not None:
                nearest += 1
            spots[i][3] = nearest

        for i in range(n):
            spots[i][4] = min(clean(spots[i][2], n), clean(spots[i][3], n))
            spots[i][5] = clean(spots[i][2]) + clean(spots[i][3])

        options = list(filter(live, spots))
        options.sort(key=near, reverse=True)
        best = near(options[0])
        options = [s for s in options if near(s) == best]
        #print "Options"
        #for s in options:
        #    print s
        options.sort(key=spaces, reverse=True)
        best = spaces(options[0])
        options = [s for s in options if spaces(s) == best]
        options.sort(key=position)
        options[0][1] = True
        result = position(options[0])
    return result + 1


last_chair = 1 .__rsub__