list - Prolog列表问题

标签 list prolog predicate

[a,b,c,d] and
[[1,2,3,4],[5,6,7,8],[43,34,56,5],[23,32,2,2]]

我想做

[[a,1,2,3,4],[b,5,6,7,8],[c,43,34,56,5],[d,23,32,2,2]]

我使用 swi prolog 可以吗?

非常感谢。

最佳答案

solve([], [], []).

solve([[X|Y]|S], [X|L1], [Y|L2]):-
  solve(S, L1, L2).

更新:如何使用

将函数写入文件“a.pl”,然后在swi-prolog 中输入:

['a.pl'].

然后输入:

solve(X, [a,b,c,d], [[1,2,3,4],[5,6,7,8],[43,34,56,5],[23,32,2,2]]).

您将获得:

X = [[a, 1, 2, 3, 4], [b, 5, 6, 7, 8], [c, 43, 34, 56, 5], [d, 23, 32, 2, 2]] 

我有一种奇怪的感觉,我正在做你的作业。是吗?

关于list - Prolog列表问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6014961/

相关文章:

java - 如何区分用户选择项目和 getSelectedValue()?

python - 如何将函数应用于 python 列表的每个子列表?

c++ - 交换列表最后一个值的问题,C++

c# List<Dictionary<string,string>> 添加唯一字典

list - 有极限的序列

prolog:列表中最大重复元素

prolog - SWI-Prolog 和文件扩展名 : Why won't swipl recognize a file with an extension?

inheritance - 在序言中定义 is_a 谓词?

java - 根据 Map 输入从 Collection<Objects> 中提取对象

java - 将多个过滤器应用于 Java 中的 map