Created
September 8, 2018 14:35
-
-
Save navneetgupta/18a0d31bdba81bd1356e63019b20e03e to your computer and use it in GitHub Desktop.
Check Plaindrome
This file contains hidden or 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
| defmodule Plaindrome do | |
| def is_plaindrome(x) when is_bitstring(x) do | |
| x | |
| |> String.reverse() | |
| |> is_palindrome(x) | |
| end | |
| def is_plaindrome(x) when is_integer(x) do | |
| x | |
| |> to_string() | |
| |> String.reverse() | |
| |> is_palindrome(to_string(x)) | |
| end | |
| defp is_palindrome(reversed_word, word) when word == reversed_word do | |
| IO.puts "#{word} IS a palindrome" | |
| end | |
| defp is_palindrome(reversed_word, word) when word != reversed_word do | |
| IO.puts "#{word} IS NOT a palindrome" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment