Skip to content

Instantly share code, notes, and snippets.

@navneetgupta
Created September 8, 2018 14:35
Show Gist options
  • Select an option

  • Save navneetgupta/18a0d31bdba81bd1356e63019b20e03e to your computer and use it in GitHub Desktop.

Select an option

Save navneetgupta/18a0d31bdba81bd1356e63019b20e03e to your computer and use it in GitHub Desktop.
Check Plaindrome
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