Prolog Tutorial

 
 
 

Prolog Basics

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) Search record by name and phone number Add an element to the begining of list 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 Generate sublist of a given list 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 Find summation of list of numbers Buy car and truck 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 Relation max(X,Y,Max) 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 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 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 Predicates evenlength(List) and oddlength(List) 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 Find grade 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 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 Read 10 strings into a list & display similar char Parent and predecessor 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 Find nth element of a list 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 Ask question Buy and sale cars 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 Fibonacci Series 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
 
 
%trace
domains
    game_list,Tmp_list=symbol* 
    name=symbol
    age,Counter,Counter1=integer

database
    student_db(name,age,game_list)

predicates

    go
    input_student_details
    read_Gamelist(symbol,integer,Game_list,Tmp_list,integer,integer) 
    display_Gamelist(Name,Age,Game_list,Tmp_list)
    get_Team
    find_Cricket(Game_list,Game_list,Counter,Counter1)
    repeate

clauses
    repeate. 
    repeate:-
              repeate.
    go:-

           input_student_details,
           save(\"abc.txt\"),
           write(\"commit\"),
           get_Team.

    input_student_details:-
           write(\"Enter Student Name: \"),
           readln(Name),
           write(\"Enter Student Age: \"),
           readInt(Age),
           write(\"\\nEnter No. of Games Student Plays \"),
           readInt(No_Game),
           read_Gamelist(Name,Age,Game_list,Tmp_list,No_Game,No_game),
           write(\"bye\").

    get_Team:-     
           student_db(Name,Age,Game_list),    
           find_Cricket(Game_list,Game_list,Counter,Counter1), 
           write(\"\\n No of Cricket Player %d\",Counter1),
           Counter=Counter1 + 0,
           repeate.  

    find_Cricket(Game_list,[],Counter,Counter1):-
           Counter1= Counter+1 .        

   find_Cricket(Game_list,Tmp_list,Counter,Counter1):-
          Game_list1=[H |T],
          H<>\"criket\",
          find_Cricket(Game_list,T,Counter,Counter1).

     read_Gamelist(Name,Age,Game_list,Tmp_list,No_Game,0):-
           display_Gamelist(Name,Age,Game_list,Tmp_list).       

     read_Gamelist(Name,Age,Game_list,Tmp_list,No_Game,Count):-
           write(\"Enter Game name :\"),
           readln(Game_nm),
           Game_list1=[Game_nm|Game_list],
           Count1=Count-1,
           read_Gamelist(Name,Age,Game_list1,Tmp_list,No_game,Count1).

     display_Gamelist(Name,Age,Game_list,[]):-
          assert(student_db(Name,Age,Game_list)),
        write(\"\\nList is Displayed\").      

     display_Gamelist(Name,Age,Game_list,Tmp_list):-
           Tmp_list=[H|T],
           write(H),
           display_Gamelist(Name,Age,Game_list,T).   

           student_db(\"Mahesh\",22,[\"football\",\"Cricket\"]).
           student_db(\"Ramesh\",23,[\"volleyball\",\"Cricket\"]).       
       student_db(\"Suresh\",24,[\"Basketball\",\"Cricket\"]).
       student_db(\"Paresh\",25,[\"football\",\"Cricket\"]).
       student_db(\"Kamlesh\",26,[\"Basketball\",\"Cricket\"]).
       student_db(\"Kamal\",27,[\"football\",\"Cricket\"]).
       student_db(\"Pratap\",18,[\"Basketball\",\"Cricket\"]).
       student_db(\"Ganpat\",19,[\"football\",\"Cricket\"]).
       student_db(\"Bupesh\",20,[\"Volleyball\",\"Cricket\"]).
       student_db(\"Sailesh\",21,[\"football\",\"Cricket\"]).
       student_db(\"Ritesh\",17,[\"Basketball\",\"Cricket\"]).
       student_db(\"Pritesh\",16,[\"Volleyball\",\"Cricket\"]).
       student_db(\"Parag\",15,[\"football\",\"Cricket\"]).                    

    Related Post:
  1. ProLog Program to sort the list of integers using Insertion Sort

  2. ProLog Program to add and multiply numbers

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

  4. Prolog program of Medical Diagnostic system

  5. Prolog program of 8-puzzle using heuristic function % with best first search technique

  6. Prolog program to reverse a list

  7. Prolog program Define the relation last(item,list) so that item is the last element of the list using concatenate

  8. Prolog program to find maximum number from a list

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

  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 read list of strings and numbers and copy in database having having string length equal to number

  12. Prolog program to find the last element in a given list

  13. Prolog Multi-List Program

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

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

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

  17. Prolog program to check whether a year is a leap year or not

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

  19. Prolog program for solving the blocks problem using hill climbing

  20. Prolog program to generate the sublist of a given list

 
 
Didn't find what you were looking for? Find more on ProLog Program of Game EX