Year 2015 Day 12 Part 2
This commit is contained in:
parent
b2704dcbcc
commit
c632ab023d
|
@ -72,9 +72,32 @@ sumNumbers dbl type value = dFoldL sumNumbers' dbl value
|
|||
sumNumbers' dbl _ value = dbl
|
||||
```
|
||||
|
||||
Filter out objects containing a "red" key
|
||||
|
||||
```idris
|
||||
noRed : (type : JSONType) -> (value : JSONValue type) -> Bool
|
||||
noRed TObject value =
|
||||
let (types ** vals) = getValues value
|
||||
in case dFind (\t, v =>
|
||||
case t of
|
||||
TString => v == (VString "red")
|
||||
_ => False
|
||||
) vals of
|
||||
Nothing => True
|
||||
Just _ => False
|
||||
noRed _ value = True
|
||||
|
||||
sumNumbersNoRed :
|
||||
Double -> (type : JSONType) -> (value : JSONValue type) -> Double
|
||||
sumNumbersNoRed dbl type value =
|
||||
case dFilter noRed value of
|
||||
Nothing => dbl
|
||||
Just value => sumNumbers dbl type value
|
||||
```
|
||||
|
||||
## Part Functions
|
||||
|
||||
### Day 1
|
||||
### Part 1
|
||||
|
||||
Parse our JSONs, then fold our `sumNumbers` reducer over them.
|
||||
|
||||
|
@ -88,10 +111,20 @@ part1 = do
|
|||
pure (result, (types ** values))
|
||||
```
|
||||
|
||||
### Part 2
|
||||
|
||||
```idris
|
||||
part2 : (types : List JSONType ** DList JSONType JSONValue types)
|
||||
-> Eff (PartEff String) Double
|
||||
part2 (types ** values) = do
|
||||
let result = dFoldL sumNumbersNoRed 0.0 values
|
||||
pure result
|
||||
```
|
||||
|
||||
```idris hide
|
||||
public export
|
||||
day12 : Day
|
||||
day12 = First 12 part1
|
||||
day12 = Both 12 part1 part2
|
||||
```
|
||||
|
||||
## References
|
||||
|
|
Loading…
Reference in a new issue