Output only the palindromic words

Hello everyone! The Brain Teaser series continues.

First, we would like to announce the winner of the previous brain teaser. We got a number of very interesting and creative solutions. The shortest answer — [Net.DNS]::GetHostAddresses(“”), with 31 characters — was given by sahal. So, he is the winner!

Congratulations sahal, you get an eBook version of Microsoft Windows PowerShell 3.0 First Look written by Adam Driscoll and published by Packt.

We would like to thank Joel ‘Jaykul’ Bennett for the new brain teaser.

You have an array of words: ‘Hannah’,’Jeffrey’,’12321′,’Madam’,’Abracadabra’. Your new task is to output only palindromic words.

The input is: ‘Hannah’,’Jeffrey’,’12321′,’Madam’,’Abracadabra’
The output is:

Once again, the shortest answer wins! Be aware, a space is a character too.
Please use the comment box at the bottom of this page to submit your solutions by Friday. The winner will be announced on the next Monday.

Don’t have a solution of your own or has it already been posted by others? You can still participate and add your voice by voting on the existing comment by using the up/down voting arrows.

This time, the prize is again the eBook version of Microsoft Windows PowerShell 3.0 First Look written by Adam Driscoll. We would like to thank our sponsor Packt, one of the most prolific and fast-growing tech book publishers in the world, for providing such a cool prize.

Good luck!

About the author: Aleksandar Nikolic

Aleksandar is a PowerShell MVP and a co-founder of PowerShell Magazine. He is a frequent speaker at the conferences and participates regularly in IT Pro user groups worldwide. Recently, Aleksandar co-authored the highly respected Administrator’s Guide to Windows PowerShell Remoting. Follow him on Twitter at @alexandair

Related Posts


    1. ‘Hannah’,’Jeffrey’,’12321′,’Madam’,’Abracadabra’|?{$OFS=”;”$($_[-1..-$_.Length])”-eq$_}

      Also works if you wanted to self-contain the $OFS=”

    1. ‘Hannah’,’Jeffrey’,’12321′,’Madam’,’Abracadabra’|?{-join$_[-1..-50]-eq$_}

      Turns out you don’t need the exact length of the string.

        1. ‘Hannah’,’Jeffrey’,’12321′,’Madam’,’Abracadabra’|?{-join$_[-1..-189819]-eq$_}

          That should be able to cover the longest know word in the English language. The description says we have an array of words. It is incredibly slow but you still don’t have to use the exact length. “-189819” is still shorter than “$_.Length”. (http://en.wikipedia.org/wiki/Longest_word_in_English) 🙂

  1. Different approach:


Comments are closed.