The goal: Any language. The smallest function which will return whether a string is a palindrome. Here is mine in Python:
R=lambda s:all(a==b for a,b in zip(s,reversed(s)))
50 characters.
The accepted answer will be the current smallest one - this will change as smaller ones are found. Please specify the language your code is in.
...
That was an interview question that I was unable to answer:
How to check that a string is a palindrome using regular expressions?
p.s. There is already a question "How to check if the given string is palindrome?" and it gives a lot of answers in different languages, but no answer that uses regular expressions.
...
I got curious by Jon Limjap's interview mishap and started to look for efficient ways to do palindrome detection. I checked the palindrome golf answers and it seems to me that in the answers are two algorithms only, reversing the string and checking from tail and head.
def palindrome_short(s):
length = len(s)
for i in xrange(0,lengt...
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 thus far.
import math
def main():
for z in range(100, 1000):
for y in range(100,...
So the puzzle is to write a hello world program in your language of choice, where the program's source file as a string has to be a palindrome.
To be clear, the output has to be exactly "Hello, World".
Edit:
Well, with comments it seems trivial (not that I thought of it myself of course [sigh].. hat tip to cobbal).
So new rule: no...
i have a problem with my program. It should be program that recognize palindome through the stack. Everything works great, only thing that don't work is printing stacks(original and reversed) after the funcion is done.
Here is my entire code, and the problem is at case d and e:
#include <iostream>
using namespace std;
const int MAXST...
How to check if the binary representation of an integer is a palindrome?
...
I need help writing a recursive function which detects whether a string is a palindrome. But i can't use any loops it must be recursive. Can anyone help show me how this is done. I need to learn this for an upcoming midterm. Im using Python.
...
e.g "ccddcc" in the string "abaccddccefe"
I thought of a solution but it runs in O(n^2) time
Algo 1:
Steps:
Its a brute force method
Have 2 for loops
for i = 1 to i less than array.length -1
for j=i+1 to j less than array.length
This way you can get substring of every possible combination from the array
Have a palindrome fu...
I am working on Project Euler question 4, and need to find the palindrome of the product of 2 3 digit numbers, so I came up with:
palindrome = [ x*y | x <- [100..999], y <- [100..999], reverse [x*y] == [x*y]]
Why doesn't this work and how can I make it work?
I suspect I need to somehow get the answer into a list so that it be reverse...
I have the following homework assignment:
I need to create a program that recursively tests in a word or phrase is a palindrome. Here is the prompt:
A palindrome is "a word, line, verse, number, sentence, etc., reading the same backward as forward, as Madam, I'm Adam or Poor Dan is in a droop." (dictionary.com) When evaluating palin...
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 ?
...
I have the program made up until the point where it has to ignore and punctuations and spaces in the thread and I was wondering if anyone could help me with the coding for that? What I've been trying out doesn't seem to be working. Here is what I have so far:
import java.util.Scanner;
public class PalindromeTester
{
public static void ...
public static boolean palindrome(String input, int i, int j)
{
if (i >= j)
return true;
if (input.charAt(i) == input.charAt(j))
{
i++;
j--;
palindrome(input, i, j);
}
else if (input.charAt(i) != input.charAt(j))
return false;
}
My Java platform (eclipse) won't accept this code as working, due to a "lack of re...
I had a question regarding a basic program I was writing said whether a word such as racecar is a palindrome or not.
All my methods which reverse the string, strip the punctuation work but the one that determines if it is a palindrome does not.
/**
* Determines if a series of letters makes a palinedrome
*
* @param str All punctuat...
Is it a good idea to check for odd/even length of a palindrome number/string? Most snippets I came across don't do this basic test. If length is even, it can't be a palindrome, no?
if len(var) % 2 != 0:
# could be a palindrome, continue...
else:
break
Or is it just better (i.e faster) to start comparing the first and last numbers...
I'm creating a program that checks if a word or phrase is a palindrome. I have the actual "palindrome tester" figured out. What I'm stuck with is where and what to place in my code to have the console read out "Enter palindrome..." and then text. I've tried with IO but it doesnt work out right. Also, how do I create a loop to keep go...
My program checks to test if a word or phrase is a palindrome (reads the same both backward and forward, ex "racecar"). The issue I'm having is after someone enters in "racecar" getting it to actually test. In the below code, I marked where if I type in "racecar" and run, Java returns the correct answer so I know I'm right there. But ...
Possible Duplicate:
Write a function that returns the longest palindrome in a given string
I know how to do this in O(n^2). But it seems like there exist a better solution.
I've found this, and there is a link to O(n) answer, but it's written in Haskell and not clear for me.
It would be great to get an answer in c# or simila...
Hello all
I got this question which asks me to figure out why is it foolish to write a regular expression for the language that consists of strings of 0's and 1's that are palindromes( they read the same backwards and forwards).
part 2 of the question says using any formal mechanism of your choice, show how it is possible to express t...