Stuttering is a problem which many of us might have experienced or at least seen it. Although most of famous speech recognition softwares have serious issues with stuttered speaking, let's imagine a software which understands stuttering, but cannot fix them and only writes them as is.
An example written text by such a software can be like this: "please be ca ca careful". In this example "careful" is the original word and "ca ca" are the stuttered words.
Write a program or function that fixes stuttered words by removing them from the input while keeping the original words. For example fixed version of "please be ca ca careful" would be "please be careful".
This is code-golf, shortest answer in every language wins!
What are stuttered words?
Stuttering has many different variations. But for simplicity of this challenge, we are going to limit it to the following rules:
- Stuttered words can be an uncompleted part or whole of the original word. By "uncompleted part" I mean that the original word should start exactly with the stuttered word. For example "ope" and "open" both can be a stuttered word for "open", but "pen" cannot be one since "open" doesn't start with "pen".
- Stuttered words must contain at least one of the "aeiou" vowels. For example "star" can be a stuttered word for "start" as it contains "a", but "st" cannot be a stuttered word as it doesn't contain any of the mentioned vowels.
- Stuttered words can only appear before the original word and should be repeated at least two times to be valid (the original word doesn't count in the repeats). For example "o o open" has stuttered words but "o open o" doesn't, because the "o" after the original word doesn't count and "o" before the original word is not repeated at least two times. "go go go go go go" has five repeats of stuttered words before the original word and is valid.
- A single set of repeated stuttered words cannot contain mixed forms and the words should be exactly like each other. For example "op o op open" doesn't count as stuttered words. On the other hand "o op op open" has stuttered words because the first "o" is seen as a whole different word here and the two "op"s are counted as stuttered words of "open".
- In case of multiple valid sets of repeated stuttered words right after each other, only the last original word stays. For example, in "o o o op op op open", the "o o o" part is seen as stuttered words of the first "op", so they should be removed and then "op op op" is seen as stuttered words of "open" and they should be removed too, so only the "open" will be left after removal of stuttered words. You can assume that multiple valid sets of repeated stuttered words only happen from left to right, so fixing "op op o o o open" would result in "op op open" (a.k.a. we do not fix again after fixing once).
- Input is a single line string containing only ASCII English letters (a-z), digits (0-9) and space characters. Letter casing is not important and you can decide to accept lowercase or uppercase or both of them, but the casing should stay the same and you cannot change it in the output.
- You can use a list of letters (like
["l","i","s","t"," ","o","f"," ","l","e","t","t","e","r","s"]) instead of the string, but you cannot use a list of words. If your language has a different input structure, use it. The point is that input shouldn't be separated by words, so cost of separating words in some languages might actually trigger other creative solutions.
- The input might contain none, one or multiple stuttered words in it.
- Words and or numbers are separated by a single space and input will not contain double spaces right next to each other.
- A string or a list of letters or the appropriate structure in your language with all stuttered words removed from the input.
- Output words should be separated by exactly one space (same as input).
- Single leading and trailing newline or space are allowed.
Standard loopholes are forbidden.
No stuttered words:
"hello world" => "hello world"
A single instance of repeated stuttered words:
"ope ope ope ope open the window" => "open the window"
Multiple instances of repeated stuttered words:
"there is is is is something un un under the the the table" => "there is something under the table"
No stuttered words, not repeated enough:
"give me the the book" => "give me the the book"
No stuttered words, don't have any of the mentioned vowels:
"h h help m m m me" => "h h help m m m me"
Numbers aren't stuttered words, they don't have any of the mentioned vowels:
"my nu nu number is 9 9 9 9876" => "my number is 9 9 9 9876"
But a word with both vowels and numbers can have stuttered words:
"my wi wi windows10 is slow" => "my windows10 is slow"
Different forms of stuttered words in same repeat group aren't counted:
"this is an ant antarctica does not have" => "this is an ant antarctica does not have"
For multiple continuous sets of stuttered words right after each other, only keep the last original word:
"what a be be be beauti beauti beautiful flower" => "what a beautiful flower"
This isn't a case of multiple continuous sets of stuttered words right after each other:
"drink wat wat wa wa water" => "drink wat wat water"
"" => ""
More cases from comments:
"a ab abc" => "a ab abc" "a ab ab abc" => "a abc" "ab ab abc abcd" => "abc abcd" "a a ab a able" => "ab a able" "i have ave ave average" => "i have average" "my wi wi windows 10 is cra cra crap" => "my windows 10 is crap"
An easy to copy list of the above test cases:
"hello world", "ope ope ope ope open the window", "there is is is is something un un under the the the table", "give me the the book", "h h help m m m me", "my nu nu number is 9 9 9 9876", "my wi wi windows10 is slow", "this is an ant antarctica does not have", "what a be be be beauti beauti beautiful flower", "drink wat wat wa wa water", "", "a ab abc", "a ab ab abc", "ab ab abc abcd", "a a ab a able", "i have ave ave average", "my wi wi windows 10 is cra cra crap"