September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,3 +1,19 @@
|
|||
is_palindrome_r x | length x <= 1 = True
|
||||
| head x == last x = is_palindrome_r . tail. init $ x
|
||||
| otherwise = False
|
||||
import Data.Char (toLower)
|
||||
|
||||
isPalindrome :: String -> Bool
|
||||
isPalindrome = (==) <*> reverse
|
||||
|
||||
-- Alternatively, comparing just the first half with the reversed latter half
|
||||
isPal :: String -> Bool
|
||||
isPal s =
|
||||
let (q, r) = quotRem (length s) 2
|
||||
in take q s == reverse (drop (q + r) s)
|
||||
|
||||
sample :: String
|
||||
sample = "In girum imus nocte et consumimur igni"
|
||||
|
||||
prepared :: String -> String
|
||||
prepared = filter (' ' /=) . fmap toLower
|
||||
|
||||
main :: IO ()
|
||||
main = print $ [isPalindrome, isPal] <*> [prepared sample]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
is_palindrome_r x | length x <= 1 = True
|
||||
| head x == last x = is_palindrome_r . tail. init $ x
|
||||
| otherwise = False
|
||||
Loading…
Add table
Add a link
Reference in a new issue