Update: My first algorithm was wrong. The actual number of cards is 35. It is only 105, when the numbering of the conncetion points is of interest. So here is the augmented algorithm, which outputs the 35 unique cards. The game comes with two of every card, except for 6 highly symmetric cards, which are unique in the game.
def makeCards(cards, card, connectionSet):
if connectionSet == set([]):
for i in range(1,4):
c = shiftCard(card, i)
try:
cards.index(c)
return cards
except ValueError:
pass
return cards + [card]
start = connectionSet.pop()
for i in connectionSet:
newConnection = sorted([start, i])
cards = makeCards(cards, sorted(card + [newConnection]), connectionSet - set([i]))
return cards
def shiftCard(card, i):
newCard = []
for c in card:
conn = sorted([(c[0] + 2 * i) % 8, (c[1] + 2 * i) % 8])
newCard = sorted(newCard + [conn])
return newCard
mycards = makeCards([], [], set([0,1,2,3,4,5,6,7]))
print mycards
print len(mycards)
No comments:
Post a Comment