Example #1
0
def getNumberOfFlips(u, v):
    node1 = getNode(u)
    node2 = getNode(v)

    count = 0 # Count the number of different cells
    for i in range(len(node1)):
      if node1[i] != node2[i]:
        count += 1

    return count
Example #2
0
def main():
    # Prompt the user to enter nine coins H's and T's
    initialNode = input("Enter an initial nine coin H's and T's: ").strip()

    # Create the NineTaileModel
    model = NineTailModel()
    path = model.getShortestPath(getIndex(initialNode))

    print("The steps to flip the coins are ")
    for i in range(len(path)):
        printNode(getNode(path[i]))
Example #3
0
def main():
    # Prompt the user to enter nine coins H's and T's
    initialNode = \
        input("Enter an initial nine coin H's and T's: ").strip()

    # Create the NineTaileModel
    model = NineTailModel()
    path = model.getShortestPath(getIndex(initialNode))

    print("The steps to flip the coins are ");
    for i in range(len(path)):
        printNode(getNode(path[i]))  
Example #4
0
def getWeightedEdges():
    # Store edges
    edges = []

    for u in range(NUMBER_OF_NODES):
      for k in range(9):
        node = getNode(u) # Get the node for vertex u
        if node[k] == 'H':
            v = getFlippedNode(node, k)
            numberOfFlips = getNumberOfFlips(u, v)
          
            # Add edge (v, u) for a legal move from node u to node v
            edges.append([v, u, numberOfFlips])

    return edges
Example #5
0
def solve():
    c = "".join(coins.get())
    model = NineTailModel()
    path = model.getShortestPath(getIndex(c))
    canvas.delete(ALL)
    x = 10
    y = 10
    canvas.config(width = 50 + (50* len(path)))
    for i in range(len(path)):
        node = getNode(path[i])

        for j in range(3):
            for k in range(3):
                canvas.create_rectangle(x, y, x+10, y + 20)
                canvas.create_text(x + 5, y +  10, text = node[j+k])
                x += 10
            x = x - 30
            y += 20
        x += 50
        y = 10