Fix Day 2015 05

This commit is contained in:
Xavier Morel
2020-12-03 14:46:26 +01:00
parent 48b6879a9f
commit d801e70166
4 changed files with 1018 additions and 8 deletions

1000
haskellAoC/inputs/2015/05 Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,5 @@
ugknbfddgicrmopn
aaa
jchzalrnumimnmhp
haegwjzuvuyypxyu
dvszwmarrgswjxmb

View File

@@ -0,0 +1,4 @@
qjhvhtzxzqqjkmpb
xxyxx
uurcxstgmygtbstg
ieodomkazucvgmuy

View File

@@ -1,5 +1,7 @@
module Y2015.Day05 (y15day05) where module Y2015.Day05 (y15day05) where
import Data.List
has3vowels :: String -> Bool has3vowels :: String -> Bool
has3vowels input = (>= 3) $ length $ filter (`elem` "aeiou") input has3vowels input = (>= 3) $ length $ filter (`elem` "aeiou") input
@@ -15,16 +17,15 @@ noForbiddenStr (x:x2:xs)
| otherwise = noForbiddenStr (x2:xs) | otherwise = noForbiddenStr (x2:xs)
noForbiddenStr _ = True noForbiddenStr _ = True
contains :: String -> String -> Bool contains :: String -> (Char, Char) -> Bool
contains _ [] = True contains (x:xs@(y:_)) p@(a, b)
contains [] _ = False | (x == a && y == b) = True
contains (x:xs) (y:ys) | otherwise = contains xs p
| x == y = contains xs ys contains _ _ = False
| otherwise = contains xs (y:ys)
repeatedTwoLetters :: String -> Bool repeatedTwoLetters :: String -> Bool
repeatedTwoLetters (x1:x2:xs) repeatedTwoLetters (x1:x2:xs)
| xs `contains` (x1:[x2]) = True | xs `contains` (x1, x2) = True
| otherwise = repeatedTwoLetters (x2:xs) | otherwise = repeatedTwoLetters (x2:xs)
repeatedTwoLetters _ = False repeatedTwoLetters _ = False
@@ -42,4 +43,4 @@ y15day05 input = (part1, part2)
applyRules rules pwd = all (== True) $ map ($ pwd) rules applyRules rules pwd = all (== True) $ map ($ pwd) rules
countCorrectPwd rules = length $ filter (== True) $ map (applyRules rules) input countCorrectPwd rules = length $ filter (== True) $ map (applyRules rules) input
part1 = show $ countCorrectPwd part1rules part1 = show $ countCorrectPwd part1rules
part2 = "WIP, invalid: " ++ (show $ countCorrectPwd part2rules) part2 = show $ countCorrectPwd part2rules