Write a predicate cmp_list/3
, the first 2 arguments are 2 lists, and the last one is Comparison
which means ge
, lt
, le
, or gt
.
ge
: greater or equal
lt
: less than
le
: less or equal
gt
: greater than
the output should be like this:
the first two lists represent a version of a software, and the function is used to compare two versions of a software to see which one is newer:
?- cmp_list([2,3,4], [2,3,5], C).
C = lt ;
C = le .
?- cmp_list([1,2,3,4], [1,1,8], C).
C = gt ;
C = ge .
这听起来像家庭作业,所以我只给你一些提示。
- 如果两个列表都为空,则它们相等 (
le
or ge
).
- 如果第一个列表为空,则有类似的内容
[], [V|Vt], ...
比较时,例如 1.2 和 1.2.3,这可能是递归的结束,因此第三个参数应该是lt
.
- 同样,如果第二个列表为空,则第三个参数应该是
gt
.
- 如果两者都非空,则应该比较头部。如果不同,请回答
gt
or lt
因此。如果它们相等,则在尾部递归。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)