palindrome

Count double palindromes in given int sequence

For a given int sequence check number of double palindromes, where by double palindrome we mean sequence of two same palindromes without break between them. So for example: in 1 0 1 1 0 1 we have 1 0 1 as a palindrome which appears 2 times without a break, in 1 0 1 5 1 0 1 we have 1 0 1 but it's separated (apart from the other palindr...

Why does this simple Python script reveal the incorrect answer?

I'm again working on Project Euler, this time problem #4. The point of this script is to find the largest palindromic product of two three digit numbers. I thought it was fairly straightforward to solve, but I'm getting an answer that is too low. More specifically, I am getting 580085, and the answer is 906609. Could someone tell me wh...

Puzzled over palindromic product problem

Hi, 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 from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest p...

Checking for palindrome string in c

I am accepting a string as a command line argument. I want to check whether the inputted string is a palindrome or not and print the result. I have written the following code. But its displaying the result 'not palindrome' for all inputs. #include<stdio.h> #include<string.h> int main(int argc, char argv[20]) { int i; int l = st...

How does this Java regex detect palindromes?

This is the third part in a series of educational regex articles. It follows How does this regex find triangular numbers? (where nested references is first introduced) and How can we match a^n b^n with Java regex? (where the lookahead "counting" mechanism is further elaborated upon). This part introduces a specific form of nested as...

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 PHP). What I came up with was: ^(([a-z])(?1)\2|[a-z]?)$ My understanding of this expr...

How does this PCRE pattern detect palindromes?

This question is an educational demonstration of the usage of lookahead, nested reference, and conditionals in a PCRE pattern to match ALL palindromes, including the ones that can't be matched by the recursive pattern given in the PCRE man page. Examine this PCRE pattern in PHP snippet: $palindrome = '/(?x) ^ (?: (.) (?= ...

Reverse digits in R

How can you reverse a string of numbers in R? for instance, I have a vector of about 1000 six digit numbers, and I would like to know if they are palindromes. I would like to create a second set which is the exact reverse, so I could do a matchup. ...

Weird cocoa bug?

Hey folks, beneath is a piece of code i used for a school assignment. Whenever I enter a word, with an O in it (which is a capital o), it fails! Whenever there is one or more capital O's in this program, it returns false and logs : sentence not a palindrome. A palindrome, for the people that dont know what a palindrome is, is a word tha...

Palindrome in C without pointers and recursion

I'm trying to determine if a phrase is a palindrome (a word that is the same from left to rigth) or not but i can't make it work. What's wrong?, i can't use pointers or recursion or string type variables #include <stdio.h> #include <string.h> int main() { int i,j = 0,length; char space = ' '; char phrase [80],phrase2[80],phrase3[...

How can I optimise my awful code for finding the highest palindrome of a 3 digit number ?

This is what I have written so far. It compiles, and, as far as I can tell, it should 'work' - if you were to give your computer an infinite amount of time to compute the answer ! I was just wondering if anyone would please be able to give me a way to optimise this so that my program will tell me the highest palindromic number (the sam...

Can I please get some feedback on this `isPalindrome()` function in C?

I'm writing some useful functions in C. One of them is isPalindrome(). I figured to determine if a number is a palindrome or not, I should... get all digits in an array iterate through with two indexes - start one at 0 and one to the array count increment/decrement the indexes whilst subscripting the array whilst they match and if the...