Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
glguy committed Dec 19, 2024
1 parent c02fead commit fe5e404
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions solutions/src/2024/19.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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] ++
Expand Down

0 comments on commit fe5e404

Please sign in to comment.