Skip to content

Instantly share code, notes, and snippets.

@tkovs
Created August 19, 2015 00:03
Show Gist options
  • Save tkovs/93842df56d7b38a75f09 to your computer and use it in GitHub Desktop.
Save tkovs/93842df56d7b38a75f09 to your computer and use it in GitHub Desktop.
"Crie um programa que verifique se um número é palíndromo em binário!"
palindrome :: Eq a => [a] -> Bool
palindrome a = (equals a (reverse' a))
bin :: Int -> [Int]
bin 0 = []
bin x = bin (div x 2) ++ [mod x 2]
reverse' :: [a] -> [a]
reverse' [] = []
reverse' (x:xs) = reverse' xs ++ [x]
equals :: Eq a => [a] -> [a] -> Bool
equals [] [] = True
equals (x:xs) (y:ys)
| x == y = equals xs ys
| otherwise = False
main = do
print $ palindrome $ bin 45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment