File: ham.pl

package info (click to toggle)
gprolog 1.4.5.0-3
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 7,924 kB
  • sloc: ansic: 55,584; perl: 18,501; sh: 3,401; makefile: 1,114; asm: 20
file content (86 lines) | stat: -rw-r--r-- 1,014 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
ham(true) :-
	ham_show, fail ; true.

ham(false) :-
	ham_silent, fail ; true.


ham_show :-
	ham1(X),
	write(X), nl.


ham_silent :-
	ham1(_).

ham1(X):-
	cycle_ham([a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t],X).



cycle_ham([X|Y],[X,T|L]):-
	chain_ham([X|Y],[],[T|L]),
	edge(T,X).


chain_ham([X],L,[X|L]).

chain_ham([X|Y],K,L):-
	del(Z,Y,T),
	edge(X,Z),
	chain_ham([Z|T],[X|K],L).




del(X,[X|Y],Y).

del(X,[U|Y],[U|Z]):-
	del(X,Y,Z).




edge(X,Y):-
	connect(X,L),
	el(Y,L).




el(X,[X|_]).

el(X,[_|L]):-
	el(X,L).




connect(a,[b,j,k]).
connect(b,[a,c,p]).
connect(c,[b,d,l]).
connect(d,[c,e,q]).
connect(e,[d,f,m]).
connect(f,[e,g,r]).
connect(g,[f,h,n]).
connect(h,[i,g,s]).
connect(i,[j,h,o]).
connect(j,[a,i,t]).
connect(k,[o,l,a]).
connect(l,[k,m,c]).
connect(m,[l,n,e]).
connect(n,[m,o,g]).
connect(o,[n,k,i]).
connect(p,[b,q,t]).
connect(q,[p,r,d]).
connect(r,[q,s,f]).
connect(s,[r,t,h]).
connect(t,[p,s,j]).


% benchmark interface

benchmark(ShowResult) :-
	ham(ShowResult).

:- include(common).