Erlang Example: Find the Maximum Palindrome Length

A palindrome is a string that is equal to its reverse. The problem here is to find the longest part of a given string that is a palindrome. For instance, the answer is 3 for aacbcx, because cbc is a palindrome, and there is no longer instance. The following program is based on the observation that if x>2 is the length of the longest palindrome, then there must also be a palindrome of length x-2 within the same input word.

Further explanation was presented in class.

In class, we worked out how to make this program concurrent, by making genMax into a process. This was the result:

(Above for the concurrent version, I omitted repeating the examine function, since it wasn't changed from the original version.)

erlang palindrome example (last edited 2014-05-25 18:24:00 by localhost)