forked from matthewsamuel95/ACM-ICPC-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalindrome.erl
More file actions
17 lines (14 loc) · 730 Bytes
/
palindrome.erl
File metadata and controls
17 lines (14 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
-module(palindrome).
-export([palindrome/1]).
palindrome(String) ->
NormalizedString = normalize(String, ""),
palindrome(NormalizedString, lists:reverse(NormalizedString)).
palindrome([], []) -> true;
palindrome([ H | Rest ], [ H | Rest2 ]) -> palindrome(Rest, Rest2);
palindrome(_, _) -> false.
normalize([], Result) -> Result;
normalize([ H | Rest ], Result) when H >= $A, H =< $Z -> normalize(Rest, [ H - $A + $a | Result ]);
normalize([ H | Rest ], Result) when (H < $1 orelse H > $9) andalso
(H < $A orelse H > $Z) andalso
(H < $a orelse H > $z) -> normalize(Rest, Result);
normalize([ H | Rest ], Result) -> normalize(Rest, [ H | Result ]).