Skip to content

Instantly share code, notes, and snippets.

@i7an
Created June 28, 2017 11:55
Show Gist options
  • Save i7an/c53e331f04484a80bdb7ffcb4511f861 to your computer and use it in GitHub Desktop.
Save i7an/c53e331f04484a80bdb7ffcb4511f861 to your computer and use it in GitHub Desktop.
-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