``````

In [2]:

board = range(36)

``````

## Computing Two Dominoes

``````

In [3]:

placements = []
for i in board:
if i%6 <> 5:
for j in range(i+2,36):
if j%6 != 5:
placements.append( ((i,i+1), (j,j+1) ))
if j/6 < 5:
placements.append( ((i,i+1), (j,j+6) ))
if i/6 < 5:
for j in range(i+1,36):
if j%6 != 5 and j != i+6 and j+1 != i+6:
placements.append( ((i,i+6),(j,j+1) ))
if j/6 < 5 and j != i + 6:
placements.append( ((i,i+6), (j,j+6)) )

``````
``````

In [5]:

d = {}
for p1,p2 in placements:
if p1 in d:
d[p1].append(p2)
else:
d[p1] = [p2]
if p2 in d:
d[p2].append(p1)
else:
d[p2] = [p1]

``````
``````

In [6]:

sum([len(d[k]) for k in d]) / 2

``````
``````

Out[6]:

1622

``````
``````

In [39]:

(24*53 + 8*56 + 12*55)/2

``````
``````

Out[39]:

1190

``````
``````

In [45]:

[[k[0],k[1],len(d[k])] for k in d]

``````
``````

Out[45]:

[[7, 8, 53],
[15, 21, 53],
[10, 11, 54],
[24, 30, 56],
[28, 29, 54],
[2, 8, 54],
[29, 35, 56],
[8, 9, 53],
[20, 26, 53],
[18, 19, 54],
[16, 22, 53],
[14, 20, 53],
[22, 23, 54],
[31, 32, 55],
[16, 17, 54],
[8, 14, 53],
[27, 33, 54],
[6, 7, 54],
[9, 15, 53],
[12, 13, 54],
[26, 32, 54],
[25, 31, 54],
[25, 26, 53],
[15, 16, 53],
[19, 25, 53],
[33, 34, 55],
[17, 23, 55],
[22, 28, 53],
[27, 28, 53],
[21, 27, 53],
[32, 33, 55],
[4, 10, 54],
[1, 2, 55],
[21, 22, 53],
[5, 11, 56],
[4, 5, 56],
[18, 24, 55],
[23, 29, 55],
[9, 10, 53],
[12, 18, 55],
[3, 9, 54],
[2, 3, 55],
[13, 19, 53],
[6, 12, 55],
[19, 20, 53],
[0, 1, 56],
[11, 17, 55],
[26, 27, 53],
[28, 34, 54],
[13, 14, 53],
[10, 16, 53],
[7, 13, 53],
[0, 6, 56],
[24, 25, 54],
[20, 21, 53],
[30, 31, 56],
[1, 7, 54],
[14, 15, 53],
[3, 4, 55],
[34, 35, 56]]

``````

## Compute 3 dominoes

``````

In [ ]:

placements_3_dominoes = []
for i in board:
tmp = []
if i%6 <> 5:
tmp.append( (i,i+1) )
for j in range(i+2,36):
if j%6 != 5 and j != i+6 and j+1 != i+6:
tmp.append( (j,j+1) )
if j/6 < 5 and j != i + 6:
tmp.append( ((i,i+1), (j,j+6) ))
for k in range(j+1,36):
if k%6 != 5  and k != i+6 and k+1 != i+6 and k != j+6 and k != j+6:
tmp.append( (k,k+1) )
if k/6 < 5 and :
tmp.append( (j,j+6) )

if i/6 < 5:
tmp.append( (i,i+6) )
for j in range(i+1,36):
if j%6 != 5 and j != i+6:
tmp.append( (j,j+1) )
if j/6 < 5 and j != i + 6:
tmp.append( (j,j+6) )
for k in range(j+1,36):
if k%6 != 5 and k != i+6 and k!= j+6

``````

# Compute Recursively

``````

In [8]:

horizontal_domino_placements = [ {'end_a':x,'end_b':x+1, 'orientation':'horizontal'} for x in range(35) if x%6 != 5]
vertical_domino_placements = [ {'end_a':x,'end_b':x+6,'orientation':'vertical'} for x in range(30)]
domino_placements = horizontal_domino_placements + vertical_domino_placements
grouped_domino_placements = {}
for d in domino_placements:
if d['end_a'] in grouped_domino_placements:
grouped_domino_placements[d['end_a']].append(d)
else:
grouped_domino_placements[d['end_a']] = [d]

empty_spaces = [True]*36
def recursivelyPopulateBoard(numDominos,cur_end_a_position):
global domino_placements
if numCars == 0
yield piecePlacementsInUseStack

if numCars > 0:
#attempt to successively place both cars with end_a at current position on board and recurse
for domino in grouped_domino_placements[cur_end_a_position]:
if empty_board_spaces[domino['end_a']] and empty_board_spaces[domino['end_b']]
for groupedCars in grouped_by_end_a_car_placements[cur_end_a_position:]:
for car in groupedCars:
# NOTE: If unable to place a car on the board, then this call falls through to a return
#       This somehow kills the chain of recursive generator calls which prevents us from
#       ending up wiht a board only partially populated with the initial car/truck counts.
if empty_board_spaces[car['end_a']] and empty_board_spaces[car['end_b']]:
for gen in recursivelyPopulateBoard(numCars -1 , numTrucks, car['end_a'] + 1):
yield gen
remove_car_from_board(car)

``````
``````

In [ ]:

``````