Looking for a fast way to limit duplicates to a max of 2 when they occur next to each other.
For example: jeeeeeeeep => ['jep','jeep']
Looking for suggestions in python but happy to see an example in anything – not difficult to switch.
Thanks for any assistance!
EDIT: English doesn’t have any (or many) consonants (same letter) in a row right? Lets limit this so no duplicate consonants in a row and up to two vowels in a row
EDIT2: I’m silly (hey that word has two consonants), just checking all letters, limiting duplicate letters that are next to each other to two.
Here’s a recursive solution using
groupby. I’ve left it up to you which characters you want to be able to repeat (defaults to vowels only though):This is really just a heuristically pruned depth-first search into your “solution space” of possible words. The heuristic is that we only allow a single repeat at a time, and only if it is a valid repeatable letter. You should end up with 2**n words at the end, where n is he number times an “allowed” character was repeated in your string.