mirror of
https://github.com/mx42/adventofcode.git
synced 2026-01-14 22:09:50 +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
|
||||
|
||||
import Data.List
|
||||
|
||||
has3vowels :: String -> Bool
|
||||
has3vowels input = (>= 3) $ length $ filter (`elem` "aeiou") input
|
||||
|
||||
@@ -15,16 +17,15 @@ noForbiddenStr (x:x2:xs)
|
||||
| otherwise = noForbiddenStr (x2:xs)
|
||||
noForbiddenStr _ = True
|
||||
|
||||
contains :: String -> String -> Bool
|
||||
contains _ [] = True
|
||||
contains [] _ = False
|
||||
contains (x:xs) (y:ys)
|
||||
| x == y = contains xs ys
|
||||
| otherwise = contains xs (y:ys)
|
||||
contains :: String -> (Char, Char) -> Bool
|
||||
contains (x:xs@(y:_)) p@(a, b)
|
||||
| (x == a && y == b) = True
|
||||
| otherwise = contains xs p
|
||||
contains _ _ = False
|
||||
|
||||
repeatedTwoLetters :: String -> Bool
|
||||
repeatedTwoLetters (x1:x2:xs)
|
||||
| xs `contains` (x1:[x2]) = True
|
||||
| xs `contains` (x1, x2) = True
|
||||
| otherwise = repeatedTwoLetters (x2:xs)
|
||||
repeatedTwoLetters _ = False
|
||||
|
||||
@@ -42,4 +43,4 @@ y15day05 input = (part1, part2)
|
||||
applyRules rules pwd = all (== True) $ map ($ pwd) rules
|
||||
countCorrectPwd rules = length $ filter (== True) $ map (applyRules rules) input
|
||||
part1 = show $ countCorrectPwd part1rules
|
||||
part2 = "WIP, invalid: " ++ (show $ countCorrectPwd part2rules)
|
||||
part2 = show $ countCorrectPwd part2rules
|
||||
|
||||
Reference in New Issue
Block a user