Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

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

Posted By: Milind Mishra     Category: Artificial Intelligence     Views: 3532

Write a complete 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.

Code for 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 in Artificial Intelligence

database
    unsorted_db(string,integer)
    sorted_db(string)

predicates
    reading
    writing
    removing
    serching(integer)
    go(integer)

goal
    clearwindow,
    reading,!,
    serching(1),
    write("String in sorted order"),nl,
    writing,
    removing.

clauses
    reading:-
        NumRead = 10,
        go(NumRead).
    go(0).
    
    go(Num):-
        write("Enter any string = "),
        readln(Name),
        str_len(Name,Len),
        asserta(unsorted_db(Name,Len)),
        N = Num - 1,
        go(N).

    writing:-
        sorted_db(Name),
        write(Name),nl,
        fail.
        
    writing.
    
    serching(Max):-
        unsorted_db(Name,Max),
        assertz(sorted_db(Name)),
        retract(unsorted_db(Name,Max)),
        serching(Max).
        
    serching(Max):-
        Max = 32767.
        
    serching(Max):-
        Max1 = Max + 1,
        serching(Max1).
            
    removing:-
        retract(sorted_db(_)),
        fail.    

    removing.
  
Share: 



Milind Mishra
Milind Mishra author of 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 is from India.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!