tushman.io

The musings of an insecure technologist

Shuffling Team Seating

I think it is good to shuffle the team around. Helps with cross-pollination, and keeps the team area neat. Here is the function that we use to randomize our team making sure that you do not sit next to someone you are already sitting next to.

Note: Only works with teams greater than four. Assign each space in your office an number, the run the following. The first person in the outputted array goes in space 1, and so on.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import random

def all_perms(elements):
    if len(elements) <=1:
        yield elements
    else:
        for perm in all_perms(elements[1:]):
            for i in range(len(elements)):
                #nb elements[0:1] works in both string and list contexts
                yield perm[:i] + elements[0:1] + perm[i:]


def find_position(key,lizt):
    return [i for i,x in enumerate(lizt) if x == key][0]

def new_neighbors(some_list):
    new_neighbor_list = some_list[:]
    list_size = len(some_list)
    for new_neighbor_list in all_perms(some_list):
        print new_neighbor_list
        too_many_neighbors = False
        for i,team_member in enumerate(new_neighbor_list):
            #find position in inital list
            position_in_original_list = find_position(team_member,some_list)
            original_neighbors = []
            original_neighbors.append(some_list[(position_in_original_list+1) % list_size])
            original_neighbors.append(some_list[(position_in_original_list-1) % list_size])

            new_neighbors = []
            new_neighbors.append(new_neighbor_list[(i+1) % list_size])
            new_neighbors.append(new_neighbor_list[(i-1) % list_size])

            delta = len(set(new_neighbors) - set(original_neighbors))
            #print "for {} comparing: {} with {} = {}".format(team_member,original_neighbors,new_neighbors,delta)

            if not delta == 2:
               too_many_neighbors = True
               break

        if too_many_neighbors == False:
            return new_neighbor_list
    else:
        print "No Matches"

    return []


# Usage      
team = ['JT','FS','MC','MA','FD']
new_seating = new_neighbors(team)
print new_seating
# >> ['MC', 'JT', 'MA', 'PS', 'FD']

To end with an quote to motivate:

Everyday I’m shufflin’ — LMFAO

(you can play that music as you are shuffling’ seats)

Comments