18
1
Note: the title was misspelled intentionally.
Given a string s, swap the first vowel runs of every 2 words. For this challenge, y is considered a vowel.
For example, given an input of "great day sir":
1. Input: "great day sir"
2. Identify pairs of words: "[great day] [sir]" (No word for sir to pair with)
3. Identify the first vowel runs in each word: "[gr[ea]t d[ay]] [s[i]r]"
4. Swap the vowel runs in each pair: "[gr[ay]t d[ea]] [s[i]r]"
5. Return/print: "grayt dea sir"
When there are vowel runs of different lengths, you still swap the whole runs. When a word has more than one vowel runs, you still only swap the first one. When the first or second word of a pair of words does not have a vowel, then you do not swap the vowels for those words.
You may assume that the input only consists of one case of alphabetic letters and the literal space or another constant delimiter.
Standard methods of I/O, standard loopholes apply. Leading/trailing whatevers are okay.
Test cases:
Input -> Output
"great day sir" -> "grayt dea sir"
"ppcg is the best" -> "ppcg is the best" (When there is no vowel to swap, don't swap vowels."
"this is a test case" -> "this is e tast case"
"loooooooooooooong word" -> "long woooooooooooooord"
"great night" -> "grit neaght"
"anything goes" -> "oenything gas"
"qwrtpsdfghjklzxcvbnm aaaaaaaa hi there" -> "qwrtpsdfghjklzxcvbnm aaaaaaaa he thire"
"this is a long test case in case you could not tell" -> "this is o lang tast cese an cise ou cyould net toll"
1
For those who can see deleted posts, the sandbox post was here.
– Comrade SparklePony – 2017-06-13T20:09:02.7501If the first word has no vowels, is it OK to swap the vowels of the second and third words? Or can vowels only swap between runs of two words? For example, should
ppcg is awesome
becomeppcg is awesome
orppcg as iwesome
? – James – 2017-06-13T20:18:40.197@DJMcMayhem Vowels can only swap between runs of two words. I will edit. – Comrade SparklePony – 2017-06-13T20:21:43.143
I believe the output for
this is a long test case in case you could not tell
should bethis is o lang tast cese an cise ou cyould net toll
, since the vowel runsyou
andou
would be swapped. – Bashful Beluga – 2017-06-13T22:49:50.820@BashfulBeluga Yep, my mistake. I will fix. – Comrade SparklePony – 2017-06-13T23:00:55.710
Passing the test cases is easy enough but getting this right is trickier than it sounds: https://en.oxforddictionaries.com/explore/is-the-letter-y-a-vowel-or-a-consonant
– gmatht – 2017-06-14T04:41:01.760I don't think you meant to have the brackets in
1. Input: "gr[ea]t day sir"
, that confused me when I reread it, since that's not part of the actual input. – Sunny Patel – 2017-06-14T14:17:36.677