42
\$\begingroup\$

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 , sa tho shirtist enswer en bytes wons.

\$\endgroup\$
  • 17
    \$\begingroup\$ You English/American people and your lack of y as vowel.. ;) \$\endgroup\$ – Kevin Cruijssen Aug 31 '16 at 7:21
  • 6
    \$\begingroup\$ @KevinCruijssen I'm not a native speaker and I would also consider y to be a vowel, but last challenge where I said y was a vowel I got asked why I chose that! \$\endgroup\$ – Fatalize Aug 31 '16 at 7:22
  • 7
    \$\begingroup\$ @KevinCruijssen, letters aren't vowels: sounds are. \$\endgroup\$ – Peter Taylor Aug 31 '16 at 8:45
  • 6
    \$\begingroup\$ +1 for cwm. Keeping mountaineering and/or Welsh alive ;) \$\endgroup\$ – Beta Decay Aug 31 '16 at 9:19
  • 2
    \$\begingroup\$ @KevinCruijssen Don't have a cow about vowels that aren't commonly considered so. \$\endgroup\$ – corsiKa Aug 31 '16 at 19:21

26 Answers 26

13
\$\begingroup\$

Jelly, 15 bytes

f€“¡ẎṢɱ»ðœpżFẊ¥

Try it online!

How it works

f€“¡ẎṢɱ»ðœpżFẊ¥  Main link. Argument: s (string)

  “¡ẎṢɱ»         Yield "aeuoi"; concatenate "a" with the dictionary word "euoi".
f€               Filter each character in s by presence in "aeuoi".
                 This yields A, an array of singleton and empty strings.
        ð        Begin a new, dyadic chain. Left argument: A. Right argument: s
         œp      Partition s at truthy values (singleton strings of vowels) in A.
            FẊ¥  Flatten and shuffle A. This yields a permutation of the vowels.
           ż     Zip the partition of consonants with the shuffled vowels.
\$\endgroup\$
  • \$\begingroup\$ Why does this seem fairly slow compared to other answers? \$\endgroup\$ – Fatalize Aug 31 '16 at 7:20
  • \$\begingroup\$ Jelly imports SymPy and NumPy before anything else. This program and the empty program have roughly the same execution time. \$\endgroup\$ – Dennis Aug 31 '16 at 7:23
  • 15
    \$\begingroup\$ Before anyone asks, euoi is a cry of impassioned rapture in ancient Bacchic revels. \$\endgroup\$ – Dennis Aug 31 '16 at 7:26
  • 5
    \$\begingroup\$ @Dennis Out of curiosity though, why does Jelly have built in dictionary words? Where does it get these dictionary words from? \$\endgroup\$ – Kevin Cruijssen Aug 31 '16 at 7:31
  • 1
    \$\begingroup\$ @KevinCruijssen When I designed Jelly, there already were a few golfing languages that used shoco, and simply using an English dictionary seemed like a good way to improve on that idea. I used the file /usr/share/dict/words from my computer and included it in the Jelly interpreter. \$\endgroup\$ – Dennis Aug 31 '16 at 21:19
17
\$\begingroup\$

R, 92 91

Can't comment yet so I'm adding my own answer albeit very similar to @Andreï Kostyrka answer (believe it or not but came up with it independently).

s=strsplit(readline(),"")[[1]];v=s%in%c("a","e","i","o","u");s[v]=sample(s[v]);cat(s,sep="")

Ungolfed

s=strsplit(readline(),"")[[1]]    # Read input and store as a vector
v=s%in%c("a","e","i","o","u")     # Return TRUE/FALSE vector if vowel
s[v]=sample(s[v])                 # Replace vector if TRUE with a random permutation of vowels
cat(s,sep="")                     # Print concatenated vector

Saved one byte thanks to @Vlo

