Generating Candidates
Let’s see, we’re generating and filtering, right? So let’s consider the operation that generates potential words for later filtering. Type-wise, we want generate_candidates :: String -> [String], so that from a given word we get all possible next steps.
It’s always good to start with some concrete examples, especially if the operation doesn’t seem obvious.
From generate_candidates "", we expect no candidates, since there’s no way to change a single character in an empty string.
From generate_candidates "a", we expect ["b", "c", ... "z"], because we change the character to every other character except "a".
From generate_candidates "ba", we expect ["aa", "ca", "da", ... "za", "bb", "bc", ... "bz" ], which is the list ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access