Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

23 wiersze
596B

  1. import Data.List (nub)
  2. main :: IO ()
  3. main = do
  4. raw <- readFile "day6.txt"
  5. let ls = map concat $ split "" $ lines raw
  6. ms = split "" $ lines raw
  7. ansA = sum $ map (length . nub) ls
  8. ansB = sum $ map (length . (foldr match ['a'..'z'])) ms
  9. in do
  10. putStrLn $ "day6a: " ++ (show ansA)
  11. putStrLn $ "day6b: " ++ (show ansB)
  12. match :: Ord a => [a] -> [a] -> [a]
  13. match as bs = nub $ filter (`elem` bs) as
  14. split :: Eq a => a -> [a] -> [[a]]
  15. split _ [] = []
  16. split d as = chunk : (split d rest)
  17. where
  18. chunk = takeWhile (/= d) as
  19. rest = drop 1 $ dropWhile (/= d) as