从序言中的列表中过滤掉大量数字 [英] Filter out large number from list in prolog

查看:34
本文介绍了从序言中的列表中过滤掉大量数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个函数,通过删除小于或等于特定数字的所有内容来过滤数字列表.该函数将采用两个参数:数字列表和要过滤的数字.该函数应返回一个列表,其中包含所有大于过滤器编号的数字.

I want to write a function which filters a list of numbers by removing everything less than or equal to a specific number. The function will take two parameters: a list of numbers and the number to filter. The function should returns a list which has all the numbers larger than the filter number.

有时像这样:

filter_num_list(L1,N,L2) :- ...

test_filter_num_list :- filter_num_list([1,2,3,4,5,6,7,8,9],5,[5,6,7,8,9]).

推荐答案

尝试类似:

filter_num_list([],N,[]) :- true.  
filter_num_list([H|T],N,[H|S]) :- H > N,filter_num_list(T,N,S).  
filter_num_list([H|T],N,S) :- N >= H, filter_num_list(T,N,S).

这篇关于从序言中的列表中过滤掉大量数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