I got a program that checks if string is palindrome or not. I want to add functionality that lets user check if given string is palindrome at i letters. For example if string is "abbaabba" and user gives number 4 it returns true because "abba" is palindrome. If user gives 5 then it returns false, because "abbaa" is not palindrome.
This is what I've done so far
palindromes:: String -> Int -> Bool
palindromes p i
| p == reverse p = True
| otherwise = False
How do I add that functionality?
You can make use of take :: Int -> [a] -> [a]
here to pre-process the string:
palindromes :: Eq a => [a] -> Int -> Bool
palindromes p i = p' == reverse p'
where p' =
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.