s=strsplit(readline(),"")[[1]];s[v]=sample(s[v<-s%in%c("a","e","i","o","u")]);cat(s,sep="")
\$\endgroup\$
  • 5
    \$\begingroup\$ Honestly, I cannot believe. Just kidding. Nice trick to save some bytes! \$\endgroup\$ – Andreï Kostyrka Aug 31 '16 at 8:49
  • \$\begingroup\$ Just to be honest, I am not stealing your ideas to golf my answer further. \$\endgroup\$ – Andreï Kostyrka Aug 31 '16 at 8:50
  • 3
    \$\begingroup\$ Hehe, gotta get them sweet upvotes so I can comment ;) \$\endgroup\$ – Billywob Aug 31 '16 at 8:53
  • \$\begingroup\$ Save a byte with in-line assignment 91 bytes s=strsplit(readline(),"")[[1]];s[v]=sample(s[v<-s%in%c("a","e","i","o","u")]);cat(s,sep="") \$\endgroup\$ – Vlo Sep 1 '16 at 20:17
  • \$\begingroup\$ Save another byte by using el() instead of [[1]]. \$\endgroup\$ – Andreï Kostyrka Mar 23 '18 at 13:11
11
\$\begingroup\$

R, 99 98 89 bytes

x=el(strsplit(readline(),""))
z=grepl("[aeiou]",x)
x[z]=x[sample(which(z))]
cat(x,sep="")

Seems to be the first human-readable solution! Thanks to Giuseppe for saving 9 bytes!

Test cases:

tho qaeck bruwn fux jemps over tho lozy dig.
progremmang pozzlos & cide gulf

Seems that there is no way to make an internal variable assignment (inside, like, cat), and again some people are going to prove I am wrong...

\$\endgroup\$
  • 2
    \$\begingroup\$ letters[c(1,5,9,15,21)] is 1 byte longer, and OEIS A161536 and A215721 seem to be of little to no help either. \$\endgroup\$ – Andreï Kostyrka Aug 31 '16 at 8:08
  • \$\begingroup\$ Wouldn't z=grepl("[aeiou]",x) be shorter? \$\endgroup\$ – Giuseppe Mar 24 '18 at 21:54
  • \$\begingroup\$ @Giuseppe You did it again! Thanks. \$\endgroup\$ – Andreï Kostyrka Mar 24 '18 at 22:00
10
\$\begingroup\$

CJam, 23 bytes

lee_{"aeiou"&},_mrerWf=

Try it online!

Explanation

l            e# Read input, e.g. "foobar".
ee           e# Enumerate, e.g. [[0 'f] [1 'o] [2 'o] [3 'b] [4 'a] [5 'r]].
_            e# Duplicate.
{"aeiou"&},  e# Keep those which have a non-empty intersection with this string
             e# of vowels, i.e. those where the enumerated character is a vowel.
             e# E.g. [[1 'o] [2 'o] [4 'a]].
_            e# Duplicate.
mr           e# Shuffle the copy. E.g. [[2 'o] [4 'a] [1 'o]].
er           e# Transliteration. Replaces elements from the sorted copy with
             e# the corresponding element in the shuffled copy in the original list.
             e# [[0 'f] [2 'o] [4 'a] [3 'b] [1 'o] [5 'r]].
Wf=          e# Get the last element of each pair, e.g. "foabor".
\$\endgroup\$
5
\$\begingroup\$

05AB1E, 17 bytes

žMÃ.r`¹vžMyå_iy}?

Explanation

žMÃ                # get all vowels from input
   .r`             # randomize them and place on stack
      ¹v           # for each in input
        žMyå_i }   # if it is not a vowel
              y    # push it on stack
                ?  # print top of stack

Try it online!

\$\endgroup\$
5
\$\begingroup\$

Python 3, 109 bytes

Only supports lowercase vowels.

Thanks to @Alissa for saving an extra byte.

import re,random
def f(s):r='[aeiou]';a=re.findall(r,s);random.shuffle(a);return re.sub(r,lambda m:a.pop(),s)

Ideone it!

\$\endgroup\$
  • \$\begingroup\$ wouldn't it be shorter if it's a function taking string and returning that string with shuffled vowels? \$\endgroup\$ – Alissa Aug 31 '16 at 12:57
  • \$\begingroup\$ @Alissa Thanks, it saved one byte! :D \$\endgroup\$ – Beta Decay Aug 31 '16 at 13:28
  • \$\begingroup\$ not sure if it will be any shorter, but you could a.pop(random.randrange(0,len(a))) instead of shuffling a \$\endgroup\$ – Alissa Aug 31 '16 at 15:26
