turbo-prolog

search all paths and the shortest path for a graph - Prolog

落花浮王杯 提交于 2019-12-14 02:45:03
问题 I have a problem in my code with turbo prolog which searches all paths and the shortest path in a graph between 2 nodes. The problem that i have is to test if the node is in the list or not (exactly in the clause of member) 1 ---- b ---- 3 --- | --- --- | ----- a |5 d --- | ----- --- | --- 2 --- | --- 4 -- c -- for example we have for b--->c ([b,c],5) , ([b,a,c],3) and ([b,d,c],7) : possible paths. ([b,a,c],3) : the shortest path. and this is my code : DOMAINS list=Symbol * PREDICATES

Convert string to Upper and Lower case Turbo Prolog

早过忘川 提交于 2019-12-13 05:22:11
问题 How do I convert a string to Upper and to Lower case in Turbo Prolog. string_upper and string_lower function is for SWI Prolog, I found something like, tolower([], []). tolower([Upper|UpperTail], [Lower|LowerTail]) :- char_type(Lower, to_lower(Upper)), tolower(UpperTail, LowerTail). But didn't get what exactly it is. Can anyone help me solve this. 回答1: I did it using upper_lower(), write("Enter string to convert\n"), readln(Str1), upper_lower(Str1,Low), write("In lower case "), write(Low),nl,

Want to print the path,but getting errors

老子叫甜甜 提交于 2019-12-11 12:43:40
问题 domains list=symbol* predicates path(symbol,symbol) solve(symbol,symbol,list) insert(symbol,list,list) clauses path(a,b). path(b,c). path(c,d). path(d,e). path(a,d). path(c,e). solve(X, Z, P):- path(X,Z), insert(Z,Temp,P), P=Temp. solve(X,Z,P):- path(X,Y), insert(Y,Temp,P), P=Temp, solve(Y,Z,P). insert(X,[X|Tail],Tail). insert(X,[Y|Tail],[Y|Tail1]):- insert(X,Tail,Tail1). Want to print the path which i have followed in going from one point to another.But getting errors.For examples, i want:

Explanation of a Prolog algorithm to append two lists together

这一生的挚爱 提交于 2019-11-26 11:39:00
问题 This is an algorithm to append together two lists: Domains list= integer* Predicates nondeterm append(list, list, list) Clauses append([], List, List) :- !. append([H|L1], List2, [H|L3]) :- append(L1, List2, L3). Goal append([9,2,3,4], [-10,-5,6,7,8], Ot). The result is a list [9,2,3,4,-10,-5,6,7,8] , and it\'s saved in \" Ot \". My question is, how does this work? What I understand is that in every recursive call, in the first list, you get only the tail as a list ( thus reducing its size by