Questions tagged [palindrome]

A word, phrase, number, or other sequence of units that may be read the same way in either direction, forward or backward.

A word, phrase, number, or other sequence of units that may be read the same way in either direction, forward or backward.

Spacing and punctuation is generally ignored when attempting to determine whether the potential palindrome under consideration is in fact a palindrome. One such example is:

I, madam, I, made radio - so I dared! Am I mad? Am I?

(from http://www.joe-ks.com/palindromes.htm)

1763 questions
3
votes
2 answers

isPalindrome function in Haskell gives an error

I was trying to write a program that checks whether a list is palindrome and returns Bool. isPalindrome :: [a] -> Bool isPalindrome [] = True isPalindrome [x] = True isPalindrome xs | (head xs) == (last xs) = isPalindrome (init(tail xs)) …
Piamoon
  • 95
  • 1
  • 7
3
votes
2 answers

How to use/modify Knuth-Morris-Pratt algorithm to convert any given string to palindrome

I have been given a task to create a class that given a String will create a palindrome with minimum number of assertions. Example Runs: Input: 123333 Output: 12333321 Input: 789 Output: 78987 Input: 1221 Output: 1221221 **Note a Palindrome…
Reemz
  • 51
  • 4
3
votes
3 answers

Stack level too deep in recursion for largest palindrome product question (Project Euler)

I'm trying to implement a recursive solution to the largest palindrome product problem What I'm trying to do is start both numbers at 999 and iterate down to 100 for num1 and then restart num1 at 999 and iterate num2 down by 1. The goal is…
user392500
  • 37
  • 8
3
votes
1 answer

Why does the string 'xabcx' return as a palindrome in my method? (Ruby)

I'm going through some exercises on App Academy Open, and I've come across a test case that I can't quite figure out. I've written a method to detect if a given string is a palindrome or not, and it seems to work fine for all strings I've thrown at…
nashsibanda
  • 31
  • 1
  • 4
3
votes
1 answer

How to make an accent insensitive palindrome checker in MIPS?

I am writing a palindrome checker in MIPS, and I was trying to make it accent insensitive so that something like "ahà" would be considered a palindrome too. However, it doesn't look so simple as the case insensitive scenario where there is a fixed…
spiky
  • 31
  • 2
3
votes
15 answers

Euler problem number #4

Using Python, I am trying to solve problem #4 of the Project Euler problems. Can someone please tell me what I am doing incorrectly? The problem is to Find the largest palindrome made from the product of two 3-digit numbers. Here is what I have…
marc lincoln
  • 1,551
  • 4
  • 21
  • 25
3
votes
3 answers

Why is my palindrome function not working?

For some reason my palindrome function is not working, I'd love some help on it: Code int Pal(char *s, int a, int b) { if (a>= b) return 1; if (s[a] != s[b]) return 0; return Pal(s, ++a , --b); } int main() { …
Faisal
  • 159
  • 9
3
votes
4 answers

Efficient way to determine whether an input string is a palindrome or not

I recently wrote this short method to determine whether a string is a palindrome. I was wondering what I could do to make it more efficient, surely I'm missing simple built-in functions that can speed up the calculation. Thank you all for your…
user9237783
3
votes
6 answers

JS How to for palindrome

The question I have been given is this; create a function that takes an array of words and returns an array containing only the palindromes. A palindrome is a word that is spelled the same way backwards. E.g. ['foo', 'racecar', 'pineapple',…
Geo
  • 439
  • 2
  • 5
  • 15
3
votes
1 answer

Palindrome checker that ignores non-alphanumeric characters and case Haskell

Need to make a program that checks if a given string is a palindrome, it should work whether the case is different, and should ignore non-alphanumeric characters, only using the ord and chr functions in Data.char and regular functions, nothing else.…
Intellects
  • 57
  • 5
3
votes
1 answer

Python: finding all pallindromic sequences of length k that sum to n

I'm trying to find all palindromic sequences of length k that sum to n. I have a specific example (k=6): def brute(n): J=[] for a in range(1,n): for b in range(1,n): for c in range(1,n): if (a+b+c)*2==n: …
jonan
  • 217
  • 1
  • 8
3
votes
3 answers

palindrome error with 8 or 9 letters

I have the following code, when going through the python, the options aaabaaaa, zzzazzazz gave me the false test.Here is the code, I am not too sure on how to fix it. def checkPalindrome(inputString): n=len(inputString) #if string is one…
M-M
  • 881
  • 2
  • 10
  • 19
3
votes
2 answers

Palindromic pairs in an array of words

I came across a code for palindromic pair problem, using Trie. public static class Trie { int pos; Trie[] nodes; // consider xyxabc. if current trie is 'a'. Then a.nodes has information. It means string after a is palindrome …
Aman
  • 159
  • 2
  • 15
3
votes
2 answers

Recursion Function Isn't Working

Okay, so I'm trying to make a recursive function that returns True if the function is a palindrome, and False otherwise. However, it doesn't go to the very end, and randomly stops. Code: def is_palindrome(word): if len(word) == 1 or len(word)…
user8681590
3
votes
1 answer

Finding the longest palindromic substring (not subsequence)

I am doing the Leetcode question of Find the Longeest Palindromic Substring. For example if the input babad then the output can be bab or aba. OR if the input is cbbd then the output is bb. I'm pretty sure I have it figured out, this is my…
buydadip
  • 8,890
  • 22
  • 79
  • 154