4
\$\begingroup\$

TSQL, 275 bytes

Golfed:

DECLARE @ VARCHAR(99)='the quick brown fox jumps over the lazy dog.'

;WITH c as(SELECT LEFT(@,0)x,0i UNION ALL SELECT LEFT(substring(@,i+1,1),1),i+1FROM c
WHERE i<LEN(@)),d as(SELECT *,rank()over(order by newid())a,row_number()over(order by 1/0)b
FROM c WHERE x IN('a','e','i','o','u'))SELECT @=STUFF(@,d.i,1,e.x)FROM d,d e
WHERE d.a=e.b PRINT @

Ungolfed:

DECLARE @ VARCHAR(max)='the quick brown fox jumps over the lazy dog.'

;WITH c as
(
  SELECT LEFT(@,0)x,0i
  UNION ALL
  SELECT LEFT(substring(@,i+1,1),1),i+1
  FROM c
  WHERE i<LEN(@)
),d as
(
  SELECT 
    *,
    rank()over(order by newid())a,
    row_number()over(order by 1/0)b
  FROM c
  WHERE x IN('a','e','i','o','u')
)
SELECT @=STUFF(@,d.i,1,e.x)FROM d,d e
WHERE d.a=e.b
-- next row will be necessary in order to handle texts longer than 99 bytes
-- not included in the golfed version, also using varchar(max) instead of varchar(99)
OPTION(MAXRECURSION 0) 

PRINT @

Fiddle

\$\endgroup\$
3
\$\begingroup\$

Perl, 38 bytes

Includes +1 for -p

Run with the sentence on STDIN

vawols.pl <<< "programming puzzles & code golf"

vawols.pl:

#!/usr/bin/perl -p
@Q=/[aeiou]/g;s//splice@Q,rand@Q,1/eg
\$\endgroup\$
3
\$\begingroup\$

Java 7, 243 241 bytes

import java.util.*;String c(char[]z){List l=new ArrayList();char i,c;for(i=0;i<z.length;i++)if("aeiou".indexOf(c=z[i])>=0){l.add(c);z[i]=0;}Collections.shuffle(l);String r="";for(i=0;i<z.length;i++)r+=z[i]<1?(char)l.remove(0):z[i];return r;}

Yes, this can probably be golfed quite a bit, but Java doesn't have any handy built-ins for this a.f.a.i.k... Also, I kinda forgot the codegolfed array-variant for Collections.shuffle..

Ungolfed & test cases:

Try it here.

import java.util.*;
class M{
  static String c(char[] z){
    List l = new ArrayList();
    char i,
         c;
    for(i = 0; i < z.length; i++){
      if("aeiou".indexOf(c = z[i]) >= 0){
        l.add(c);
        z[i] = 0;
      }
    }
    Collections.shuffle(l);
    String r = "";
    for(i = 0; i < z.length; i++){
      r += z[i] < 1
               ? (char)l.remove(0)
               : z[i];
    }
    return r;
  }

  public static void main(String[] a){
    System.out.println(c("".toCharArray()));
    System.out.println(c("a".toCharArray()));
    System.out.println(c("cwm".toCharArray()));
    System.out.println(c("the quick brown fox jumps over the lazy dog.".toCharArray()));
    System.out.println(c("abcdefghijklmnopqrstuvwxyz".toCharArray()));
    System.out.println(c("programming puzzles & code golf".toCharArray()));
    System.out.println(c("fatalize".toCharArray()));
    System.out.println(c("martin ender".toCharArray()));
  }
}

Possible output:

