Year 2015 Day 11 Part 2
This commit is contained in:
parent
d84f361577
commit
49525e43a1
|
@ -183,8 +183,8 @@ containsPairs xs = length (nub $ pairs (reverse xs) []) >= 2
|
||||||
Combine our password criteria into one function
|
Combine our password criteria into one function
|
||||||
|
|
||||||
```idris
|
```idris
|
||||||
part1Critera : Vect n PasswordChar -> Bool
|
passwordCriteria : Vect n PasswordChar -> Bool
|
||||||
part1Critera xs = incrimentingChars xs && noInvalidChars xs && containsPairs xs
|
passwordCriteria xs = incrimentingChars xs && noInvalidChars xs && containsPairs xs
|
||||||
```
|
```
|
||||||
|
|
||||||
### Find the next password
|
### Find the next password
|
||||||
|
@ -207,19 +207,30 @@ findNextPassword f password =
|
||||||
### Part 1
|
### Part 1
|
||||||
|
|
||||||
```idris
|
```idris
|
||||||
part1 : Eff (PartEff String) (String, ())
|
part1 : Eff (PartEff String) (String, Password)
|
||||||
part1 = do
|
part1 = do
|
||||||
input <- map trim $ askAt "input"
|
input <- map trim $ askAt "input"
|
||||||
password <- parsePassword input
|
password <- parsePassword input
|
||||||
info "Starting password: \{show password} -> \{passwordToString password}"
|
info "Starting password: \{show password} -> \{passwordToString password}"
|
||||||
let next_password = findNextPassword part1Critera password
|
let next_password = findNextPassword passwordCriteria password
|
||||||
pure (passwordToString next_password, ())
|
pure (passwordToString next_password, next_password)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Part 2
|
||||||
|
|
||||||
|
```idris
|
||||||
|
part2 : Password -> Eff (PartEff String) String
|
||||||
|
part2 password = do
|
||||||
|
info
|
||||||
|
"Second starting password: \{show password} -> \{passwordToString password}"
|
||||||
|
let next_password = findNextPassword passwordCriteria password
|
||||||
|
pure $ passwordToString next_password
|
||||||
```
|
```
|
||||||
|
|
||||||
<!-- idris
|
<!-- idris
|
||||||
public export
|
public export
|
||||||
day11 : Day
|
day11 : Day
|
||||||
day11 = First 11 part1
|
day11 = Both 11 part1 part2
|
||||||
-->
|
-->
|
||||||
|
|
||||||
## References
|
## References
|
||||||
|
|
Loading…
Reference in a new issue