Predicate in prolog -


i need define predicate in prolog takes list input , sums squares of numbers >= 5 , subtract sum of absolute value of numbers <=2.

this have :-

pred([], 0). pred([head|tail], result) :-     gr85(head),     pred(tail, total),     result head*head + total.  pred([head|tail], result) :-     leq2(head),     pred(tail, total),     result total - head.  gr85(number):-     number >= 5.  leq2(number):-     number =< 2. 

my question how exclude between 2 , 5. if input 3 in list, returns false.

expected input

pred([3,6,2,-1], result). 

expected output

result= 33 (6*6 -2-1) 

add 'skip all' clause:

weird_sum([_|tail], result) :- weird_sum(tail, result). 

i think gain insight prolog working when analyze where clause should added.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -