mirror of
https://github.com/mx42/adventofcode.git
synced 2026-01-14 13:59:51 +01:00
Fix Day 2015 05
This commit is contained in:
1000
haskellAoC/inputs/2015/05
Normal file
1000
haskellAoC/inputs/2015/05
Normal file
File diff suppressed because it is too large
Load Diff
5
haskellAoC/inputs/2015/05_test_p1
Normal file
5
haskellAoC/inputs/2015/05_test_p1
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
ugknbfddgicrmopn
|
||||||
|
aaa
|
||||||
|
jchzalrnumimnmhp
|
||||||
|
haegwjzuvuyypxyu
|
||||||
|
dvszwmarrgswjxmb
|
||||||
4
haskellAoC/inputs/2015/05_test_p2
Normal file
4
haskellAoC/inputs/2015/05_test_p2
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
qjhvhtzxzqqjkmpb
|
||||||
|
xxyxx
|
||||||
|
uurcxstgmygtbstg
|
||||||
|
ieodomkazucvgmuy
|
||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user