Created
June 28, 2017 11:55
-
-
Save i7an/c53e331f04484a80bdb7ffcb4511f861 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(main). | |
-export([palindrome/1]). | |
-import(lists, [filter/2, map/2, reverse/1]). | |
is_between(X, A, B) -> | |
X >= A andalso B >= X. | |
is_lowercase_char(Ch) -> | |
is_between(Ch, $a, $z). | |
is_uppercase_char(Ch) -> | |
is_between(Ch, $A, $Z). | |
is_letter(Ch) -> | |
is_lowercase_char(Ch) orelse | |
is_uppercase_char(Ch). | |
lowercase(Ch) -> | |
case is_uppercase_char(Ch) of | |
true -> $a + Ch - $A; | |
false -> Ch | |
end. | |
palindrome(Str) -> | |
Filtered = filter(fun is_letter/1, Str), | |
Lowercase = map(fun lowercase/1, Filtered), | |
Lowercase == reverse(Lowercase). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment