From fe5e404a4b40dd0b2b34fa2d02a7fbf2c969e920 Mon Sep 17 00:00:00 2001 From: Eric Mertens Date: Wed, 18 Dec 2024 23:11:52 -0800 Subject: [PATCH] comments --- solutions/src/2024/19.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/solutions/src/2024/19.hs b/solutions/src/2024/19.hs index f90e5f4..e71f614 100644 --- a/solutions/src/2024/19.hs +++ b/solutions/src/2024/19.hs @@ -57,9 +57,15 @@ designWays t str = memo ! 0 data Trie = Node !Bool (Map Char Trie) +-- | Construct a 'Trie' that matches exactly one string. toTrie :: String -> Trie toTrie = foldr (\x t -> Node False (Map.singleton x t)) (Node True Map.empty) +-- | Given a starting index find all the ending indexes for +-- suffixes that remain after matching a string in the 'Trie'. +-- +-- >>> matches (toTrie "pre" <> toTrie "pref") 0 "prefix" +-- [3,4] matches :: Trie -> Int -> String -> [Int] matches (Node b xs) n yys = [n | b] ++