Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

prolog program to read 10 strings into a list and display similar characters

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

Write a complete prolog program to read 10 strings into a list.
Then read one more string and retrun a string which has similar
characters as the entered string in any order.

Code for prolog program to read 10 strings into a list and display similar characters in Artificial Intelligence

Domains
    stringList = string*
Predicates
    reading
    startup(integer,stringList)
    comparsion(stringList,string)
    compareString(string,string)
    compareChar(char,string)
Clauses
    
    startup(0,List):-
        write("Enter one more string = "),
        readln(Str),
        comparsion(List,Str).
    
    startup(Number,StringList):-
        write("Enter String = "),
        readln(Name),
        Newlist = [Name | StringList],
        TempNumber = Number - 1,
        startup(TempNumber,Newlist).

    comparsion(StringList,Str):-
        StringList = [Head | Tail],
        str_len(Str,Lenstr),
        str_len(Head,LenHead),
        Lenstr = LenHead,    
        compareString(Str,Head),
        write(Head," Which Is Similar Character As ",Str),nl.
    
    comparsion(StringList,Str):-
        StringList = [Head | Tail],
        comparsion(Tail,Str).

    comparsion(StringList,Str):-
        write("No String Found In List Simillar To ",Str),nl.

    compareString(Str1,Str2):-
        Str1 <> "",
        frontchar(Str1,Char1,Rest1),
        compareChar(Char1,Str2),
        comparestring(Rest1,Str2).

    compareString(Str1,Str2):-
        Str1 = "".        

    compareString(Str1,Str2):-
        fail.

    comparechar(Char1,Str2):-
        frontchar(Str2,Char2,Rest2),
        Char1 <> Char2,
        Rest2 <> "",
        compareChar(Char1,Rest2).

    comparechar(Char1,Str2):-
        frontchar(Str2,Char2,Rest2),
        Char1 = Char2.

    comp_char(Char1,Str2):-
        fail.
    
    reading:-
        NumRead = 10,
        startup(NumRead,[]).

Goal
    clearwindow,    
    makewindow(1,2,3,"String Operations",0,0,25,80),
    reading.


Output :-->

+-------------------------------String Operations------------------------------+
¦Enter String = mayankmodi                                                    ¦
¦Enter String = rahul khanna                                                   ¦
¦Enter String = rahul patel                                                    ¦
¦Enter String = mr.bajaj                                                       ¦
¦Enter String = rahul mishara                                                  ¦
¦Enter String = idom knayam                                                    ¦
¦Enter String = hello                                                          ¦
¦Enter String = good morning                                                   ¦
¦Enter String = good night                                                     ¦
¦Enter String = good                                                           ¦
¦Enter one more string = aamynk idom                                           ¦
¦idom knayam Which Is Similar Character As aamynk idom                         ¦
¦                                                                              ¦
¦Press the SPACE bar                                                           ¦
¦                                                                              ¦
¦                                                                              ¦
¦                                                                              ¦
¦                                                                              ¦
¦                                                                              ¦
¦                                                                              ¦
¦                                                                              ¦
¦                                                                              ¦
¦                                                                              ¦
+------------------------------------------------------------------------------+
  
Share: 



Milind Mishra
Milind Mishra author of prolog program to read 10 strings into a list and display similar characters 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!