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
7
votes
13 answers

How to check for palindrome in Swift using recursive definition

I like many of the features in Swift, but using manipulating strings are still a big pain in the ass. func checkPalindrome(word: String) -> Bool { print(word) if word == "" { return true } else { if word.characters.first…
funct7
  • 3,407
  • 2
  • 27
  • 33
7
votes
2 answers

How can I detect a palindrome in Hebrew?

I am writing a series of tests for a palindrome solver. I came across the interesting palindrome in Hebrew: טעם לפת תפל מעט Which is a palindrome, but the letter Mem has both a regular form (מ) and a "final form" (ם), how it appears as the last…
6
votes
0 answers

Stream variant of the Longest palindromic substring

Suppose I have a character stream as my input. What is the most optimal way to find the longest palindromic substring after each new character is added without reprocessing the whole string all over again? After each new character comes in, I…
user78706
6
votes
6 answers

Finding palindromes in a linked list

This is an interview question(again). Given a singly connected linked list, find the largest palindrome in the list. (You may assume the length of the palindrome is even) The first approach I made was using a stack - we traverse over the list…
letsc
  • 2,075
  • 5
  • 24
  • 43
6
votes
2 answers

Optimized way for checking if the given number is a Palindrome

I wrote two functions to check if a number (Integer) is a Palindrome or not. The first function reverses the number without affecting the datatype whereas the second function converts the numbers into string, reverses the string, then converts it…
Gagan Deep Singh
  • 372
  • 3
  • 13
6
votes
7 answers

Python reverse() for palindromes

I'm just getting started in python, and I'm trying to test a user-entered string as a palindrome. My code is: x=input('Please insert a word') y=reversed(x) if x==y: print('Is a palindrome') else: print('Is not a palindrome') This always…
Matthew Sainsbury
  • 1,470
  • 3
  • 18
  • 42
6
votes
1 answer

Loop Counting Scoping In Python

I'm trying to figure out how this code works. How is i accessible outside the for loop? # Palindrome of string str=raw_input("Enter the string\n") ln=len(str) for i in range(ln/2) : if(str[ln-i-1]!=str[i]): break if(i==(ln/2)-1): …
Kittystone
  • 661
  • 3
  • 9
  • 28
6
votes
2 answers

Why will this recursive regex only match when a character repeats 2^n - 1 times?

After reading polygenelubricants's series of articles on advanced regular expressions techniques (particularly How does this Java regex detect palindromes?), I decided to attempt to create my own PCRE regex to parse a palindrome, using recursion (in…
Daniel Vandersluis
  • 91,582
  • 23
  • 169
  • 153
6
votes
13 answers

Puzzled over palindromic product problem

I've been learning Ruby, so I thought I'd try my hand at some of the project Euler puzzles. Embarrassingly, I only made it to problem 4... Problem 4 goes as follows: A palindromic number reads the same both ways. The largest palindrome made …
fletcher
  • 13,380
  • 9
  • 52
  • 69
6
votes
5 answers

Decide(in Haskell) if a number is or not a palindrome without using lists

I need to check in Haskell if a four digit number is a palindrome, the problem is that I can't use lists, and in spite of having a fixed digit number, I should use recursion. I have been think on the problem and I couldn't get a solution using…
Iván Rodríguez Torres
  • 4,293
  • 3
  • 31
  • 47
6
votes
7 answers

The fastest method of determining if a string is a palindrome

I need an algorithm that verify with the fastest possible execution time, if a string is a palindrome ( the string can be a proposition with uppercase or lowercase letter, spaces etc.). All of this in Java. I got a sample : bool isPalindrome(string…
Bogdan Mursa
  • 63
  • 1
  • 2
  • 10
6
votes
2 answers

Understanding difference lists (Prolog)

I'm having trouble understanding difference list, particularly in this predicate: palindrome(A, A). palindrome([_|A], A). palindrome([C|A], D) :- palindrome(A, B), B=[C|D]. Could anyone help me follow what's happening?
user2796815
  • 465
  • 2
  • 11
  • 18
6
votes
5 answers

if given a 15 digit number whats the best way to find the next palindrome?

in c++ what will be the fastest logic to find next palindrome of a given 15 digit number? for example what will be the next palindrome of: 134567329807541 ?
Vaibhav
  • 6,620
  • 11
  • 47
  • 72
6
votes
2 answers

need algorithm to find the nth palindromic number

consider that 0 -- is the first 1 -- is the second 2 -- is the third ..... 9 -- is the 10th 11 -- is the 11th what is an efficient algorithm to find the nth palindromic number?
Merna
  • 269
  • 1
  • 5
  • 14
6
votes
4 answers

Create palindrome from existing string by removing characters

How do i determine the length of the longest palindrome you can get from a word by removing zero or more letters. for eg : amanQQQapl12345anacaZZZnalpaXXXna67890ma longest palindrome will be of 21 digits.
Nitin Kabra
  • 3,146
  • 10
  • 43
  • 62