Initial commit
This commit is contained in:
commit
f242d2b0df
420 changed files with 62521 additions and 0 deletions
29
2017/04/day4.hs
Normal file
29
2017/04/day4.hs
Normal file
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env stack
|
||||
-- stack --resolver lts-9.14 script
|
||||
|
||||
import Data.List
|
||||
|
||||
testDuplicates :: [String] -> Bool
|
||||
testDuplicates xs = length (nub xs) /= (length xs)
|
||||
|
||||
countLinesWithDuplicates :: [String] -> Int
|
||||
countLinesWithDuplicates = sum . map (fromEnum . testDuplicates . words)
|
||||
|
||||
isAnagram :: String -> String -> Bool
|
||||
isAnagram s1 s2 = sort s1 == sort s2
|
||||
|
||||
testAnagrams :: [String] -> Bool
|
||||
testAnagrams [] = True
|
||||
testAnagrams (x:xs) =
|
||||
if or (map (isAnagram x) xs)
|
||||
then False
|
||||
else testAnagrams xs
|
||||
|
||||
countValidLines :: [String] -> Int
|
||||
countValidLines = sum . map (fromEnum . testAnagrams . words)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
contents <- getContents
|
||||
putStrLn . show . (\xs -> length xs - countLinesWithDuplicates xs) . lines $ contents
|
||||
putStrLn . show . countValidLines . lines $ contents
|
Loading…
Add table
Add a link
Reference in a new issue