Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search results for query: *

  1. slackerbrad

    New to prolog - how to execute program??

    the unix(argv([Word|Constraints])), line makes it look like it's intended to run from the command prompt, instead of in the SWI-Prolog interface. If you replace that with getWord(Word), the program should prompt you for words instead. Then just start up SWI-Prolog, type in['filename.pl']. at the...
  2. slackerbrad

    Sequences in Prolog

    Assuming you're representing the sequences as lists of r,g, and b (since prolog interprets capitals as variables), and you want to accept an empty sequence, you want something like: gbr(g,b,r). accept([]). accept([X]). accept([X,Y]):-X /== Y. accept([X,Y,Z|Xs]):- X /== Y, not gbr(X,Y,Z)...
  3. slackerbrad

    Counting number of points

    You seem to be missing rules for 3 and 4 cards in a suit. You should assign a value of 0 to those cases. Otherwise, prolog can't unify hands containing those numbers of cards, so it will say 'No'.
  4. slackerbrad

    List Problems, need help, thank you.

    General hint: make sure you dig recursion Hint on previous-to: It's obviously true if X is the head of a list and Y is a member of the list. So you must first figure out a member predicate, then reduce Z to the point where X is the head. Hint on number-occurences: number-occurences(X,[],0)...
  5. slackerbrad

    Can anyone give me some tips on how

    You probably want to start with some simpler predicates you can use in constructing the more complex ones, such as: / member(X,Ys) returns true if X is a member of Ys member(X,[X|_Xs]). member(X,[_Y|Ys]):-member(X,Ys). / select(X,Ys,Zs) returns true if Zs is Ys with the first occurence of X...
  6. slackerbrad

    How to calculate the distance between two cities??

    You should throw in a recursive step. i.e. add: oad(X,Y,D) :- distance(X,Y,D). {base case} oad(X,Y,D) :- distance(X,Z,D1), oad(Z,Y,D2), D is D1+D2.

Part and Inventory Search

Back
Top