Skip to content

Commit 44b3e82

Browse files
committed
note that the cata/ana is faster
1 parent 6191a6e commit 44b3e82

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

reflections/2024/day19.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ If we had a `CharTrie a`, then `cata lookupAlg myTree "hello"` would look up
3535

3636
The buildup co-algebra is an interesting one. We will convert a `Map String a`
3737
into a `CharTrie a`, _but_, every time we reach the end of the string, we
38-
"restart" the building from the start. So, we'll take a `Set String` as well,
39-
which we will trigger when we hit the end of a pattern.
38+
"restart" the building from the start, while merging all of the resulting
39+
leaves monoidally. So, we'll take a `Set String` as well, which we will trigger
40+
when we hit the end of a pattern.
4041

4142
```haskell
4243
fromMapCoalg ::
@@ -74,3 +75,8 @@ part1 pats = length . mapMaybe (buildable () pats)
7475
part2 :: Set String -> [String] -> Int
7576
part2 pats = getSum . foldMap (fold . buildable (Sum 1) pats)
7677
```
78+
79+
However, this may be a case where the hylomorphism is slower than doing the
80+
unfold and fold separately, because the full `CharTrie` is actually going to be
81+
re-used multiple times for each design. However, there's something a little
82+
more satisfying about just re-building and tearing down every time.

0 commit comments

Comments
 (0)