a
cwm
tha queck brown fox jumps evor tho lezy dig.
ebcdifghujklmnopqrstavwxyz
prigrommeng puzzlos & cade golf
fatelazi
mertan inder
\$\endgroup\$
  • 1
    \$\begingroup\$ How about reusing i in the second loop? \$\endgroup\$ – Frozn Aug 31 '16 at 11:06
  • \$\begingroup\$ I thought "why didn't he go with char[] instead of a List", so I started, but the lack of Arrays.shuffle stopped me right there... \$\endgroup\$ – Olivier Grégoire Aug 31 '16 at 14:24
  • \$\begingroup\$ Shaved 6 characters with some minor tweaks: import java.util.*;String c(char[]z){List l=new ArrayList();int i=0,j=z.length;for(;i<j;i++)if("aeiou".indexOf(z[i])>=0){l.add(z[i]);z[i]=0;}Collections.shuffle(l);String r="";for(i=0;i<j;i++)r+=z[i]<1?(char)l.remove(0):z[i];return r;} \$\endgroup\$ – durron597 Sep 1 '16 at 19:52
3
\$\begingroup\$

Perl 6, 65 bytes

{my \v=m:g/<[aeiou]>/;my @a=.comb;@a[v».from]=v.pick(*);@a.join}

Anonymous function. Assumes lower-case input.

(try it online)

\$\endgroup\$
3
\$\begingroup\$

Ruby 45 + 1 = 46 bytes

+1 byte for -p flag

a=$_.scan(e=/[aeiou]/).shuffle
gsub(e){a.pop}
\$\endgroup\$
3
\$\begingroup\$

Brachylog, 39 bytes

@eI:1aToS,I:2f@~:LcS,Tc
.'~e@V;
e.~e@V,

Try it online!

Explanation

  • Main predicate:

    @eI        I is the list of chars of the input.
    :1aT       T is I where all vowels are replaced with free variables.
    oS,        S is T sorted (all free variables come first).
    I:2f       Find all vowels in I.
    @~         Shuffle them.
    :LcS,      This shuffle concatenated with L (whatever it may be) results in S.
                 This will unify the free variables in S with the shuffled vowels.
    Tc         Output is the concatenation of elements of T.
    
  • Predicate 1:

    .          Input = Output…
    '~e@V      …provided that it is not a vowel.
    ;          Otherwise Output is a free variable.
    
  • Predicate 2:

    e.         Output is an element of the input…
    ~e@V,      … and it is a vowel.
    
\$\endgroup\$
3
\$\begingroup\$

Javascript (ES6), 78 76 bytes

s=>s.replace(r=/[aeiou]/g,_=>l.pop(),l=s.match(r).sort(_=>Math.random()-.5))

Saved 2 bytes thanks to apsillers

Alternate version proposed by apsillers (76 bytes as well)

s=>s.replace(r=/[aeiou]/g,[].pop.bind(s.match(r).sort(_=>Math.random()-.5)))

Test

let f =
s=>s.replace(r=/[aeiou]/g,_=>l.pop(),l=s.match(r).sort(_=>Math.random()-.5))

console.log(f("the quick brown fox jumps over the lazy dog."))

\$\endgroup\$
  • 1
    \$\begingroup\$ Not an improvement (exact same score), but a fun uglification I found: drop the l=... entirely and use the bound function [].pop.bind(s.match(r).sort(_=>Math.random()-.5))) as the second argument to replace (instead of an arrow function). Maybe there's an improvement to be found down that road, but I haven't found one yet. If you used a JS-superset language that has the bind operator ::, I think you could do (s.match(r).sort(_=>Math.random()-.5)))::pop. \$\endgroup\$ – apsillers Aug 31 '16 at 17:41
3
\$\begingroup\$

MATL, 15 bytes

tt11Y2m)tnZr7M(

Try it online!

Explanation

tt      % Take input string implicitly. Duplicate twice
11Y2    % Predefined string: 'aeiou'
m       % Logical index that contains true for chars of the input that are vowels
)       % Get those chars from the input string. Gives a substring formed by the
        % vowels in their input order
tnZr    % Random permutation of that substring. This is done via random sampling
        % of that many elements without replacement
