Guest User

Untitled

a guest
Jul 24th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.67 KB | None | 0 0
  1. %returns true iff all bids in [Bids] results in all Items being sold
  2. %func2/2(+[Items], +[Bids])
  3. func2([item(T,N)|Is],Bs) :- Is == [], func3(T,Bs,Count), Count == N.
  4. func2([item(T,N)|Is],Bs) :- func2(Is, Bs), func3(T,Bs,Count), Count == N.
  5.  
  6. %func3/3(+Type, +[Bids], ?Count).
  7. func3(_,[],0).
  8. func3(Type,[bid(_, Items, _)|Bs],Count) :- func3(Type, Bs, C), countItem(Items, Type, C1), Count is C + C1.
  9.  
  10. %counts the sum of bids for a particular item
  11. %countItem/3(+[Items], +Type, ?NumberOfItem).
  12. countItem([],_,0).
  13. countItem([item(Type,N)|Xs], T, Count) :- Type == T, countItem(Xs, T, C), Count is C + N.
  14. countItem([item(Type,_)|Xs], T, Count) :- Type \= T, countItem(Xs, T, Count).
Add Comment
Please, Sign In to add comment