127
\$\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\$
4
  • 1
    \$\begingroup\$ Test case for case insensitivity: MOONLIGHT. And just for fun: Why did the chicken cross the road? \$\endgroup\$
    – Titus
    Mar 1, 2017 at 11:05
  • 39
    \$\begingroup\$ Challenge sponsored by: National Stuttering Association \$\endgroup\$
    – sergiol
    Mar 1, 2017 at 23:34
  • 7
    \$\begingroup\$ Or Prof. Quirrell \$\endgroup\$
    – Brian J
    Mar 2, 2017 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, 2017 at 16:23

42 Answers 42

1
2
1
\$\begingroup\$

Pyth - 24 bytes

jd[Ke:Q"^.*?[aeiou]+"1KQ

Test Suite.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I think you maybe forgot y? \$\endgroup\$ Feb 27, 2017 at 18:04
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\$
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\$

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\$
1
\$\begingroup\$

Jelly, 13 bytes

e€ØyIi-⁸ḣ;⁶Ȯ;

Try it online!

Full program.

\$\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\$
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\$

Vyxal r, 16 bytes

k∩c)M¯uḟ₌iẎ+:"JṄ

Try it online!

Explanation:

   )              # Lambda from the beginning of the line
k∩                #   Does "aeiouyAEIOUY"
  c               #   Contain the lambdas argument
    M             # Map that lambda over the input string returning a list of 1s and 0s (1 if a vowel and 0 if not)
     ¯            # Differences between each 
      u           # Negative 1
       ḟ          # In the list of the differences, find the first index of that 
                  # (this will be the length of the string to prepend twice (let's call that s), minus 1. Let's call that number l)
        ₌         # Apply the next two elements to the top of the stack
         i        #   Index; get the lth character from the input (0-indexed)
          Ẏ       #   Get the first l characters from the input
           +      # Add (r flag flips argument order). 
                  # Now we have s, but found in a way that if l is -1 (i.e. -1 isn't in the deltas) s isn't just an empty string
            :     # Duplicate
             "    # Pair (resulting in [s, s])
              J   # Prepend (not append because of r flag) that to the input
               Ṅ  # Join by spaces
\$\endgroup\$
1
\$\begingroup\$

Thunno 2 J, 16 bytes

ð+k.s€ƇJTȮ⁺ɱð+ḌƤ

Try it online!

Explanation

ð+k.s€ƇJTȮ⁺ɱð+ḌƤ  # Implicit input
ð+                # Append a space to the input string
  k.s€Ƈ           # Check if each character is in the string "AEIOUYaeiouy"
       JTȮ⁺       # Find the first one-based index of [1, 0]
           ɱ      # Take this many characters from the start of the input
            ð+    # Append a space to this string
              ḌƤ  # Double it and append the input string
                  # Implicit output
\$\endgroup\$
0
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 70 bytes

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

Try it online!

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

Node.JS, 64 bytes

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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