Year 2015 Day 7 Part 2
This commit is contained in:
parent
fc7f79a96a
commit
5a313c952f
|
@ -197,11 +197,11 @@ solveWire wire = do
|
||||||
|
|
||||||
### Part 1
|
### Part 1
|
||||||
|
|
||||||
Parse the input, then feed it and an initial empty cache into our `solveWire` function, passing the produced value as the output and the circut, represented as a dependent map from wires to gates, as the context for part 2.
|
Parse the input, then feed it and an initial empty cache into our `solveWire` function, passing the produced value as the output and the circut, represented as a dependent map from wires to gates, as well as the output signal from wire 'a' as the context for part 2.
|
||||||
|
|
||||||
```idris
|
```idris
|
||||||
covering
|
covering
|
||||||
part1 : Eff (PartEff String) (Bits16, SortedDMap Wire Gate)
|
part1 : Eff (PartEff String) (Bits16, (SortedDMap Wire Gate, Literal))
|
||||||
part1 = do
|
part1 = do
|
||||||
circut <- askAt "input" >>= parseGates
|
circut <- askAt "input" >>= parseGates
|
||||||
(value, _) <-
|
(value, _) <-
|
||||||
|
@ -209,11 +209,28 @@ part1 = do
|
||||||
{fs = State (SortedMap Wire Literal)
|
{fs = State (SortedMap Wire Literal)
|
||||||
:: Reader (SortedDMap Wire Gate)
|
:: Reader (SortedDMap Wire Gate)
|
||||||
:: PartEff String }
|
:: PartEff String }
|
||||||
pure (value, circut)
|
pure (value, (circut, value))
|
||||||
|
```
|
||||||
|
|
||||||
|
### Part 2
|
||||||
|
|
||||||
|
Override the value for the 'b' wire to the output from the 'a' wire in part 1, then rerun our calcuation to find the new output for the 'a' wire.
|
||||||
|
|
||||||
|
```idris
|
||||||
|
covering
|
||||||
|
part2 : (SortedDMap Wire Gate, Literal) -> Eff (PartEff String) Bits16
|
||||||
|
part2 (circut, value) = do
|
||||||
|
let circut = insert "b" (Constant (Left value)) circut
|
||||||
|
(value, _) <-
|
||||||
|
runState empty . runReader circut $ solveWire "a"
|
||||||
|
{fs = State (SortedMap Wire Literal)
|
||||||
|
:: Reader (SortedDMap Wire Gate)
|
||||||
|
:: PartEff String }
|
||||||
|
pure value
|
||||||
```
|
```
|
||||||
|
|
||||||
<!-- idris
|
<!-- idris
|
||||||
public export covering
|
public export covering
|
||||||
day7 : Day
|
day7 : Day
|
||||||
day7 = First 7 part1
|
day7 = Both 7 part1 part2
|
||||||
-->
|
-->
|
||||||
|
|
Loading…
Reference in a new issue