r/dailyprogrammer • u/mattryan • Mar 22 '12
[3/22/2012] Challenge #29 [easy]
A Palindrome is a sequence that is the same in reverse as it is forward.
I.e. hannah, 12321.
Your task is to write a function to determine whether a given string is palindromic or not.
Bonus: Support multiple lines in your function to validate Demetri Martin's 224 word palindrome poem.
Thanks to _lerp for submitting this idea in /r/dailyprogrammer_ideas!
13
Upvotes
3
u/Kanos Mar 22 '12 edited Mar 22 '12
Java. Disregards all spaces and punctuation after reading from a file(I used Demetri Martin's palindrome poem).
2
u/gjwebber 0 0 Mar 22 '12 edited Mar 22 '12
Python:
2
u/Yuushi Mar 22 '12
Haskell:
Which should validate the poem.
2
u/met48 Mar 22 '12 edited Mar 22 '12
Python, with bonus:
*Edited regex
2
u/DanielJohnBenton 0 0 Mar 22 '12
A lot of fantastic few-liners. I won't try to compete. I noticed nobody implemented it in PHP, so here's my contribution.
Output:
2
u/ixid 0 0 Mar 22 '12
The bonus points version in D:
2
u/Music_Man94 Mar 23 '12
10 Line Input"Enter a number : ",A$ 20 L=Len(A$) 30 For I=L to 1 Step -1 40 B$=B$+MID$(A$,I,1) 50 Next I 60 If A$=B$ then (It is a palindrome)
I've just started learning this... I love working with computers but only know GW. Sorry, please don't laugh.
2
u/Xlator Mar 26 '12 edited Mar 26 '12
C#
3
u/Steve132 0 1 Mar 23 '12
C++ is usually considered to be a verbose language, I just wanted to show that it can do one-liners like perl and python too!
2
u/luxgladius 0 0 Mar 22 '12
Perl
2
u/stevelosh Mar 22 '12
Clojure:
Handles punctuation, mixed case, whitespace, etc. Doesn't handle non-english characters like é.
1
u/thatrandomusername Mar 22 '12
Javascript
1
u/[deleted] Mar 22 '12
Perl
1
u/julrocas Mar 22 '12
ANSI C :) :
int main(int argc, char** argv) { char word[30]; int n,verified,i; printf("Enter a word: "); scanf("%s",word); n=strlen(word); if ((n%2)==1) n=(n-1)/2; else n=n/2; verified=1; i=0; while ((verified==1)&&(n>i)){
}
1
u/namekuseijin Mar 22 '12 edited Mar 22 '12
; palindrome poem from http://www.pastemagazine.com/articles/2009/02/demetri-martins-palindrome-poem.html ; http://www.reddit.com/r/dailyprogrammer/comments/r8a70/3222012_challenge_29_easy/ ; not quite so easy when your language is quite bare. This is R5RS scheme
1
u/magwhich Mar 23 '12
python
1
u/rudymiked Mar 23 '12
C++ (with while loop)
1
u/lullabysinger Mar 23 '12
Perl, with support for Demetri Martin.
1
u/Zamarok Mar 23 '12 edited Mar 23 '12
Haskell:
It's efficient because it returns false as soon as it finds a non palindrome without the need to reverse the list first or something.
1
u/drb226 0 0 Mar 23 '12
Pointless Haskell! (Compare original to similar solutions in Python, Clojure, Perl)
Thanks, lambdabot! So readable ;) Throwing in
fixis always fun.1
u/JerMenKoO 0 0 Mar 24 '12
Python 3.x, w/o bonus now:
1
u/cooper6581 Mar 24 '12
Python. Not as clever as some of the other ones, bonus works if passed in as the first argument.
1
u/just_news Mar 26 '12 edited Mar 26 '12
1
u/JerMenKoO 0 0 Apr 09 '12
J:
1
u/DisasterTourist May 10 '12
Java. Complete with a while loop and some if statements.
1
u/[deleted] Mar 22 '12
In java:
0
u/[deleted] Mar 22 '12
[deleted] — view deleted comment