answersLogoWhite

0


Best Answer

How about a Perl compatible regular expression for grep? I guess that's an algorithm.

This one will search for seven-letter palindromes:

grep -P '(?=^.{7}$)(.)(.)(.).\3\2\1' /path/to/your/dictionary

The -P flag let's grep recognize perl compatible regular expressions (PCRE).

The (?=^.{7}$) looks ahead to make sure it's matching a seven-letter word.

The \1 is a backreference to the first (.) which matches any character. But now it has to match it again, except we're asking it to match in reverse order, \3\2\1 instead of \1\2\3.

Then we have a single dot for the fourth letter, which will match any character.

Just add or subtract subexpressions "(.)" as needed, along with the appropriate number backreferences "/1" to find palindromes.

This is the output from grepping the TWL (the Scrabble dictionary):

deified

halalah

reifier

repaper

reviver

rotator

sememes

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the algorithm for palindrome?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Using Python write an algorithm that takes a string as input and determines whether or not it is a palindrome?

def isPalindrome(s): return s == s[::-1] then just call the function with a string like isPalindrome('poop')


Design an algorithm to check whether a given string is a palindrome or not?

#include <stdio.h> #include <conio.h> #include <string.h> void input(char a[ ]) { int i; printf("\n enter string\n"); scanf("%s",a); } void output(char a[ ]) { printf("\n string is %s",a); } int palindrome(char a[ ]) { int n,i; n=count(a); n=n-1; i=0; for(;a[n]==a[i] && n>=i;i++,n--); if(n>=i) return 0; else return 1; } void main( ) { char a[80],b[80],s; int n; printf("\n check palindrome"); input(a); n=palindrome(a); output(a); if(n==1) printf("\n palindrome"); else printf("\n not palindrome"); getch(); }


Design a algorithm to check whether a given string is palindrome or not?

#include <stdio.h> #include <conio.h> #include <string.h> void input(char a[ ]) { int i; printf("\n enter string\n"); scanf("%s",a); } void output(char a[ ]) { printf("\n string is %s",a); } int palindrome(char a[ ]) { int n,i; n=count(a); n=n-1; i=0; for(;a[n]==a[i] && n>=i;i++,n--); if(n>=i) return 0; else return 1; } void main( ) { char a[80],b[80],s; int n; printf("\n check palindrome"); input(a); n=palindrome(a); output(a); if(n==1) printf("\n palindrome"); else printf("\n not palindrome"); getch(); }


Write an algorithm to check whether a given string is palindrome or not?

#include <stdio.h> #include <conio.h> #include <string.h> void input(char a[ ]) { int i; printf("\n enter string\n"); scanf("%s",a); } void output(char a[ ]) { printf("\n string is %s",a); } int palindrome(char a[ ]) { int n,i; n=count(a); n=n-1; i=0; for(;a[n]==a[i] && n>=i;i++,n--); if(n>=i) return 0; else return 1; } void main( ) { char a[80],b[80],s; int n; printf("\n check palindrome"); input(a); n=palindrome(a); output(a); if(n==1) printf("\n palindrome"); else printf("\n not palindrome"); getch(); }


Is glockenspiel a palindrome?

No, it isn't a palindrome.


What is the palindrome of balanced?

The palindrome is Level.


What is the palindrome of 14?

There is no palindrome for 14.


Which 4 digit number is always a palindrome?

Any number that is is a palindrome will always be a palindrome.


Is 107541 a palindrome?

No. A palindrome reads the same backwards and forwards. 5791111975 is an example of a palindrome.


How are the expanded algorithm and the standard algorithm different?

They are different because standard algorithm is more common then the expanded algorithm


What is the palindrome of 1998?

1998 is not and cannot be a palindrome.


What is the palindrome for detector?

"radar" is a palindrome for detector.