Given an input string, output that string with all vowels a
, e
, i
, o
and u
swapped at random between each other.
For example, in the string this is a test
, there are 4 vowels: [i, i, a, e]
. A valid shuffling of those vowels could be [a, i, e, i]
therefore yielding the output thas is e tist
.
About shuffling
All shuffles shall be equally likely if we consider equal vowels to be distinct. For the example above, those 24 shuffles are possible:
[i1, i2, a, e] [i1, i2, e, a] [i1, a, i2, e] [i1, a, e, i2] [i1, e, i2, a] [i1, e, a, i2] [i2, i1, a, e] [i2, i1, e, a] [i2, a, i1, e] [i2, a, e, i1] [i2, e, i1, a] [i2, e, a, i1] [a, i1, i2, e] [a, i1, e, i2] [a, i2, i1, e] [a, i2, e, i1] [a, e, i1, i2] [a, e, i2, i1] [e, i1, i2, a] [e, i1, a, i2] [e, i2, i1, a] [e, i2, a, i1] [e, a, i1, i2] [e, a, i2, i1]
Each one should be equally as likely.
You may not try random shuffles of the entire string until finding one where all vowels are in the right place. In short, your code's running time shall be constant if the input is constant.
Inputs and outputs
You may assume that all letters in the input will be lowercase or uppercase. You may also support mixed casing, though this won't give you any bonus.
The input will always consist of printable ASCII characters. All characters that are in the input shall be in the output, only the vowels must be shuffled around and nothing else.
The input can be empty. There is no guarantee that the input will contain at least one vowel or at least one non-vowel.
You may take the input from
STDIN
, as a function parameter, or anything similar.You may print the output to
STDOUT
, return it from a function, or anything similar.
Test cases
The first line is the given input. The second line is one of the possible outputs.
<empty string>
<empty string>
a
a
cwm
cwm
the quick brown fox jumps over the lazy dog.
tho qeuck brewn fax jumps ovir the lozy dog.
abcdefghijklmnopqrstuvwxyz
abcdefghujklmnipqrstovwxyz
programming puzzles & code golf
pregromming pezzlos & coda gulf
fatalize
fitaleza
martin ender
mirten ander
Scoring
This is code-golf, sa tho shirtist enswer en bytes wons.
y
as vowel.. ;) \$\endgroup\$y
to be a vowel, but last challenge where I saidy
was a vowel I got asked why I chose that! \$\endgroup\$