7M      % Push logical index of vowel positions again
(       % Assign the shuffled vowels into the input string. Display implicitly
\$\endgroup\$
3
\$\begingroup\$

Japt v2.0a0, 14 13 bytes

ō²f\v
NÌr\v@o

Try it


Explanation

           :Implicit input of string U.
ö²         :Generate a random permutation of U.
  f\v      :Get all the vowels as an array.
\n         :Assign that array to U.
NÌ         :Get the last element in the array of inputs (i.e., the original value of U)
  r\v      :Replace each vowel.
     @o    :Pop the last element from the array assigned to U above.
\$\endgroup\$
2
\$\begingroup\$

Pyth, 26 bytes

J"[aeiou]"s.i:QJ3.Sf}TPtJQ

A program that takes input of a quoted string and prints the shuffled string.

Try it online

How it works

J"[aeiou]"s.i:QJ3.Sf}TPtJQ  Program. Input: Q
J"[aeiou]"                  J="[aeiou]"
             :QJ3           Split Q on matches of regex J, removing vowels
                      PtJ   J[1:-1], yielding "aeiou"
                   f}T   Q  Filter Q on presence in above, yielding vowels
                 .S         Randomly shuffle vowels
           .i               Interleave non-vowel and vowel parts
          s                 Concatenate and implicitly print
\$\endgroup\$
2
\$\begingroup\$

PHP, 144 129 bytes

Using lowercase input

$r=Aaeiou;$v=str_shuffle(preg_replace("#[^$r]+#",'',$a=$argv[1]));for(;$i<strlen($a);)echo strpos($r,$a[$i++])?$v[$j++]:$a[$i-1];

Explanation:

$r="aeiou"; // set vowels

preg_replace("#[^$r]+#",'',$argv[1]) // find all vowels in input

$v=str_shuffle() // shuffle them

for(;$i<strlen($a);) // run through the text

strpos($r,$a[$i++])?$v[$j++]:$a[$i-1]; // if it's a vowel print the j-th shuffled vowel else print original text
\$\endgroup\$
2
\$\begingroup\$

Actually, 24 bytes

;"aeiou";╗@s@`╜íu`░╚@♀+Σ

Try it online!

Explanation:

;"aeiou";╗@s@`╜íu`░╚@♀+Σ
;                         dupe input
 "aeiou";╗                push vowels, store a copy in reg0
          @s              split one copy of input on vowels
            @`╜íu`░       take characters from other copy of input where
              ╜íu           the character is a vowel (1-based index of character in vowel string is non-zero)
                   ╚      shuffle the vowels
                    @♀+   interleave and concatenate pairs of strings
                       Σ  concatenate the strings
\$\endgroup\$
2
\$\begingroup\$

Bash, 75 bytes

paste -d '' <(tr aeoiu \\n<<<$1) <(grep -o \[aeiou]<<<$1|shuf)|paste -sd ''

Takes the string as an argument and prints the result to stdout.

Eg

for x in "" "a" "cwm" \
         "the quick brown fox jumps over the lazy dog." \
         "abcdefghijklmnopqrstuvwxyz" \
         "programming puzzles & code golf" \
         "fatalize" "martin ender"; do
  echo "$x";. sheffle.sh "$x"; echo
done

prints

<blank line>
<blank line>

a
a

cwm
cwm

the quick brown fox jumps over the lazy dog.
tho quuck brown fix jamps ever the lozy dog.

abcdefghijklmnopqrstuvwxyz
ibcdefghajklmnopqrstuvwxyz

programming puzzles & code golf
progremmong pazzlus & cedo gilf

fatalize
fetilaza

martin ender
mertan endir
\$\endgroup\$
2
\$\begingroup\$

Bash, 89

Assumes all input to be lowercase.

a=`tee z|grep -o [aeiou]`
[ -n "$a" ]&&tr `tr -d \ <<<$a` `shuf -e $a|tr -d '
'`<z||cat z
\$\endgroup\$
2
\$\begingroup\$

PowerShell v3+, 155 99 bytes

param([char[]]$n)$a=$n|?{$_-match'[aeiou]'}|sort{random};-join($n|%{if($_-in$a){$a[$i++]}else{$_}})

Big props to @Ben Owen for the 56-byte golf

Takes input $n, expecting all lowercase, immediately casts it as a char-array.

We pipe that into a Where-Object clause to pull out those elements that -match a vowel, pipe them to Sort-Object with {Get-Random} as the sorting mechanism. Calling Get-Random without qualifiers will return an integer between 0 and [int32]::MaxValue -- i.e., assigning random weights to each element on the fly. We store the randomized vowels into $a.

Finally, we loop through $n. For each element, |%{...}, if the current character is somewhere -in $a, we output the next element in $a, post-incrementing $i for the next time. Otherwise, we output the current character. That's all encapsulated in parens and -joined together into a string. That string is left on the pipeline, and output is implicit at program conclusion.

Test cases

PS C:\Tools\Scripts\golfing> 'a','cwm','the quick brown fox jumps over the lazy dog.','abcdefghijklmnopqrstuvwxyz','programming puzzles & code golf','fatalize','martin ender'|%{.\vawols.ps1 $_}
a
cwm
thu qaeck brown fix jomps ovor thu lezy deg.
abcdofghejklmnupqrstivwxyz
prugrammong pizzles & code golf
fitaleza
mertin endar
\$\endgroup\$
  • \$\begingroup\$ You can save a lot of bytes here by iterating through $n's characters and matching on each vowel to output the char-array of vowels instead. Something like: $a=[char[]]$n|?{$_-match'[aeiou]'}|sort{random} \$\endgroup\$ – Ben Owen Sep 1 '16 at 19:41
  • \$\begingroup\$ @BenOwen Holy dang, yes. Thanks for the 56-byte golf. For the life of me, I could just not figure out a better way to construct $a. \$\endgroup\$ – AdmBorkBork Sep 1 '16 at 19:54
2
\$\begingroup\$

Python 3, 106 bytes

Lowercase only.

import re,random
def f(s):s=re.split('([aeiou])',s);v=s[1::2];random.shuffle(v);s[1::2]=v;return''.join(s)
\$\endgroup\$
1
\$\begingroup\$

PHP >= 5.3, 139 136 bytes (and no errors thrown)

array_map(function($a,$b){echo$a.$b;},preg_split("/[aeiou]/",$s=$argv[1]),str_split(str_shuffle(implode(preg_split("/[^aeiou]/",$s)))));
\$\endgroup\$
1
\$\begingroup\$

K (oK), 29 bytes

Solution:

{x[a:&x in"aeiou"]:x@(-#a)?a}

Try it online!

Examples:

"pregrommeng pizzlas & codo gulf"
{x[a:&x in"aeiou"]:x@(-#a)?a}"programming puzzles & code golf"
"pregremmong puzzlos & coda gilf"
{x[a:&x in"aeiou"]:x@(-#a)?a}"programming puzzles & code golf"
"pregrommeng pazzlos & cidu golf"

Explanation:

Find locations of the vowels and replace with the vowels drawn in a random order.

{x[a:&x in"aeiou"]:x@(-#a)?a} / the solution
{                           } / anonymous function with input x
 x[              ]            / index into x at these indices
      x in"aeiou"             / is character a vowel
     &                        / indices where true
   a:                         / assign to add
                  :           / assign
                          ?a  / draw randomly from a
                     (   )    / do this together
                       #a     / count length of a
                      -       / negate (draws from list, no duplication)
                   x@         / apply these indices to input
\$\endgroup\$
0
\$\begingroup\$

APL (Dyalog Unicode), 21 bytes

{⍵[?⍨≢⍵]}@{⍵∊'AEIOU'}

Try it online!

Assumes uppercase.

\$\endgroup\$
  • \$\begingroup\$ Would {⍵∊'AEIOU'}∊∘'AEIOU' work? \$\endgroup\$ – Cows quack Apr 29 '18 at 14:55
  • \$\begingroup\$ @Cowsquack I don't think so, since then it would be parsed as ({⍵[?⍨≢⍵]}@∊)∘'AEIOU'. \$\endgroup\$ – Erik the Outgolfer Apr 29 '18 at 15:01
0
\$\begingroup\$

Kotlin, 122 118 bytes

x->val v=x.filter{"aeiuo".contains(it)}.toList().shuffled()
x.split(Regex("[aeiou]")).reduceIndexed{i,a,s->a+v[i-1]+s}

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.