# here is a topological icosahedron, expressed as openings (faces) # Note: I recycled this from my rbf.py but changed the letters to # something friendlier 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')] # we will consider these the names of 12 pentagons then add a # 'soccer ball' pattern of 20 hexagons, named for the pentagons # at their 3 alternate edges, e.g. hexagon ACI. # Every hexagon will have six neighbors: three pentagons with # one letter in common, three hexagons with two letters is common # Every pentagon with have five neighbors: five hexagons with # one letter in common. pents = ['A','B','C','D','E','F','G','H','I','J','K','L'] # 20 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 # and let's get the edges while we're at it. Every edge of every # triangle is an edge. We'll use the set data structure to police # against duplicates 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 # now we'd like a global dictionary in which every pentagon is paired # with its 5 neighbors. These will simply be all hexagons with # a letter in common. 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) # adding to our globaldata, will be all the hexagons paired with # their six neighbors: 3 pentagons, and 3 hexagons across an edge. # We detect edge sharing as a boundary condition, i.e. if a panel # has two (and only two) letters in common, it's across an edge def buildhexes(): result = {} for h in hexes: neighbors = list(h) # 3 pentagons 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)