Difference between revisions of "99 questions/Solutions/6"
< 99 questions | Solutions
Jump to navigation
Jump to search
Line 8: | Line 8: | ||
<haskell> |
<haskell> |
||
isPalindrome' [] = True |
isPalindrome' [] = True |
||
− | isPalindrome' [ |
+ | isPalindrome' [_] = True |
isPalindrome' xs = (head xs) == (last xs) && (isPalindrome' $ init $ tail xs) |
isPalindrome' xs = (head xs) == (last xs) && (isPalindrome' $ init $ tail xs) |
||
</haskell> |
</haskell> |
Revision as of 07:29, 17 November 2010
(*) Find out whether a list is a palindrome. A palindrome can be read forward or backward; e.g. (x a m a x).
isPalindrome :: (Eq a) => [a] -> Bool
isPalindrome xs = xs == (reverse xs)
isPalindrome' [] = True
isPalindrome' [_] = True
isPalindrome' xs = (head xs) == (last xs) && (isPalindrome' $ init $ tail xs)