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
5
votes
3 answers

How does regular expression engine parse regex with recursive subpatterns?

This regular expression matches palindromes: ^((.)(?1)\2|.?)$ Can't wrap my head around how it works. When does the recursion end, and when regex breaks from the recursive subpattern and goes to "|.?" part? Thanks. edit: sorry I didn't explain \2…
alexy2k
  • 560
  • 1
  • 6
  • 10
5
votes
2 answers

Is my code efficient for finding out the next palindrome given a positive integer?

Problem statement: For a given positive number, I have to find out the immediately next palindrome. Eg: For 808, output:818 2133, output:2222 I want to know if my code is efficient at all, and how efficient is it? Is this a good way to solve the…
karan k
  • 947
  • 2
  • 21
  • 45
4
votes
2 answers

Convert Prolog functor to functor with difference lists

I'm working on my homework for Prolog (SWI) but can't figure out how to get this done: I have the functor: palindrome([]). palindrome([_]). palindrome([A|T]) :- append(Middle,[A],T), palindrome(Middle). which tells if a given list is a…
Waarten
  • 115
  • 6
4
votes
5 answers

Why does the following Clojure not detect a palindrome?

I'm just trying to convert to a string and compare to the reverse (defn is-palindrome? [num] (= (str num) (reverse (str num)))) Something like (is-palindrome 1221) Is returning false
deltanovember
  • 42,611
  • 64
  • 162
  • 244
4
votes
4 answers

Loops and Stacks, palindrome homework assignment

I'm working on an assignment for my programming class but I've run into some difficulty and I'm not sure where else to look. Basically the question asks that we write a program that checks for palindromes. The user enters text (No non-alphanumberic…
Eogcloud
  • 1,335
  • 4
  • 19
  • 44
4
votes
2 answers

Efficient way to get longest palindrome subsequence in a string

I'm trying to implement a function that takes a string as input and returns the longest palindrome subsequence in the string. I've tried using dynamic programming and have come up with the following code: function longestPalindromicSubsequence(str)…
user21196765
4
votes
1 answer

How can I generate prime palindromes in a given range without complete searching it and using a check function?

I have seen previous solutions to this problem, but it is all complete search with a check function and not fast enough for me. I am working on a C++ program trying to generate all prime palindromes highly efficiently in a given range of integers.…
Hudson
  • 312
  • 2
  • 18
4
votes
3 answers

Finding longest but lexicographically smallest palindrome in case of more than one palindromes

Given a string, I need to find the longest palindrome that can be constructed by removing or shuffling characters from the string. If more than one palindrome exists of same length then I need to make ensure that lexicographically smallest one is…
Gaurav Gupta
  • 99
  • 1
  • 2
  • 5
4
votes
2 answers

Count how many palindromes in a string

I want to find out all possible palindromes that can be possible using substrings from a given string. Example: input = abbcbbd. Possible palindromes are a,b,b,c,b,b,d,bb,bcb, bbcbb,bb Here is the logic I have implemented: public int…
learner
  • 6,062
  • 14
  • 79
  • 139
4
votes
1 answer

How to remove all non-alphabet characters, javascript

I am asked to check if a string is a Palindrome. To not be case sensitive. To ignore all characters that are not letters. My Answer function palindrome(str) { var oldStr = str.toLowerCase().replace(/\s+|\,|\.|\_|\-|\:|\(|\)|\/|\\/g, ''); var…
Chuck
  • 248
  • 5
  • 13
4
votes
6 answers

Python: Iterating through the columns in a list of list to find the palindromes

Here I have a word list as: [['r', 'o', 't', 'o', 'r'], ['e', 'v', 'e', 'i', 'a'], ['f', 'i', 'n', 'e', 'd'], ['e', 'n', 'e', 't', 'a'], ['r', 'a', 't', 'e', 'r']] And I have to display all the palindromes in this list which are in rows as well as…
eye
  • 91
  • 1
  • 3
  • 14
4
votes
1 answer

How to choose the next center in the longest palindrome algorithm?

This is a question about the longest palindrome algorithm discussed here some time ago. The quoted blog post, which explains the algorithm, says: "to pick the next center, take the center of the longest palindromic proper suffix of the current…
Michael
  • 41,026
  • 70
  • 193
  • 341
4
votes
21 answers

Creating a recursive method for Palindrome

I am trying to create a Palindrome program using recursion within Java but I am stuck, this is what I have so far: public static void main (String[] args){ System.out.println(isPalindrome("noon")); System.out.println(isPalindrome("Madam I'm…
Nightshifterx
  • 51
  • 1
  • 1
  • 4
4
votes
2 answers

Checking if digits in a string are symmetric (in edges)

I have a string of numbers. I need to check if the numbers on the edges are symmetric, meaning they have the same remainder when modulo by 2. I have written a code which works, but I have something troubling my mind about that, after some failures…
Ilan Aizelman WS
  • 1,630
  • 2
  • 21
  • 44
4
votes
5 answers

Palindrome Checker in JavaScript - don't know how to debug

I want to build a palindrome checker in javascript. All non-letter characters should be removed, so that a phrase like "A man, a plan, a canal. Panama" can also be a palindrome. function reverse(str) { return…
k_rad
  • 59
  • 6