123
\$\begingroup\$

This challenge is a tribute to the winner of Best Picture at the Oscars 2017, La La Land Moonlight!


Write a function/program that takes a string containing only letters [A-Za-z], the four symbols that are common in every day sentences .,'? and spaces, and outputs the string in the style of La La Land.

To be more specific, take the letters up to, and including, the first vowel group, and print/output it twice adding a space each time, then print/output the whole string. y is a vowel in this challenge. Punctuation and capitalization should be kept.

You may assume that all strings contain at least one vowel, and that all strings start with a letter.

Test cases:

Land
La La Land

Moonlight
Moo Moo Moonlight

quEueIng
quEueI quEueI quEueIng

This isn't a single word.
Thi Thi This isn't a single word.

It's fun to play golf
I I It's fun to play golf

Ooo
Ooo Ooo Ooo

I'm okay
I I I'm okay

Hmm, no. There will be at least one vowel, but it can be anywhere.
Hmm, no Hmm, no Hmm, no. There will be at least one vowel, but it can be anywhere.

Why is y a vowel?
Why Why Why is y a vowel?

This is so the shortest code in each language wins. Explanations are encouraged, also in mainstream languages.

\$\endgroup\$
  • 1
    \$\begingroup\$ Test case for case insensitivity: MOONLIGHT. And just for fun: Why did the chicken cross the road? \$\endgroup\$ – Titus Mar 1 '17 at 11:05
  • 35
    \$\begingroup\$ Challenge sponsored by: National Stuttering Association \$\endgroup\$ – sergiol Mar 1 '17 at 23:34
  • 6
    \$\begingroup\$ Or Prof. Quirrell \$\endgroup\$ – Brian J Mar 2 '17 at 19:26
  • 1
    \$\begingroup\$ 6th test case bought to you by Louis Prima and the Jungle Book. Joined just to add this (bad) pun. \$\endgroup\$ – Toby Mar 3 '17 at 16:23

40 Answers 40

0
\$\begingroup\$

C# (Visual C# Interactive Compiler), 79 75 bytes

Since it hasn't been posted yet...

f=>{var v=new Regex(".*?[aeiouyAEIOUY]+").Match(f).Value+" ";return v+v+f;}

Try it online!

\$\endgroup\$
12
\$\begingroup\$

PowerShell, 46 47 41 39 38 bytes

$args-replace"^.*?[aeiouy]+",(,'$&'*3)

Try it online!

Thanks to Maarten Bamelis for the bugfix

Saved 6 bytes thanks to Rynant

Saved 2 3 bytes thanks to Joey

\$\endgroup\$
2
\$\begingroup\$

C (gcc), 111 110 bytes

*d="AEIOUYaeiouy";b;f(char*a){b=strcspn(a,d);write(printf(" "),a,write(1,a,b+strspn(a+b,d)));printf(" %s",a);}

Try it online!

This just uses library functions strspn() and strcspn() and exploits the order in which gcc evaluates function parameters. Slightly less golfed

*d="AEIOUYaeiouy";b;
f(char*a){
  b=strcspn(a,d);
  write(printf(" "),a,write(1,a,b+strspn(a+b,d)));
  printf(" %s",a);
}

Thanks to @gastropner for -1.

\$\endgroup\$
0
\$\begingroup\$

Node.JS, 64 bytes

console.log(process.argv[2].replace(/.*?[aeiouy]+/i,"$& $& $&"))
\$\endgroup\$
  • \$\begingroup\$ just use a lambda function, it's shorter \$\endgroup\$ – ASCII-only Apr 4 at 1:07
0
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 70 bytes

	T =INPUT
	T (ARB SPAN('AEIOUYaeiouy')) . X
	OUTPUT =X ' ' X ' ' T
END

Try it online!

\$\endgroup\$
4
\$\begingroup\$

R, 49bytes

sub("(.*?[aeiouy]+)","\\1 \\1 \\1",scan(,""),T,T)

Regex based replace, match everything until not a vowel, capture and replace it by itself 3 times.

