baseicosa = [('A', 'C', 'I'),
('A', 'L', 'B'),
('B', 'D', 'K'),
('D', 'C', 'J'),
('I', 'E', 'G'),
('G', 'J', 'H'),
('K', 'F', 'H'),
('L', 'F', 'E'),
('A', 'B', 'D'),
('A', 'C', 'D'),
('A', 'L', 'I'),
('I', 'E', 'L'),
('C', 'I', 'G'),
('C', 'G', 'J'),
('L', 'B', 'F'),
('K', 'B', 'F'),
('D', 'K', 'J'),
('H', 'K', 'J'),
('F', 'E', 'H'),
('G', 'E', 'H')]
pents = ['A','B','C','D','E','F','G','H','I','J','K','L']
print "Pents: %s" % pents
def gethexes():
thelist = []
for t in baseicosa:
thehex = ''.join(sorted(t))
thelist.append(thehex)
return thelist
hexes = gethexes()
print "Hexes: %s" % hexes
def getedges():
theset = set()
for t in baseicosa:
for i in (t[:2], t[1:], t[-1]+t[0]):
theset.add(''.join(sorted(i)))
return sorted(list(theset))
edges = getedges()
print "Edges: %s" % edges
globaldata = {}
def buildpents():
result = {}
for p in pents:
neighbors = []
for h in hexes:
if p in h:
neighbors.append(h)
result[p] = neighbors
return result
result = buildpents()
print "Pent neighbors: %s" % result
globaldata.update(result)
def buildhexes():
result = {}
for h in hexes:
neighbors = list(h)
for candidate in hexes:
votes = 0
for i in range(3):
if h[i] in candidate:
votes += 1
if votes == 2:
neighbors.append(candidate)
result[h] = neighbors
return result
result = buildhexes()
print "Hexa neighbors: %s" % result
globaldata.update(result)
# code highlighted using py2html.py version 0.8