Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm trying to find the palindromes in the dictionary, but my output isn't giving me all of them.

I have this so far

Palindrome[] := DictionaryLookup[y_ /; (y == StringReverse[y])]
Palindrome[]

And my the output just it gives me {a,I}. What's wrong with my input? I don't see it.


Thanks.

share|improve this question
    
Two underscores after your y should help –  bobthechemist Oct 22 '13 at 0:37
1  
Palindrome[] := DictionaryLookup[y__ /; (y == StringReverse[y])] –  bobthechemist Oct 22 '13 at 0:38
    
Ah okay thanks. Why did I need two underscores? I read the reference on wolfram, but I'm not sure how it applies here. –  jas Oct 22 '13 at 0:51
    
A single underscore is for a single character, and double underscore is for one or more. –  bobthechemist Oct 22 '13 at 0:55
    
So by character, you mean the double underscore is applied to the y and that would give me more than a one letter word? –  jas Oct 22 '13 at 0:58
show 1 more comment

1 Answer

up vote 4 down vote accepted

As mentioned in the comments, to search for multi-letter palindromes, two underscores are needed as described in the help for string patterns:

Palindrome[] := DictionaryLookup[y__ /; (y == StringReverse[y])]

Now, Mathematica is probably not good enough to come up with lyrical palindromes.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.