Help:=proc(): print(`Ham(G), IsLegal(G,P)`):end: #IsLegal(G,P): is the path P feasible in the graph G? IsLegal:=proc(G,P) local i: evalb({seq(member([P[i],P[i+1]],G[2]),i=1..nops(P)-1)}={true}): end: with(combinat): #Ham(G): Inputs a directed graph (in the form [V,E]) #and outputs all Hamiltinian paths Ham:=proc(G) local V,E,n,S,Sg,i: V:=G[1]: E:=G[2]: S:=permute(V): Sg:={}: for i from 1 to nops(S) do if IsLegal(G,S[i]) then Sg:=Sg union {S[i]}: fi: od: Sg: end: #IsLegalE(G,P): Is the sequence of edges P #feasible in the graph G? IsLegalE:=proc(G,P) local i: evalb({seq(evalb(P[i][2]=P[i+1][1]),i=1..nops(P)-1)}={true}): end: #EulerB(G): Inputs a directed graph (in the form [V,E]) #and outputs all Eulerian paths by stupid brute force EulerB:=proc(G) local V,E,n,S,Sg,i: V:=G[1]: E:=G[2]: S:=permute(E): Sg:={}: for i from 1 to nops(S) do if IsLegalE(G,S[i]) then Sg:=Sg union {S[i]}: fi: od: Sg: end: