users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

cube(s) path program


From: Stephen
Subject: cube(s) path program
Date: Tue, 17 Apr 2018 16:03:49 +0100

Hi there I have a program (in another language) which finds the paths through a cube.

For a single cube there are just 18 paths, for a 2 * 2 * 2 cube there are 392628 paths for a 3 * 3 * 3 cube it is very large…

The program(s) I have used to solve this would take many years to solve this.

I have been trying to write a program in Prolog to solve it in the hope that it would be quicker but am having almost zero ‘luck’.

Was wondering if anyone could help?

As an example here is a crude program that works out paths between two corners on a single cube:

(it is not one I wrote but modified – slightly)

 

edge(0,1).

edge(0,2).

edge(0,4).

edge(1,5).

edge(1,3).

edge(3,7).

edge(5,7).

edge(2,3).

edge(2,6).

edge(6,7).

edge(4,6).

edge(4,5).

 

connected(X,Y) :- edge(X,Y) ; edge(Y,X).

 

path(A,B,Path) :-

       travel(A,B,[A],Q),

       reverse(Q,Path).

 

travel(A,B,P,[B|P]) :-

       connected(A,B).

travel(A,B,Visited,Path) :-

       connected(A,C),          

       C \== B,

       \+member(C,Visited),

       travel(C,B,[C|Visited],Path). 

 

Any ideas?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]