Prolog Tutorial

 
 
 

Prolog Basics

Find permutation of a given list 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 Compare characters, strings, reverse string 4-3 Gallon Water Jug Problem 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 Write elements of the list line by line 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 Display each digit with respective frequencie Family hierarchy 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) Defines predicate maxlist (L,Max) Add element in last position in given list 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 Find names of student obtained marks greater 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 Read number Parent Tree 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 Reverse list using concatenate 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 Display item name, code, quantity, price,grade Find easy courses person likes 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 Check given word is a palindrome or not 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 Generate first 10 prime num store them in list Blocks problem using hill climbing 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 Merge two ordered list 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 Read two strings concatenation of the both Production system - Missionary cannibal problem 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 Add element in head position in given list Water Jug Problem start with state(0,0) end (2,0) Search record by name and phone number Add an element to the begining of list Print message Find relations in family Login page Relation split(L,P,N) 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 Compare character and string Medical Diagnostic system 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
 
 
Domains
    stringlist = string*
Predicates
    startup
    reading(stringlist)
    findClosestString(integer,stringlist,stringlist,stringlist)
Clauses
    startup:-
        write(\"\\nEnter Any String = \"),
        readln(Str),
        OldList = [Str],
        reading(OldList).

    reading(OldList):-
        write(\"\\nDo You Want To Enter Another String (y/n) ? : \"),
        readchar(Ans),
        write(Ans),nl,
        Ans = \'y\',
        write(\"\\nEnter Any String = \"),
        readln(Str),
        Newlist = [Str|OldList],nl,
        reading(Newlist).

    reading(OldList):-
        write(\"\\nEnter ANy Positive Number = \"),
        readint(Number),
        findClosestString(Number,OldList,[],Newlist).

    findClosestString(_,[],List,_):-
        write(List).

    findClosestString(Number,Oldlist,List,Newlist):-
        Oldlist = [Head | Tail],
        str_len(Head,Length),
        Number - 1 <= Length,
        Number + 1 >= Length,
        Newlist = [Head | List],
        findClosestString(Number,Tail,Newlist,List2).

    findClosestString(Number,Oldlist,List,Newlist):-
        Oldlist = [Head | Tail],
        Newlist = List,
        findClosestString(Number,Tail,Newlist,List2).

Goal
    clearwindow,
    makewindow(1,2,3,\"String Operations\",0,0,50,80),
    startup.


Output :-->

+-------------------------------String Operations------------------------------+
¦                                                                              ¦
¦Enter Any String = Mayank                                                     ¦
¦                                                                              ¦
¦Do You Want To Enter Another String (y/n) ? : y                               ¦
¦                                                                              ¦
¦Enter Any String = raj                                                        ¦
¦                                                                              ¦
¦                                                                              ¦
¦Do You Want To Enter Another String (y/n) ? : y                               ¦
¦                                                                              ¦
¦Enter Any String = rahul                                                      ¦
¦                                                                              ¦
¦                                                                              ¦
¦Do You Want To Enter Another String (y/n) ? : y                               ¦
¦                                                                              ¦
¦Enter Any String = kesha                                                      ¦
¦                                                                              ¦
¦                                                                              ¦
¦Do You Want To Enter Another String (y/n) ? : y                               ¦
¦                                                                              ¦
¦Enter Any String = shwetambari                                                ¦
¦                                                                              ¦
¦                                                                              ¦
¦Do You Want To Enter Another String (y/n) ? : y                               ¦
¦                                                                              ¦
¦Enter Any String = anukul                                                     ¦
¦                                                                              ¦
¦                                                                              ¦
¦Do You Want To Enter Another String (y/n) ? : n                               ¦
¦                                                                              ¦
¦Enter ANy Positive Number = 5                                                 ¦
¦[\"Mayank\",\"rahul\",\"kesha\",\"anukul\"]                                           ¦
¦Press the SPACE bar                                                           ¦
¦                                                                              ¦
+------------------------------------------------------------------------------+

    Related Post:
  1. Prolog program to find the permutations of a given list i.e. to find all possible combinations of the elements of a list

  2. ProLog Program to add and multiply numbers

  3. ProLog Program to create a window and input a new string, remove the window and text, write to existing window

  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. Game

  6. Prolog program to find last item of the list

  7. Program to compare character and string

  8. Prolog program to add an element in a last position in given list

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

  10. Prolog program to read 10 string and store them in database and then write the string in increasing order of their length to other database

  11. Design a game based on 5*5 matrix and two players moving in spiral way to the center given the dice value

  12. Prolog program to define the relation shift(List1, List2) so that List1 shifts rotationally by one element to the left

  13. 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

  14. ProLog Program of Bubble Sort

  15. Prolog program to create a database of teachers containing, TeacherName, List of subjects taught and for given teacher, display no of lectures require

  16. Prolog program of Water Jug Problem start with state(0,0) and end with(2,0)

  17. ProLog Program to buy car and truck

  18. Prolog program to concatenate two lists giving third list

  19. Prolog program to delete an element from a list using concatenate

  20. Prolog program to define the relation shift(L1,L2) so that L2 is L1 shifted rotationally by one element to the left