TETRAHEDRON TRAVEL
You will make a travel through the edges of two tetrahedrons (ABCD, and CDEF) joined as shown in the figure.
-You will start at A, and finish at F.
-You can visit the vertices more than once except the finishing vertex F.
-You cannot pass through the edges more than once.
In how many ways can this travel be done?
Note: Two travels having same edges in different order will be considered as different.
Answer:
Check here please,
Cube Travel
The same question was asked before as a cube travel. The same approach works.
In this case,
nodes=[(1,2,3),(0,2,3),(0,1,3,4,5),(0,1,2,4,5),(2,3,5)]
What does it mean? For example, the first item of nodes is (1,2,3), then this shows there is a path from 0 to 1, 0 to 2 and also 0 to3.
The other example is, look at the fourth item, there is a path from (3,0),(3,1),(3,2),(3,4),(3,5).
And the final destination is the 5th node. There is also a code to check whether or not having added an edge before.
Please, check the code to solve the cube travel puzzle.
Here is the code:
import time
time1=time.time()
nodes=[(1,2,3),(0,2,3),(0,1,3,4,5),(0,1,2,4,5),(2,3,5)]
edges,vertices,count=[],[0],0
def Check(t,eds):
if (t) in edges:
return False
Len=len(eds)
for i in range(Len-1):
e1=eds[i]
for j in range(i+1,Len):
if e1==eds[j]:
return False
return True
alledges=[[] for i in range(1908)]#This size is because I have already found the answer.
def Solve(vertice):
global count
for j in range(len(nodes[vertice])):
newvertice=nodes[vertice][j]
t1,t2=(vertice,newvertice),(newvertice,vertice)
edges.append(t1)
vertices.append(newvertice)
#print("edges=",edges,j,newvertice)
if newvertice!=5 and Check(t2,edges):
#print("vertice=",vertice)
Solve(newvertice)
elif newvertice==5:
for i in range(len(edges)):
alledges[count].append(edges[i])
print(count,alledges[count])
#print("edges=",edges)
#print(vertices)
count+=1
# print("Backtrack before=",edges)
edges.pop()
vertices.pop()
#print("Backtrack after=",edges)
Solve(0)
print("count=",count)
print((time.time()-time1)*1000)