September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -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]

View file

@ -0,0 +1,3 @@
is_palindrome_r x | length x <= 1 = True
| head x == last x = is_palindrome_r . tail. init $ x
| otherwise = False