The Palindrome Project

This page is a compilation of Palindrome checkers implemented in various programming languages. To view a particular implementation, choose a language from the drop-down select list below. The page should be updated to display the source code for the chosen language, with syntax highlighting applied. A second drop-down can be used to choose another language implementation to display in a separate window. More details about the project appear at the end of the page.

Source Language:
Compare with: (new window)

(please ensure JavaScript is enabled)

About the Palindrome Project: an exercise in comparative linguistics

This page brings together the results of a little hobby that's been developing slowly over the past few years whenever I found some spare time: solving a straight-forward problem in a variety of different programming languages. The problem is a staple in university computer science courses, namely to determine if a string is a palindrome. Example palindromes include: "A man, a plan, a canal: Panama!" and "Madam, I'm Adam". Palindromes are not limited to letters, so numbers can be palindromes (e.g. "16461"). By the way, when I started learning Java, one of the first programs I wrote was a rewrite of a palindrome detector originally written in Ada for a Uni assignment. That approach used recursion to successively compare characters at each end of the string, from the outside in.

For this project I've chosen a different approach, which may suit some programming languages better than others. Here's the outline for the general approach used in all the example programs:

  1. Prompt the user to input a string to test.
  2. Convert the user's input to uppercase.
  3. Remove any non-alphanumeric characters, i.e. we're only interested in letters and numbers.
    (The intent of steps 2 and 3 is to ensure that punctuation, capitalisation, and spacing are ignored.)
  4. Reverse the "stripped" string.
  5. Compare the reversed and stripped strings, reporting whether or not the user input is a palindrome.

Where possible I've conformed to the idioms and conventions of each language. To help comparison of implementations, I've tried to use the same key variable names (e.g. for the intermediate strings in the outline above), even if camelcase is not typical for all languages. Given my limited experience, many implementations may not be optimal or strictly idiomatic for the relevant language.

The languages span several decades of computer programming history. Most of the major paradigms are represented: procedural, object-oriented, functional, logic-based, stack-oriented and array-based. There's a mix of compiled and interpreted, static and dynamic, specific- and general-purpose, and several that are considered hybrid or multi-paradigm languages.

To browse an implementation, choose a language from the drop-down select list provided. The page should be updated to display the source code for the chosen language, with syntax highlighting applied. To aid comparison with other languages, a second drop-down select list is available for choosing another language. Just pick a different language, click on the "Compare" link, and its implementation will be displayed in a new window.

This page uses jQuery to do some dynamic layout magic. Syntax highlighting is done using SHJS - Syntax Highlighting in JavaScript. Check the comments at the top of each implementation for other relevant information and links.

Many of the implementations can be run using either the Online IDE & Debugging Tool at, or Try It Online (TIO). Steps:

  1. Copy the code for the desired language.
  2. Go to or Try It Online.
  3. Choose the appropriate language from the list.
  4. Paste the code into the large text area.
  5. Click on the link below the code area and enter some text to pass as input or "stdin" (i.e. the text to test).
  6. Click on the submit/run button.

Go back to the top.

Last updated: January 24, 2022