scan wait for a double type input, to tell it to use character type we have to give it two arguments, first is the default , emtpy string for stdin, and for the second the R evaluation allow to use only c as it's not ambiguous for character in this context.

T stands for TRUE and save some char as 4th and 5th parameter to sub to tell it to ignore case and use PCRE (the greedyness is not the same with R regex syntax)

4 bytes saved courtesy of Sumner18 along with the Tio link to running code

\$\endgroup\$
1
\$\begingroup\$

Java 8, 49 bytes

Lambda from String to String.

s->s.replaceAll("(?i)^(.*?[aeiouy]+)","$1 $1 $1")

Try It Online

The same regular expression approach many are using. (?i) turns on case insensitivity, the capture group is substituted for each $1 in the replacement string, and .*? is lazy so that it doesn't match vowels.

\$\endgroup\$
1
\$\begingroup\$

Julia 0.6, 45 bytes

s->(match(r"^.*?[aeiouy]+"i,s).match*" ")^2*s

Try it online!

A pretty straightforward regex-based solution (for now at least). * is a concatenation operator when applied to strings, and ^ is a self-concatenation operator - "Moo "^2 == "Moo "*"Moo " == "Moo Moo ".

\$\endgroup\$
4
\$\begingroup\$

PHP, 69 65 53 bytes

<?=preg_filter("#.*?[aeiouy]+#i","$0 $0 $0",$argn,1);

requires PHP 5.3 or later. Run as pipe with -F or try some versions online.

Saved 4 bytes (and fixed the code) with regex stolen from @aross;
10 more with preg_filter instead of preg_match and -F
and another two with an improved regex.

75 81 bytes for a non-regex version:

for(;$c=$argn[$i++];)($k+=$k^!trim($c,aeiouyAEIOUY))>1?:$w.=$c;echo"$w $w $argn";

requires PHP 5 or later; replace ?: with ?1: for older PHP. Run with -nR

Breakdown

for(;$c=$argn[$i++];)       // loop $c through input characters
    ($k+=$k^!                   // 2. !$k and vowel or $k and not vowel: increment $k
        trim($c,aeiouyAEIOUY)   // 1. strip vowels -> vowel=false, non-vowel=true
    )>1                         // 3. if $k>1
    ?                           // do nothing
    :$w.=$c;                    // else append $c to $w
echo"$w $w $argn";          // output
\$\endgroup\$
  • \$\begingroup\$ Doesn't appear to work. Out put for This isn't a single word: T T This isn't a single word. \$\endgroup\$ – aross Feb 27 '17 at 12:20
  • \$\begingroup\$ @aross seems it's checking just lowercase values? I may be wrong I don't know PHP that well \$\endgroup\$ – Albert Renshaw Mar 1 '17 at 10:53
  • 1
    \$\begingroup\$ @AlbertRenshaw The regex version uses the i modifier that renders the regex case insensitive. The other one version did only check lowercase. Fixed. \$\endgroup\$ – Titus Mar 1 '17 at 11:02
0
\$\begingroup\$

Jelly, 13 bytes

e€ØyIi-⁸ḣ;⁶Ȯ;

Try it online!

Full program.

\$\endgroup\$
1
\$\begingroup\$

Japt v2.0a0, 17 bytes

r/^.*?\y+/@[XXX]¸

Try it | Check all test cases


Explanation

                      :Implicit input of string
r/^.*?\y+/            :RegEx replace
                      :  ^ is required to save the extra bytes disabling the g flag
                      :  \y is the class for [AEIOUYaeiouy]
          @[XXX]      :An array containing three copies of the match
                ¸     :Joined to a string with spaces
                      :Implicit output of result
\$\endgroup\$
6
\$\begingroup\$

Perl, 25 + 1 (-p flag)

s/.*?[aeiouy]+/$& $& $&/i
\$\endgroup\$
5
\$\begingroup\$

C, 202 196 195 193 190 180

i,j,k,m,n;f(char*a){if((a[i/12]-"AEIOUY"[i++%6])%32==0)k=n=24-(i%12);else if(k&&!n--){m=j=(i-13)/12;for(i=0;i<j*2;)printf("%c%c",a[i%j],(i==j-1)*32),i++;printf(" %s", a);}m?:f(a);}

Try it online!


Thing left to golf:

•Collapse two printf into one.

•Printing my space char can be changed into %*c logic I'm sure.

•I'm using conditionals which can be removed somehow

j=(i-13)/12 can likely be shortened.

•[A-Y] conditional checks if ==0 which is usually un-necessary, though I'm currently stuck on that one (tried switching if-else and ditching the ==0 altogether but that requires adding more {brackets} and increase byte size)


Tricks I've used to golf this down:

•Combined a double for loop string search by using modulo for x-axis and integer-division for y-axis (input string vs vowel string). (X-axis is looped twice before iterating once on y-axis; the first time with [A-Z] and the second time with [a-z] using character value 32 differential.

•Bypassed having to use "[A-Y] and [a-y]" by just taking the distance between character sets and modulo 32. That way if the distance is 0 (A-A) or if the distance is 32 (a-A)

•Re-using integer variables that are no longer in use as boolean variables.

•Recursively calling a function with the same string to process through it and avoid a second for-loop.

•Set BOOL values to the logic of setting another variable. (e.g. bool = i=5;) to knock out both with one stone.

•Ternary empty-true exploit abuse. (GCC)


Readable Format:

i,j,k,m,n;
f(char*a){
    if((a[i/12]-"AEIOUY"[i++%6])%32==0)
        k=n=24-(i%12);
    else
        if(k&&!n--){
            m=j=(i-13)/12;
            i=0;
            for(;i<j*2;)
               printf("%c%c",a[i%j],(i==j-1)?32:0),i++;
            printf(" %s", a);
        }
    m?:f(a);
}

Knocked off 10 bytes thanks to Keyu Gan (in comments)

\$\endgroup\$
  • \$\begingroup\$ Note to self: j=(i-13)/12 can likely be shortened. \$\endgroup\$ – Albert Renshaw Feb 27 '17 at 21:51
  • \$\begingroup\$ Am I missing something, or could you start with i=j=k=m=n=0;? \$\endgroup\$ – Richard Irons Mar 1 '17 at 10:05
  • \$\begingroup\$ @RichardIrons the variables have to be declared first. \$\endgroup\$ – Albert Renshaw Mar 1 '17 at 10:33
  • \$\begingroup\$ You may use i,j,k,m,n; for initialization. \$\endgroup\$ – Keyu Gan Jun 7 '17 at 18:14
  • \$\begingroup\$ @KeyuGan undefined behavior, not guaranteed to always be 0. (as far as I know?) \$\endgroup\$ – Albert Renshaw Jun 7 '17 at 22:20
1
\$\begingroup\$

APL (Dyalog), 28 bytes

'(?i)^.*?[aeiouy]+'⎕R'& & &' or 29 chars: '^.*?[aeiouy]+'⎕R'& & &'⍠1

Simply a ((?i) or ⍠1) case-insensitive PCRE Replace of

^ the beginning
.*? zero or more characters (lazy)
[aeiouy]+ one or more vowels

with

& & & the entire match thrice with spaces inbetween


Version without RegEx, 43 bytes

⊢(↑,' ',↑,' ',⊢)⍨1⍳⍨1 0⍷'aeiouy'∊⍨' ',⍨819⌶

819⌶ lowercase

' ',⍨ append a space

'aeiouy'∊⍨ which letters are vowels

1 0⍷ vowels that are followed by a non-vowel

1⍳⍨ index of first one

⊢()⍨ apply the following tacit function with the string as right argument, and the above index as left argument

 that many characters taken from the string

, followed by

 that many characters taken from the string

, followed by

 the string

\$\endgroup\$
1
\$\begingroup\$

C, 150 146 bytes

f(char*s){char*v="aeiouyAEIOUY",*p=strpbrk(s,v);int i=strspn(p,v),f=i+(p-s),d=0,j=2;while(j--)while(d<f)putchar(s[d++]);d=0,putchar(' ');puts(s);}

Ungolfed:

#include <stdio.h>
#include <string.h>

int main(void)
{
    char *s = "Land";  // change this

    char *p = strpbrk(s, "aeiouyAEIOUY");
    int count = strspn(p, "aeiouyAEIOUY");

    int idx = count + (p - s);

    int i, j = 2;

    while (j--)
    {
        while (i < idx)
            putchar(s[i++]);

        i = 0;
        putchar(' ');
    }

    puts(s);
}

How it works:

  • strpbrk finds the first vowel and returns a pointer p.
  • strspn finds how many vowels there are in a row in p and returns an integer count.
  • The index idx of the last vowel equals count (# of vowels) + p - s (index of first vowel).
  • Print the first idx characters in s, twice.
\$\endgroup\$
1
\$\begingroup\$

Python 3, 102 99 bytes

def l(s,v=0):
 for l in range(len(s)):
  if s[l]in"aeiouyAEIOUY":v=1
  elif v:return(s[:l]+" ")*2+s

Running on IDLE, so the Print/output part stands

>>> l("Land")
'La La Land'

Managed to shave off a space or two, and replace .lower() with simply adding uppercase vowels to the check.

\$\endgroup\$
4
\$\begingroup\$

Ohm, 19 bytes (CP437), non-competing

New language, and as such, I had to add some new features to make this work, which sadly makes this non-competitive (because loopholes).

≡┬üC▓αy_ε;TF«u├DQüj

Explanation:

≡┬üC▓αy_ε;TF«u├DQüj     Main wire, arguments: s

≡                       Triplicate input
 C                    Push input, all lowercase with concatenated space character
    ▓    ;              Map string into an array with...
     αy_ε                 Boolean: is element a vowel?
          TF«u          Find first occurrence of [true, false]
              ├D        Slice input up to that index and duplicate it
                Q       Reverse stack
                 üj     Join on spaces, implicitly print
\$\endgroup\$
  • \$\begingroup\$ I'm curious to know which features you implemented...? \$\endgroup\$ – Stewie Griffin Feb 27 '17 at 21:04
  • \$\begingroup\$ @StewieGriffin Stack reversal (Q), subarray searching (u), string/array slicing (), and vowel constants (αv and αy). \$\endgroup\$ – Nick Clifford Feb 28 '17 at 0:02
2
\$\begingroup\$

MATLAB / Octave, 58 51 bytes

7 Bytes saved thanks to @HughNolan

@(x)regexprep(x,'(^.*?[aeiouyAEIOUY]+)','$1 $1 $1')

Creates an anonymous function named ans which can be called by passing a string to it: ans('Land')

Online Demo

For MATLAB compatibility, $0 should be used in place of $1 in the above function.

\$\endgroup\$
  • \$\begingroup\$ Was thinking about this and then saw you had it done already. Save a few bytes: @(x)regexprep(x,'^.*?[aeiouyAEIOUY]+','$0 $0 $0 '); - also Matlab seems to use $0 rather than $1 strangely \$\endgroup\$ – Hugh Nolan Mar 1 '17 at 12:13
  • \$\begingroup\$ @HughNolan Great point, thanks! \$\endgroup\$ – Suever Mar 1 '17 at 14:27
4
\$\begingroup\$

Python 3, 101 96 bytes

s=input()
v=i=0
for c in s:
 w=c in'aAeEiIoOuUyY'
 if v*~-w:break
 v=w;i+=1
print(s[:i],s[:i],s)

Try it online!

a non-regex solution


Commented:

s=input()
a='aAeEiIoOuUyY'
v=i=0
for c in s:          # for each character in the string
 w=c in a            # w = True if the character is a vowel, else false
                     # true is equivalent to 1  and false to zero
                     # v*(w-1) evaluates only to true (-1 in this case) if v=1 (last character was a vowel) and w=0 (current character is not a vowel)
 if v*(w-1):break    # if so, break the loop
 v=w;i+=1            # increase the counter and set v to w
print(s[:i],s[:i],s)
\$\endgroup\$
  • \$\begingroup\$ Why do you need a? Replace w=c in a with w=c in'aAeEiIoOuUyY' \$\endgroup\$ – sagiksp Mar 1 '17 at 10:14
3
\$\begingroup\$

C, 123 bytes

#define v(x)while(x strchr("AEIOUY",*s&95))++s;
a;f(s,t)char*s,*t;{t=s;v(!)v()a=*s;*s=0;printf("%s %s ",t,t);*s=a;puts(t);}

Call as:

main(){char s[] = "queueing"; f(s);}
\$\endgroup\$
  • 1
    \$\begingroup\$ This is nice! You knocked my C solution out of the park lol. \$\endgroup\$ – Albert Renshaw Mar 1 '17 at 10:54
19
\$\begingroup\$

Python, 61 bytes

import re;lambda x:re.sub('(.*?[aeiouy]+)',r'\1 \1 \1',x,1,2)

Here comes the first non-regex-based language (using regex).

Saved 1 byte thanks to Neil.

\$\endgroup\$
2
\$\begingroup\$

Python 3, 130 102 bytes

w=input();a='';v=0
for i in w:
	if i in 'aeiouyAEIOUY': v=1
	elif v:
		break
	a+=i
a+=' ';print(a*2+w)

Try it online!

Uses no function of any kind and no external libraries! (Unless print and input count as functions, which they do).

Works by seeing if it gets out of the consonants in the start of the title into the 'vowel zone'. If it is in the 'vowel zone' and detects a consonant, then it prints the title.

Saved 28 bytes thanks to @LliwTelracs

\$\endgroup\$
4
\$\begingroup\$

Clojure, 192 188 181 bytes

(fn[p](let[[f] p v #(#{\a \e \i \o \u \y}(Character/toLowerCase %))[q r](split-with(if(v f)v #(not(v %)))p)[w _](split-with v r)as #(apply str %)](str(as(repeat 2(str(as q)(as w) \ )))p)))

-4 bytes by inlining first-sp-pred (whoops).

-7 bytes by removing some missed spaces

This was far more challenging than I thought it would be going in! I'm manually parsing the string...since I still haven't gotten around to learning regex :/

See pre-golfed code for breakdown:

(defn repeat-prefix-cons [phrase]
  (let [[first-letter] phrase ; Get first letter

        ; Function that checks if a lowercased character is a part of the vowel set
        vowel? #(#{\a \e \i \o \u \y} (Character/toLowerCase %))

        ; cons(onant)? Negation of above
        cons? #(not (vowel? %))

        ; Decide how to split it depending on if the first character is a vowel
        first-sp-pred (if (vowel? first-letter) vowel? cons?)

        ; Split off the first chunk of cons/vowels
        [pre1 r] (split-with first-sp-pred phrase)

        ; Split off the rest of the vowels
        [pre2 r2] (split-with vowel? r)

        ; Shortcut function that turns a list into a string (Basically (join "" some-list-of-strings) )
        as #(apply str %)]

    (str ; ... then concat the prefix in front of the original phrase, and return
      (as ; ...then turn it back into a string since "repeat" returns a list... ^
        (repeat 2 ; ... then repeat it twice (shame Clojure doesn't have string multiplication)... ^
                (str (as pre1) (as pre2) \ ))) ; Concat the 2 prefix parts together with an space at the end... ^
      phrase)))
\$\endgroup\$
6
\$\begingroup\$

Javascript (ES6), 38 bytes

x=>(y=/.*?[aeiouy]+/i.exec(x)+' ')+y+x

f=
x=>(y=/.*?[aeiouy]+/i.exec(x)+' ')+y+x
<!-- snippet demo: -->
<input list=l oninput=console.log(f(this.value))>
<datalist id=l><option value=Land>
<option value=Moonlight>
<option value=queueing>
<option value="This isn't a single word.">
<option value="It's fun to play golf">
<option value=Ooo>
<option value="I'm okay.">
<option value="Hmm, no. There will be at least one vowel, but it can be anywhere.">
<option value="Why is y a vowel?">

\$\endgroup\$
8
\$\begingroup\$

Ruby, 31 32 30 Bytes

->s{(s[/.*?[aeiouy]+/i]+' ')*2+s}

Two bytes saved thanks to G B and Cyoce.

\$\endgroup\$
4
\$\begingroup\$

Python 3, 75 68 bytes

lambda s:(s[:[x in"aAeEiIoOuUyY"for x in s][1:].index(0)+1]+" ")*2+s

Try it online!

Explanation:

Works by generating a boolean value for every character in the input string based on whether or not it is a vowel, and finding the lowest index of 0, the first non-vowel (excluding the first character). It returns the substring to this index twice,separated by spaces, and the original string.

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

Java 8, 147 140 bytes

Golfed:

import java.util.regex.*;s->{Matcher m=Pattern.compile("([^aeiouy]*[aeiouy]+)",2).matcher(s);m.find();return m.group()+" "+m.group()+" "+s;}

Ungolfed:

import java.util.regex.*;

public class LaLaLandNoWaitMooMooMoonlight {

  public static void main(String[] args) {
    for (String[] strings : new String[][] { { "Land", "La La Land" }, { "Moonlight", "Moo Moo Moonlight" },
        { "queueing", "queuei queuei queueing" }, { "This isn't a single word.", "Thi Thi This isn't a single word." },
        { "It's fun to play golf", "I I It's fun to play golf" }, { "Ooo", "Ooo Ooo Ooo" },
        { "I'm okay", "I I I'm okay" }, { "Hmm, no. There will be at least one vowel, but it can be anywhere.",
            "Hmm, no Hmm, no Hmm, no. There will be at least one vowel, but it can be anywhere." } }) {
      final String input = strings[0];
      final String expected = strings[1];
      final String actual = f(s -> {
        java.util.regex.Matcher m = java.util.regex.Pattern.compile("([^aeiouy]*[aeiouy]+)", 2).matcher(s);
        m.find();
        return m.group() + " " + m.group() + " " + s;
      } , input);
      System.out.println("Input:    " + input);
      System.out.println("Expected: " + expected);
      System.out.println("Actual:   " + actual);
      System.out.println();
    }

  }

  private static String f(java.util.function.Function<String, String> function, String input) {
    return function.apply(input);
  }
}

Note: the literal 2 in the code is the value of java.util.regex.Pattern.CASE_INSENSITIVE.

\$\endgroup\$
  • 2
    \$\begingroup\$ I think you can use import java.util.regex.*; to save some bytes. \$\endgroup\$ – Roman Gräf Feb 27 '17 at 20:14
  • \$\begingroup\$ @RomanGräf you are correct. I had the packages spelled out because in an earlier version of the code (did not work) it was shorter not to use imports. I did not reevaluate after fixing the code. \$\endgroup\$ – user18932 Feb 27 '17 at 21:00
18
\$\begingroup\$

JavaScript (ES6), 40 46

Edit 5+1 bytes saved thx @Arnauld

Overly long compared to other using the same trick (as usual)

x=>x.replace(/.*?[aeiouy]+/i,'$& $& $&')

let f=
x=>x.replace(/.*?[aeiouy]+/i,'$& $& $&')

test=`Land
La La Land

Moonlight
Moo Moo Moonlight

queueing
queuei queuei queueing

This isn't a single word.
Thi Thi This isn't a single word.

It's fun to play golf
I I It's fun to play golf

Ooo
Ooo Ooo Ooo

I'm okay
I I I'm okay

Hmm, no. There will be at least one vowel, but it can be anywhere.
Hmm, no Hmm, no Hmm, no. There will be at least one vowel, but it can be anywhere.`
test.split(`\n\n`).forEach(z=>{
  var [i,k]=z.split(`\n`),x=f(i);
  console.log(k==x ? 'OK':'KO',i+'\n'+x);
})

\$\endgroup\$
  • \$\begingroup\$ @Arnauld no, but I could use '$& $& $&' - I always forget the special dollar chars. Thank you. Unfortunately now it's really a port of Martin's retina answer. \$\endgroup\$ – edc65 Feb 27 '17 at 9:51
  • \$\begingroup\$ The ^ is required in Retina which -- I think -- looks for all matches by default. But do we really need it here? \$\endgroup\$ – Arnauld Feb 27 '17 at 10:03
  • \$\begingroup\$ @Arnauld you're right again \$\endgroup\$ – edc65 Feb 27 '17 at 13:09
  • \$\begingroup\$ -2: x=>(y=/.*?[aeiouy]+/i.exec(x)+' ')+y+x \$\endgroup\$ – nderscore Feb 27 '17 at 16:31
  • \$\begingroup\$ @ETHproductions in fact. Thanks for noticing. \$\endgroup\$ – edc65 Feb 27 '17 at 20:41
4
\$\begingroup\$

V, 21, 20 bytes

é /ã[aeiouy]«“.
3ä|<

Try it online!

Explanation:

é               " Insert a space
  /             " Jump forward too...
   ã[aeiouy]«. "   The first non-vowel after a vowel
3ä              " Make three copies of
  |             " Everything from the cursor to the first character
   <            " Delete the space we inserted

Hexdump:

00000000: e920 2fe3 5b61 6569 6f75 795d ab93 2e0a  . /.[aeiouy]....
00000010: 33e4 7c3c                                3.|<

Alternate version (21 bytes):

Í㨃[aeiouy]«©/± ± &

Try it online!

This uses ridiculous regex compression, and it still manages to get it's butt kicked by the other golfing languages. For reference, this is about two/thirds the length of the regular "uncompressed" version, namely:

:%s/\v\c(.{-}[aeiou]).*/\1 \1 &

Explanation:

Í                               " Replace on every line:
 ã                              "   Case-insensitive
  ¨              ©              "   Capture-group 1
   <131>                        "   Any character, any number of times (non-greedy)
        [aeiouy]«               "   A vowel, repeated once or more
                  <129>         "   Followed by anything
                       /        " Replaced with:
                        ± ±     "   Capture group one twice, with spaces between
                            &   "   The whole matched pattern

Here is a hexdump:

00000000: cde3 a883 5b61 6569 6f75 795d aba9 812f  ....[aeiouy].../
00000010: b120 b120 26                             . . &
\$\endgroup\$
  • 2
    \$\begingroup\$ +1 This has got to be the most impressive V regex submission I ever saw \$\endgroup\$ – Cows quack Feb 27 '17 at 18:25
  • \$\begingroup\$ Try it online! \$\endgroup\$ – nmjcman101 Feb 27 '17 at 18:35
4
\$\begingroup\$

MATL, 33 bytes

'(^.*?[yY%s]+)'13Y2YD'$1 $1 $1'YX

Try it at MATL Online

Explanation

                % Implicitly grab input as a string
'(^.*?[yY%s]+)' % Push this string literal (regex pattern)
13Y2            % Push the string literal 'AEIUOaeiuo'
YD              % Replace the '%s' in the string with 'AEIUOaeiuo'
'$1 $1 $1'     % Push the string literal to use for replacement which repeats
                % the first match 3 times
YX              % Perform regular expression matching and replacement
                % Implicitly display the result
\$\endgroup\$
  • \$\begingroup\$ '(^.*?[yY%s]+)'13Y2YD'$1 '8:)YX saves 2 bytes \$\endgroup\$ – Luis Mendo Jun 7 '17 at 17:00
  • \$\begingroup\$ '(^.*?[%s]+)'19Y2YD'$1 '8:)YX saves another 2 \$\endgroup\$ – B. Mehta Sep 18 '17 at 22:48
  • \$\begingroup\$ @B.Mehta 19Y2 didn't exist when this answer was submitted unfortunately \$\endgroup\$ – Suever Sep 18 '17 at 22:56
  • \$\begingroup\$ Yeah, slightly expected that reply... I'll keep my comment so others can learn about inbuilt literal 'aeiouy' too. \$\endgroup\$ – B. Mehta Sep 18 '17 at 22:59
  • \$\begingroup\$ @B.Mehta No worries. With MATL Online (matl.suever.net) you can select a specific version using the drop-down on the top right \$\endgroup\$ – Suever Sep 19 '17 at 0:32

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.