Dot product Prolog/3 need Hint for the SUM

前端 未结 2 1795
小蘑菇
小蘑菇 2021-01-21 15:09

Good Day I am doing the problema of arithmetic in prolog and Yes its the dot Product I have Searched and found a mess of code that did not equal to what the book is asking me. I

2条回答
  •  时光取名叫无心
    2021-01-21 15:51

    Your problems are that you're using Mul twice where you mean to use it once, and Reuslt2 doesn't exist anywhere. Probably what you mean is:

    dot([], [], 0).
    dot([H1|T1], [H2|T2], Result) :- 
      Prod is H1 * H2,
      dot(T1, T2, Remaining),
      Result is Prod + Remaining.
    

提交回复
热议问题