| Bytes | Lang | Time | Link |
|---|---|---|---|
| 123 | Python | 241125T113334Z | Joon Yor |
| 016 | Japt Sx | 241011T131537Z | Shaggy |
| 021 | Pip | 241030T180648Z | DLosc |
| 017 | Vyxal s | 241011T010339Z | lyxal |
| 118 | AWK | 241029T144646Z | xrs |
| 043 | Ruby | 241012T031245Z | DrQuariu |
| 033 | Perl 5 p | 241011T151332Z | Xcali |
| 045 | Sed | 241011T110921Z | Toby Spe |
| 026 | 05AB1E | 241011T084101Z | Kevin Cr |
| 033 | Charcoal | 241011T063404Z | Neil |
| 049 | JavaScript Node.js | 241011T013249Z | l4m2 |
| 037 | Retina 0.8.2 | 241011T044913Z | Neil |
| 016 | Vyxal | 241011T023608Z | emanresu |
| 019 | Jelly | 241011T020839Z | Unrelate |
Python, 123 bytes
f=lambda s,j=0:"".join(x+" "*((j:=j+d)-(x<"!"))if x in"aeiouAEIOU "and(d:=(y in" ,.")<1)else x for x,y in zip(s,s[1:]+" "))
Looking at the other solutions I'm pretty sure using regex would be shorter but this is the best I can do
Japt -Sx, 18 16 bytes
r"%v%B"Èú2øË+Eç
r"%v%B"Èú2øË+Eç :Implicit input of string
r :Replace
"%v%B" : RegEx /[aeiou]\B/gi
È : Pass each match through the following function
ú2 : Right pad with spaces to length 2
à :End replace
¸ :Split on spaces
Ë :Map each element at 0-based index E
+ : Append
Eç : Space repeated E times
:Implicit output joined with spaces and trimmed
Pip, 21 bytes
aR-XV.`\B`_.sRssX{Ui}
Explanation
aR-XV.`\B`_.sRssX{Ui}
a ; Command-line input
R ; Replace:
XV ; Regex matching a vowel
- ; Case-insensitive
. ; Concatenate
`\B` ; Regex matching non-word-boundary (next character is a letter)
; with:
_ ; The matched character
.s ; Concatenated with a space
R ; Then, replace:
s ; Space
; with:
{Ui} ; Increment i (initially 0)
sX ; That many spaces
Vyxal s, 136 bitsv2, 17 bytes
øWƛṫ$ƛA꘍;p∑;ṅƛð=[&›¥I
Bitstring:
0001011010100000000000101000111001001011011000111111100111100100001000101110110101111001100100010101101111110101110101000000101011011000
A very silly approach
Explained
øWƛṫ$ƛA꘍;p∑;ṅƛð=[&›¥I
øW # Split on words (i.e. spaces, but also punctuation, etc)
ƛ ; # To each word:
ṫ$ # Push word[-1], word[:-1]
ƛ ; # To each character in word[:-1]
A꘍ # Append a space if the character is a vowel
p # Add the last letter back to the end
∑ # Join into a single string
ṅ # Join the list of modified words back into a sentence
ƛ # To each character:
ð= # If it's a space:
&› # Increment the register (starts at 0)
¥I # and then push that many spaces
The s flag joins the result into a single string
💎
Created with the help of Luminespire.
AWK, 118 bytes
BEGIN{FS=X}{for(;++i<=NF;){d=d$i
$i~/ /&&(d=d y)&&y=y" "
$i~/[AEIOUaeiou]/&&$(i+1)!~/[ \.,]/&&(y=y" ")&&d=d y}print d}
BEGIN{FS=X} # split input by character
{for(;++i<=NF;){d=d$i # pop next letter onto string d
$i~/ /&&(d=d y)&&y=y" " # special case for space
$i~/[AEIOUaeiou]/&&$(i+1)!~/[ \.,]/&&(y=y" ")&&d=d y}
print d} # ^vowel/punctuationmatching
Ruby, 43 bytes
->x{x.gsub(/ |(?<=[aeiou])\B/i){' '*$.+=1}}
Simply a direct port of l4m2's JavaScript solution. Uses the global $. which counts which line of input we are 'up to' so always starts at 0. Had to reset it to 0 manually in the header only because I wanted to repeat the function on all the test cases. I formatted the ATO link so that correct solutions are shown above the code's output for comparison.
Sed, 45 bytes
s/[aouei]\B/&_/gi
y/ /_/
:a
s/_/ &/g
s/_//
ta
We use _ as a placeholder for the spaces we add (line 1) and any pre-existing spaces (line 2), then we loop (line 3), adding a space to all the placeholders (line 4) and removing the first one (line 5), repeating the loop until no more placeholders remain (line 6).
We can see the progression if we add some debug printing in the loop:
l
s/[aouei]\B/&_/gi
y/ /_/
:a
l
s/_/ &/g
s/_//
ta
fo am to, ex.$
fo_a_m_to,_e_x.$
fo a _m _to, _e _x.$
fo a m _to, _e _x.$
fo a m to, _e _x.$
fo a m to, e _x.$
fo a m to, e x.$
05AB1E, 27 26 bytes
ü2ε¬lžMëágÍ}0šÅ¡Jðý#íāúíJ
Try it online or verify all test cases.
Or alternatively:
Ćü2ε¬DŠlžMëágÍið«]J#íāúíJ
Try it online or verify all test cases.
It feels way too long, but I'm not seeing it.. :/
Explanation:
ü2 # Get all overlapping pairs of the (implicit) input
ε # Map over each pair:
¬ # Push the first character of the pair (without popping)
l # Convert it to lowercase
žMÃ # Only keep the vowels "aeiou"
« # Append it to the pair
á # Only keep the letters of this now pair or triplet
g # Pop and push its length
Í # Decrease it by 2
}0š # After the map: prepend a leading 0
Å¡ # Split the (implicit) input before every truthy (==1) position
# (side effect: parts become lists of characters)
J # Join each inner list of characters back to a string
ðý # Then join this list of parts with a space delimiter
# # Split it by spaces
í # Reverse each part
ā # Push a list in the range [1,length] (without popping)
ú # Pad each reversed string with that amount of leading spaces
í # Reverse the strings back, since we wanted trailing spaces
J # Join everything together
# (after which the result is output implicitly)
Ć # Enclose; append its own first character to the (implicit) input
ü2 # Pop and get all overlapping pairs
ε # Map over each pair:
¬ # Push the first character of the pair (without popping)
D # Duplicate it
Š # Triple-swap [pair,head,head] to [head,pair,head]
lžMëágÍ # Similar as above
i # If this is truthy (==1):
ð« # Append a space to the head
] # Close both the if-statement and map
J # Join everything together
#íāúíJ # Same as above
# (after which the result is output implicitly)
Charcoal, 33 bytes
FS«F№⁺ ω↧ι⭆⊞Oυ¹ F›ι ι≔×β№aeiou↧ιω
Try it online! Link is to verbose version of code. Explanation:
FS«
Loop through the input string.
F№⁺ ω↧ι
If the current character is a space, or it is a letter and the previous character was a vowel, then...
⭆⊞Oυ¹
...output one more space than last time.
F›ι ι
Output the current character if it is not a space.
≔×β№aeiou↧ιω
Remember whether the current character is a vowel for the next pass.
Alternative approach, also 33 bytes:
⭆⪪⭆θ⎇∧κ∧№β↧ι№aeiou↧§θ⊖κ⁺ ιι ⁺× κι
Try it online! Link is to verbose version of code. Explanation:
θ Input string
⭆ Map over characters and join
κ Current index
∧ Logical And
№ Count of
ι Current character
↧ Lowercased
β In predefined variable lowercase alphabet
∧ Logical And
№ Count of
θ Input string
§ Indexed by
κ Current index
⊖ Decremented
↧ Lowercased
aeiou In literal string `aeiou`
⎇ If true then
Literal space
⁺ Concatenated with
ι Current character
ι Else current character
⪪ Split on spaces
⭆ Map over each part and join
Literal space
× Repeated by
κ Current index
⁺ Plus
ι Current part
Implicitly print
Retina 0.8.2, 37 bytes
i`[aeiou]\B
$&
(?<=(( )|.)+)
$#2$*
Try it online! Link includes test cases. Explanation:
i`[aeiou]\B
$&
Insert spaces after every non-trailing vowel in either upper or lower case.
(?<=(( )|.)+)
$#2$*
Replace each space with the spaces so far, obtained by counting them in a lookbehind and then repeating a space by the count.
24 bytes in Retina 1:
i` |([aeiou])\B
$1$>:&*
Try it online! Link includes test cases. Explanation: $>:& gives the match index, which is then used to repeat spaces, so all that remains is to replace all of the spaces and append to all of the non-trailing vowels.
Vyxal, 16 bytes
⇧a?Aǔ*ÞṗṠ⌈fꜝ₅ɽ꘍∑
Try it Online! I don't like this but it's probably optimal. +4 bytes due to the weird punctuation requirement that isn't at all clearly specified.
Þṗ # Partition before indices where
ǔ # The character before
?A # is a vowel
* # And
⇧a # The character after is a letter
Ṡ # Concatenate each
⌈f # Split each on spaces and flatten
ꜝ # Remove empty strings after words ending with vowels. (this also condenses spaces but we don't have to handle that)
꘍ # Pad each with spaces by
₅ɽ # range from 1 to its length exclusive
∑ # Concatenate the result
Jelly, 19 bytes
e€ØWḊae€Øc$kKfƤẹ¦¥⁶
A bit of a mess with the word logic, but I'm pretty proud of how I golfed the actual spacing 3 bytes down from ḲµJ⁶xⱮż@!
e€ For each character, is it
Øc a vowel,
a $ and is
Ḋ the character after it
eۯW a word character?
Ḋa (The end of the string can be a false positive but yeah.)
k Split the string after those characters,
¥ then
K join on spaces
¦ and replace characters at
ẹ ⁶ indices of spaces
fƤ ⁶ with the string up to that point filtered to spaces.