Skip to content

Instantly share code, notes, and snippets.

@Ceroce
Created July 6, 2017 13:46
Show Gist options
  • Save Ceroce/fdd80e61ba68e6c11e9a2ed9b55bac25 to your computer and use it in GitHub Desktop.
Save Ceroce/fdd80e61ba68e6c11e9a2ed9b55bac25 to your computer and use it in GitHub Desktop.
Determine if a string is a palindrome
-module (palin).
-export ([palindrome/1, cleanString/1]).
% "Madam, I\'m Adam." must return true
palindrome(String) ->
palinClean(cleanString(String)).
palinClean(String) ->
{HeadHalf, TailHalf} = lists:split(length(String) div 2, String),
lists:prefix(HeadHalf, lists:reverse(TailHalf)).
cleanString([]) -> [];
cleanString([X|Xs]) when (X >= $a) and (X =< $z) ->
[X|cleanString(Xs)];
cleanString([X|Xs]) when (X >= $A) and (X =< $Z) ->
[X+($a-$A) | cleanString(Xs)];
cleanString([_X|Xs]) ->
cleanString(Xs).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment