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

Prolog - Palindrome Functor

I am trying to write a predicate palindrome/1 in Prolog that is true if and only if its list input consists of a palindromic list. for example: ?- palindrome([1,2,3,4,5,4,3,2,1]). is true. Any ideas or solutions?
Amjad
  • 1,627
  • 5
  • 21
  • 41
5
votes
1 answer

Hackerrank - Solving Palindrom Index Solution

Problem: Given a string of lower case letters in the range ascii[a-z], identify the index of character to be removed to change the string into a palindrome. If the string cannot be converted to palindrome or is already a palindrome just return -1…
Waleed
  • 63
  • 1
  • 1
  • 6
5
votes
2 answers

Find palindromes in list

Assume we have a list of integers, for example: L = [13,13,4,13,4,2] I want to find the set of all palindromes, where each palindrome is a sub-list of L containing contiguous integers. For the above list that would be: S = {[13], [4], [2], [13,13],…
oiale
  • 67
  • 1
5
votes
3 answers

Finding the largest palindrome in string implementation

I'm trying to solve a problem that asks to find the largest palindrome in a string up to 20,000 characters. I've tried to check every sub string whether it's a palindrome, that worked, but obviously was too slow. After a little googling I found this…
Marijus
  • 4,195
  • 15
  • 52
  • 87
5
votes
9 answers

Recursive palindrome check with JavaScript

I am trying to find out whether a string is a palindrome by recursion using javascript. But I can't figure out what I am missing in the code. var firstCharacter = function(str) { return str.slice(0, 1); }; var lastCharacter = function(str) { …
Niaz Ahsan
  • 351
  • 1
  • 7
  • 21
5
votes
3 answers

Check if a number is a palindrome without changing it into string

I'm having trouble with this problem that simply return True of False if a number n, is a palindrome. Note: wherever I have a ____ indicates where there is a blank that needs to be filled in. There are 2 blank spaces. def is_palindrome(n): x,…
user9873466
  • 95
  • 1
  • 5
5
votes
3 answers

dictionary with palindromes to non palindromes?

I am sorry if this is too easy but I can't figure out how to build this dictionary. I have a string for example "Bob and Anna are meeting at noon" and I want a dictionary with all palindromes pointing to a list of the following not-palindromes,…
Flo
  • 67
  • 9
5
votes
2 answers

std::_throw_out_of_range occurs from nowhere

I'm an absolute beginner in c++. Literally. It's just been a week. Today I was writing a program to test how many iterations are needed to make a certain number palindromic. Here is the code: #include #include #include…
5
votes
9 answers

Finding the largest palindrome of the product of two three digit numbers problem

So on Project Euler the Problem 4 states the following: A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99. Find the largest palindrome made from the product…
thyrgle
5
votes
5 answers

Optimizing the largest palindrome from product of two three digit numbers?

I am working on an interview question which I was asked in which I was supposed to write a program to find the largest palindrome from product of two three digit numbers. Here is the question I came up with this brute force approach which starts…
john
  • 11,311
  • 40
  • 131
  • 251
5
votes
2 answers

remove both commas and white space ruby

I am new to ruby and my regex knowledge leaves a lot to be desired. I am trying to check if a string is a palindrome, but wish to ignore white space and commas. The current code I have is def palindrome(string) string = string.downcase string =…
Paul Fitzgerald
  • 11,770
  • 4
  • 42
  • 54
5
votes
8 answers

Determine if a given string is a k-palindrome

I'm trying to solve the following interview practice question: A k-palindrome is a string which transforms into a palindrome on removing at most k characters. Given a string S, and an integer K, print "YES" if S is a k-palindrome; …
Brandon
  • 1,029
  • 3
  • 11
  • 21
5
votes
8 answers

Palindrome Checker using StringBuilder

Im trying to create a palindrome checker. I am using a StringBuilder and I've discovered that appending spaces are kind of tricky. EDIT: are there other ways besides using .reverse()? Thanks for the answers. :D This code works when the word has no…
user1993177
  • 573
  • 2
  • 6
  • 9
5
votes
4 answers

For-loops in Python 3.0

I am currently working on a palindrome-detector (anna, lol, hahah etc) and I am requested to use for-loops. I want the program to loop through two strings (read them regularly and backwards at the same time while comparing the values). If the values…
user1916173
  • 61
  • 1
  • 6
5
votes
5 answers

How to calculate nth n-digit palindrome efficiently?

I think the question is simple enough to understand.For more clarity I'm giving example : In the list of 2 digit palindromes, the 7th palindrome is 77 (1st being 11, 2nd being 22 and so on). Obviously a brute force solution exists but it's not…
dark_shadow
  • 3,503
  • 11
  • 56
  • 81