Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Program to compare character and string

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

Program to compare character and string.....

Code for Program to compare character and string in Artificial Intelligence

predicates
    start
    comp_str(string,string)
    comp_char(char,string)
goal
    clearwindow,
    start.
clauses
    start:-
        comp_str("abcd","dcab"),
        write("equal"),nl.
    
    start:-
        write("not equal"),nl.

    comp_str(Str1,Str2):-
        Str1 <> "",
        frontchar(Str1,Char1,Rest1),
        comp_char(Char1,Str2),
        comp_str(Rest1,Str2).

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

    comp_str(Str1,Str2):-
        fail.

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

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

    comp_char(Char1,Str2):-
        fail.        
                
  
Share: 


Didn't find what you were looking for? Find more on Program to compare character and string Or get search suggestion and latest updates.

Milind Mishra
Milind Mishra author of Program to compare character and string 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!