我如何声明两个列表的长度相同? [英] How do I state that two lists have the same length?
本文介绍了我如何声明两个列表的长度相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要知道如何在 Prolog 中比较两个列表的长度.这是我目前所拥有的:
I need to know how to compare the length of two lists in Prolog. This is what I have so far:
sum(N1,N2) :-
checklength(N1,N2).
checklength(N1,N2) :-
L1 is length(N1,What),
L2 is length(N2,What),
Comp(L1,L2).
Comp(L1,L2) :-
L1=:=L2.
推荐答案
当然,CapelliC 的答案是完美的,但您也可以尝试解决此问题的标准"方法:
Of course, the answer from CapelliC is perfect, but you can try also the "standard" method of approaching this problem:
same_length([],[]).
same_length([_|L1],[_|L2]) :- same_length(L1, L2).
这篇关于我如何声明两个列表的长度相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文