Prolog Tutorial

 
 
 

Prolog Basics

Find length of given list DB of teacher - show no of lectures require

Game

Game Predicates evenlength(List) and oddlength(List) Multi-List Program Run marriage burro Find names of student obtained marks greater Search company, car name, price, class, color Relation translate L1, L2 to num b/w 0 and 9 Read file and create list of all the lines of it Add and multiply numbers Find grade Concate , member in list, reverse, delete list Read number Parent Tree Check number is member of given list or not 10 int in list,10 from database - find 2nd max

Search Programs

Game LT Relation dividelist (L,L1,L2) Find factorial of given number Create window i/p string, remove the window & text Reverse list using concatenate Logic repres - converting to prove the proof Define relation shift L1,L2- L1 shift by one left Read file display line by line - go to output file Find grade Find relations Insert an element anywhere in the list Display item name, code, quantity, price,grade Find easy courses person likes Delete an element from given list Copy String length equal to number using file Sort list of integers using Insertion Sort Delete an element from list using concatenate Read 10 strings into a list & display similar char Parent and predecessor Check given word is a palindrome or not Find last item of the list Check whether given list is palindrome or not Store cricket players details in database Find maximum number from inputted number Monkey and banana Find nth element of a list Generate first 10 prime num store them in list Blocks problem using hill climbing Print number from 1 to 25 Murder mystery 8puzzle - heuristic function % - best first search Relation last(item,list) so last el w/o concate Ask question Buy and sale cars Merge two ordered list Print zodiac sign of a given birth date Use of list DB Employees - Print emp children of given age

Problem Solving

Game 5*5 matrix -moving in spiral way- dice value Fibonacci Series Read two strings concatenation of the both Production system - Missionary cannibal problem Search record by name and phone number Add an element to the begining of list Print message Find relations in family Login page Add element in head position in given list Water Jug Problem start with state(0,0) end (2,0) Find sum of all numbers in given list Show no of user entered book - 2 diff database

Sort Programs

Game EX Find length of a list is even or odd String token Generate facts of family - take different relation Relation split(L,P,N) Rotate list n places to the left Define relation shift L1,L2- L1 shift by one right Read sentence from file copy each of token in list Program to print user entered number Marcus Check year is a leap year or not Compare character and string Medical Diagnostic system Find last element in a given list Read file and create a list of all words of it

Basic Programs

Sort list using Bubble Sort Delete el from given list w/o using concatenate Display strings with closest length of int entered Find murderer Find permutation of a given list Split list in negative & positive list Reverse given list Read and write file Find length of names Teacher and lecture Generate sublist of a given list Compare characters, strings, reverse string 4-3 Gallon Water Jug Problem Concatenate two lists in giving third list Copy in database - string length equal to number Sort list using Quick Sort Relation count(A,L,N) num of occurrences Find summation of list of numbers Buy car and truck Write elements of the list line by line Person hobbies Predicate order (List) is true if List is ordered String in increasing order of their length in db

File and Database Programs

