根据一个值找到列表中列表的最小值 [英] find minimum of list inside list on the basis of one value
本文介绍了根据一个值找到列表中列表的最小值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在序言中有这个列表
[[[dublin, london], 1000], [[dublin, moscow, london], 5000]]
我想计算列表的最小值,这样答案应该是
And I want to calculate the minimum of the list such that answer should be
[[都柏林,伦敦],1000]
这个问题有一些类似的问题 prolog 列表中的最小值一个>
This question has some similar problem minimum in list of lists in prolog
但这似乎不起作用,我得到的输出为假.请帮忙
But that doesn't seems to working I am getting output as false. Please help
推荐答案
尝试库(聚合):
?- aggregate_all(min(X,Y),
member([Y,X], [[[dublin, london], 1000],
[[dublin, moscow, london], 5000]]),
R).
R = min(1000, [dublin, london]).
另见此处:
可回溯谓词上的聚合运算符
https://www.swi-prolog.org/pldoc/man?section=聚合
这篇关于根据一个值找到列表中列表的最小值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文