在 Prolog 中访问数字和字符串向量
我必须解决图形定义如下的派系问题:
[1-[2,3,4,5,6], 2-[1,3,4,5,6], 3-[1,2 ,4,5,6],4-[1,2,3,5,6], 5-[1,2,3,4,6], 6-[1,2,3,4,5]]
所以我开始这样做
c(_,[]).
c(G,X):-length(G,S),rest(X, G, G1).
rest(X, [X|Ys], Ys).
rest(X, [_|Ys], Zs):-rest(X, Ys, Zs).
我收到:
S = 6-[1,2,3,4,5] ;
S = 5-[1,2,3,4,6] ;
S = 4-[1,2,3,5,6] ;
S = 3-[1,2,4,5,6] ;
S = 2-[1,3,4,5,6] ;
S = 1-[2,3,4,5,6] ;
S = [] ;
parsing query: c([1-[2,3,4,5,6],2-[1,3,4,5,6],3-[1,2,4,5,6],4-[1,2,3,5,6],5-[1,2,3,4,6],6-[1,2,3,4,5]],S) ok!
所以我试图获取每次迭代的第一个元素(1,2,3,4,5,6),然后是对...... 但不知道如何访问每个元素。
I have to do the clique problem where the graph is defined like that:
[1-[2,3,4,5,6], 2-[1,3,4,5,6], 3-[1,2,4,5,6],4-[1,2,3,5,6], 5-[1,2,3,4,6], 6-[1,2,3,4,5]]
so I started to do this
c(_,[]).
c(G,X):-length(G,S),rest(X, G, G1).
rest(X, [X|Ys], Ys).
rest(X, [_|Ys], Zs):-rest(X, Ys, Zs).
And i receive:
S = 6-[1,2,3,4,5] ;
S = 5-[1,2,3,4,6] ;
S = 4-[1,2,3,5,6] ;
S = 3-[1,2,4,5,6] ;
S = 2-[1,3,4,5,6] ;
S = 1-[2,3,4,5,6] ;
S = [] ;
parsing query: c([1-[2,3,4,5,6],2-[1,3,4,5,6],3-[1,2,4,5,6],4-[1,2,3,5,6],5-[1,2,3,4,6],6-[1,2,3,4,5]],S) ok!
So i'm trying to get the first element of each iteration (1,2,3,4,5,6), and later the pairs...
but don't know how to access to each element.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

这样做:
可以获得第一个元素
Doing that:
Can obtain the first element