In [2]:
board = range(36)
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]:
In [39]:
(24*53 + 8*56 + 12*55)/2
Out[39]:
In [45]:
[[k[0],k[1],len(d[k])] for k in d]
Out[45]:
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
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']]:
add_car_to_board(car)
for gen in recursivelyPopulateBoard(numCars -1 , numTrucks, car['end_a'] + 1):
yield gen
remove_car_from_board(car)
In [ ]: