diff --git a/src/Years/Y2015/Day7.md b/src/Years/Y2015/Day7.md index f8abae3..2a8df71 100644 --- a/src/Years/Y2015/Day7.md +++ b/src/Years/Y2015/Day7.md @@ -197,11 +197,11 @@ solveWire wire = do ### 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 covering -part1 : Eff (PartEff String) (Bits16, SortedDMap Wire Gate) +part1 : Eff (PartEff String) (Bits16, (SortedDMap Wire Gate, Literal)) part1 = do circut <- askAt "input" >>= parseGates (value, _) <- @@ -209,11 +209,28 @@ part1 = do {fs = State (SortedMap Wire Literal) :: Reader (SortedDMap Wire Gate) :: 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 ```