Prolog Tutorial

 
 
 

Prolog Basics

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 Login page 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 String token Generate facts of family - take different relation 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 Check year is a leap year or not 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 Display strings with closest length of int entered Find murderer 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 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 Multi-List Program Run marriage burro 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) Concate , member in list, reverse, delete list 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 Find factorial of given number Create window i/p string, remove the window & text 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) Insert an element anywhere in the list 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 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
 
 
%trace
domains
    pr = price(real)
    clr = color(symbol)
    co = company(symbol)
    name = name(symbol)
    cls = class(symbol)

predicates
    data(name,co,clr,pr,cls)
    choice(integer)
    repeat

clauses

    repeat.
    repeat :-
        repeat.

    data(name(Van), company(maruti), color(White), price(265000), class(family)).
    data(name(fiat), company(fiat), color(white), price(200000), class(family)).
    data(name(Swift), company(maruti), color(Red), price(400000), class(family)).
    data(name(sumo), company(tata), color(white), price(300000), class(travel)).
    data(name(toyata), company(tata), color(black), price(800000), class(travel)).


    choice(1) :- 
        write(\"Enter Company Name : \"),
        readln(CO_NAME),

        data(name(Z),company(CO_NAME),_,_,_),
        nl, write(Z),
        fail.

    choice(2) :-
        write(\"Enter Car Name : \"),
        readln(CAR_NAME),

        data(name(CAR_NAME),company(X),color(Y),price(Z),_),
        nl, write(CAR_NAME), nl, write(X), nl, write(Y), nl, write(Z),
        fail.

    choice(3) :-
        write(\"Enter the Price : \"),
        readreal(PRCE),

        data(name(X),_,_,price(PRCE),_),
        nl, write(X),
        fail.

    choice(4) :-
        write(\"Enter the Class (travel/family) : \"),
        readln(CL),

        data(name(X),company(Y),_,_,class(CL)),
        nl, write(X), write(\' \'), write(Y),
        fail.

    choice(5) :-
        write(\"Enter the Color : \"),
        readln(CLR),

        data(name(X),_,color(CLR),_,_),
        nl, write(X),
        fail.        

    choice(6) :-
        data(name(A),company(B),color(C),price(D),class(E)),
        nl, write(A), write(\' \'), write(B), write(\' \'), 
        write(C), write(\' \'), write(D), write(\' \'), write(E),
        fail.

    choice(0) :- !.


    goal 
        repeat,

        write(\"\\n\\n1. Search by Com Name\"),
        write(\"\\n2. Search by Car Name\"),
        write(\"\\n3. Search by Price\"),
        write(\"\\n4. Search by Class\"),
        write(\"\\n5. Search by Color\"),
        write(\"\\n6. Search all Cars\"),
        write(\"\\n0. Exit\"),
        write(\"\\n\\nEnter your choice : \"),
        readint(CH),
        choice(CH).

    Related Post:
  1. Prolog program to use of list

  2. Prolog program of login page

  3. Prolog program to define two predicates evenlength(List) and oddlength(List) so that they are true if their argument is a list of even or odd length

  4. Prolog program to define the relation translate(List1, List2) to translate a list of numbers between 0 and 9

  5. Prolog program that defines a relation count(A,L,N) that counts into N the number of occurrences of the element A in the list L

  6. Prolog program to print the zodiac sign of a given birth date

  7. Prolog program for family hierarchy

  8. ProLog Program of Game EX

  9. Prolog program to check whether a number is a member of given list or not

  10. Prolog program to create a database of Employees containing EmpNo, EmpName, Emp Spouse Name, children and print Employee children having a given age

  11. Program to find easy courses person likes

  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 read file and create list of all the lines of it. Each list in turn should be list of word.

  14. Prolog program to compare characters, strings and also reverse string

  15. Prolog program to reverse a list using concatenate

  16. Prolog program to generate a fibonacci series of N elements

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

  18. ProLog Program to find maximum number from inputted numbers

  19. ProLog Program to buy and sale cars

  20. PROLOG PROGRAM TO SPLIT A LIST IN TWO LISTS SUCH THAT ONE LIST CONTAINS NEGATIVE NUMBERS AND ONE CONTAINS POSITIVE NUMBERS

 
 
Didn't find what you were looking for? Find more on ProLog Program to search car by company name, car name, price, class, color...