Spiral game Relation max(X,Y,Max) Display each digit with respective frequencie Family hierarchy Predicate logic representation and prove proof Search student data - Name or phone no is i/p Rel last(item,list) so item is last el of list Convert decimal number to roman number Find animals leaving in water and land Defines predicate maxlist (L,Max) Add element in last position in given list
 
 
<P><FONT size=2 face=\"Courier New\">%  Rotate a list N places to the left </FONT></P>
<P><FONT size=2 face=\"Courier New\">% rotate(L1,N,L2) :- the list L2 is obtained from the list L1 by <BR>%    rotating the elements of L1 N places to the left.<BR>%    Examples: <BR>%    rotate([a,b,c,d,e,f,g,h],3,[d,e,f,g,h,a,b,c])<BR>%    rotate([a,b,c,d,e,f,g,h],-2,[g,h,a,b,c,d,e,f])<BR>%    (list,integer,list) (+,+,?)</FONT></P>
<P><BR><FONT size=2 face=\"Courier New\">% Split a list into two parts</FONT></P>
<P><FONT size=2 face=\"Courier New\">% split(L,N,L1,L2) :- the list L1 contains the first N elements<BR>%    of the list L, the list L2 contains the remaining elements.<BR>%    (list,integer,list,list) (?,+,?,?)</FONT></P>
<P><FONT size=2 face=\"Courier New\">domains<BR> list=symbol*<BR>predicates<BR> rotate(list,integer,list).<BR> length(list,integer).<BR> rotate_left(list,integer,list).<BR> append(list,list,list).<BR> split(list,integer,list,list).<BR>clauses</FONT></P>
<P><FONT size=2 face=\"Courier New\">rotate(L1,N,L2) :- N >= 0, <BR>   length(L1,NL1), N1 = N mod NL1, rotate_left(L1,N1,L2).<BR>rotate(L1,N,L2) :- N < 0,<BR>   length(L1,NL1), N1 = NL1 + (N mod NL1), rotate_left(L1,N1,L2).</FONT></P>
<P><FONT size=2 face=\"Courier New\">rotate_left(L,0,L).<BR>rotate_left(L1,N,L2) :- N > 0, split(L1,N,S1,S2), append(S2,S1,L2).</FONT></P>
<P><FONT size=2 face=\"Courier New\">append([],Listb,Listb).<BR> <BR> append([X|List1],List2,[X|List3]):-</FONT></P>
<P><FONT size=2 face=\"Courier New\"> append(List1,List2,List3).</FONT></P>
<P><FONT size=2 face=\"Courier New\">split(L,0,[],L).<BR>split([X|Xs],N,[X|Ys],Zs) :- N > 0, N1 = N - 1, split(Xs,N1,Ys,Zs).</FONT></P>
<P><FONT size=2 face=\"Courier New\">length([],0).<BR>length([_|L],N) :- length(L,N1), N = N1 + 1.</FONT></P>
<P><FONT size=2 face=\"Courier New\">--------------------------------------------------------</FONT></P>
<P><FONT size=2 face=\"Courier New\">Goal: rotate([a,b,c,d,e,f,g,h],3,X)</FONT></P>
<P><FONT size=2 face=\"Courier New\">X=([\"d\",\"e\",\"f\",\"g\",\"h\",\"a\",\"b\",\"c\"])</FONT></P>
<P><FONT size=2 face=\"Courier New\">1 solution</FONT></P>

    Related Post:
  1. ProLog Program of parent and predecessor

  2. Prolog program to find the permutations of a given list i.e. to find all possible combinations of the elements of a list

  3. ProLog Program to sort a list using Quick Sort

  4. Prolog program to define the relation last(item,list) so that item is the last element of the list without the use of concatenate

  5. ProLog Program to find murderer

  6. Prolog program of string token

  7. Prolog program to find maximum number from a list

  8. Prolog program to solve the 4-3 Gallon Water Jug Problem

  9. Prolog program to read a list of strings , integer and display all the strings with the closest length of the integer entered should go to a new list

  10. Prolog program to define a relation dividelist (L,L1,L2) so that L is partitioned into L1 and L2 where length of L1 and L2 are almost same

  11. Prolog program to find whether the length of a list is even or odd

  12. Prolog program to read a file and display each of its line one by one and lines chosen by user should go to an output file

  13. Prolog program to reverse a list using concatenate

  14. Prolog program to define the relation translate(L1,L2) to translate a list of numbers 0-9 to a list of corresponding words i.e. 0 - zero 1 - one

  15. Predicate logic representation and then converting them to prolog, prove the proof.

  16. ProLog Program to read 10 integers in a list and 10 from the database and find 2nd maximum of all of them

  17. Prolog program to check whether a given word is a palindrome or not

  18. Prolog program to concatenate two lists giving third list

  19. Prolog program to find sum of all the numbers in a given list

  20. Prolog program to merge two ordered list generating an ordered list

 
 
Didn't find what you were looking for? Find more on Prolog program to rotate a list n places to the left