0
votes

I'm trying to learn prolog. I want to write in prolog a code for a general list of numbers. So far I have pick_numbers_general(List, N, NumList), where List is a general list (including nested ones), and N is a number.

The predicate succeeds if NumList is a list of the numbers in List, including those in nested lists, greater than N. The appearance order of the numbers in Numlist is the same as that in L, so for instance, pick_numbers_general([g,h,1,[2,[n,3]],p],1,NumList) is true when NumList is [2,3].

1

1 Answers

0
votes

Hint: you're doing three operations at once. If you split those out, this exercises becomes a lot easier.

pick_numbers_general(List, Min, Numbers) :-
    flatten(List, Flat),
    filter_numbers(Flat, Numbers0),
    filter_greater_than(Numbers0, Min, Numbers).