| Bytes | Lang | Time | Link |
|---|---|---|---|
| 094 | Haskell | 250820T224443Z | Hayden B |
| 082 | Janet | 250810T225353Z | Adam |
| 009 | Vyxal 3 | 250810T210349Z | pacman25 |
| 015 | Uiua | 250810T193747Z | nyxbird |
| 040 | APLNARS | 250809T042414Z | Rosario |
| 024 | Dyalog APL | 250808T181936Z | Aaron |
| 150 | Setanta | 250807T190621Z | bb94 |
| 017 | 05AB1E | 221217T093330Z | The Thon |
| 036 | Ruby p | 221224T014513Z | south |
| 110 | Ruby 2.7 | 221224T005100Z | Armand F |
| 025 | sed | 221220T201343Z | Jiří |
| 026 | Raku | 221220T194859Z | Sean |
| 019 | Pyth | 221220T193312Z | CursorCo |
| 090 | Python 3 | 221219T114804Z | U13-Forw |
| 016 | Pip | 221217T041110Z | jezza_99 |
| 013 | Japt | 221217T165308Z | Shaggy |
| 052 | Zsh extendedglob | 221219T062317Z | roblogic |
| 051 | Factor | 221219T063900Z | chunes |
| 012 | Jelly | 221218T223820Z | Jonathan |
| 080 | Dart v2.18.4 | 221217T121351Z | Alex |
| 065 | Python 3.8 prerelease | 221217T021507Z | AlephSqu |
| 022 | Charcoal | 221217T191959Z | Neil |
| nan | 221217T043753Z | bigyihsu | |
| 025 | Retina 0.8.2 | 221217T185430Z | Neil |
| 023 | Vim | 221217T172611Z | DJMcMayh |
| 056 | JavaScript Node.js | 221217T022001Z | naffetS |
| 048 | R | 221217T154352Z | pajonk |
| 048 | C clang | 221217T153953Z | jdt |
| 047 | JavaScript Node.js | 221217T102932Z | Arnauld |
| 023 | Retina | 221217T134123Z | corvus_1 |
| 030 | Ly | 221217T053518Z | cnamejj |
| 061 | C clang | 221217T035540Z | dingledo |
| 011 | Vyxal | 221217T030851Z | lyxal |
| 011 | Vyxal | 221217T021318Z | naffetS |
Haskell, 94 bytes
import Data.Char
f(x:s)=x:zipWith(#)(x:s)s
x#y|elem x"aeiou"&¬Elem y"aeiou"=toUpper y|1>0=y
Janet, 82 bytes
|(peg/replace-all~(%(*'(set"aeiou")(!(set"aeiou"))(/'1,string/ascii-upper)))|$1 $)
Uiua, 15 bytes
⍥¯⊂0⧈<⊸∊"aeiou"
⊸∊"aeiou" # get membership in vowels
⊂0⧈< # pairwise less-than (prepend 0)
⍥¯ # flip case if true
APL(NARS), 40 chars
2{(⍵∊⎕a∼k)∧⍺∊k←'aeiou':⎕A[⎕a⍳⍵]⋄⍵}/'0',⎕
test:
2{(⍵∊⎕a∼k)∧⍺∊k←'aeiou':⎕A[⎕a⍳⍵]⋄⍵}/'0',⎕
⎕:
'b'
b
2{(⍵∊⎕a∼k)∧⍺∊k←'aeiou':⎕A[⎕a⍳⍵]⋄⍵}/'0',⎕
⎕:
'abba'
aBba
2{(⍵∊⎕a∼k)∧⍺∊k←'aeiou':⎕A[⎕a⍳⍵]⋄⍵}/'0',⎕
⎕:
'ab'
aB
2{(⍵∊⎕a∼k)∧⍺∊k←'aeiou':⎕A[⎕a⍳⍵]⋄⍵}/'0',⎕
⎕:
'helloworldandhellocodegolf'
heLloWoRldaNdheLloCoDeGoLf
Dyalog APL, 24 chars
{1∘⎕C@{0,2>/⍵∊'aeiou'}⍵}
Explanation
{1∘⎕C@{0,2>/⍵∊'aeiou'}⍵}
1∘⎕C # Uppercase
@{ }⍵ # at the positions this function returns 1
⍵∊'aeiou' # Mark where positions are vowels
2>/ # Over windows of 2, find where the left is greater to than the right to find right after any string of vowels
0, # Append a zero, so we're never doing the first character
💎
Created with the help of Luminespire.
Setanta, 168 162 150 bytes
gniomh(s){t:=""u:=1le i idir(0,fad@s){d:=aimsigh@(go_liosta@"bcdfghjklmnpqrstvwxyz"())(s[i])t+=(!u&d+1&"BCDFGHJKLMNPQRSTVWXYZ"[d])|s[i]u=d+1}toradh t}
05AB1E, 17 bytes
'zì.γžMså}2Å€™}J¦
- -4 thanks to Kevin Cruijssen
Port of Steffan's Vyxal answer
'zì.γžMså}2Å€™}J¦ # Implicit input TOP OF THE STACK:
'zì # Prepend a 'z' "zhelloworldandhellocodegolf"
.γ } # Group by
žM # The string of vowels 'aeiou'
så # Contains the letter ["zh", "e", "ll", "o", "w", "o", "rld", "a", "ndh", "e", "ll", "o", "c", "o", "d", "e", "g", "o", "lf"]
2Å€ } # Every second item:
™ # Convert to title case ["Zh", "e", "Ll", "o", "W", "o", "Rld", "a", "Ndh", "e", "Ll", "o", "C", "o", "D", "e", "G", "o", "Lf"]
J # Join everything 'ZheLloWoRldaNdheLloCoDeGoLf'
¦ # And remove the leading 'z' 'heLloWoRldaNdheLloCoDeGoLf'
Ruby 2.7, 110 bytes
->(s){v="aeiou";s.chars.map.with_index{v.include?(s[_2-1])&&!v.include?(_1)?(_1.upcase):_1}.join}
sed, 25 bytes
s/[aeiou][^aeiou]/\U\l&/g
It makes the whole match uppercase and then it turns first letter to lowercase. This is 5 bytes shorter than s/([aeiou])([^aeiou])/\1\u\2/g solution and it also doesn't require -E flag.
Pyth, 19 bytes
sm?*Z!=Z}d"aeiou"r1
Explanation
sm?*Z!=Z}d"aeiou"r1ddQ # implicitly add ddQ to the end
# implicitly assign Q = eval(input())
s # sum of
m Q # map lambda d over Q
? # ternary if (
*Z! # Z and not
=Z}d"aeiou" # assign Z to d being a vowel):
r1d # d capitalized
d # else: d
Python 3, 90 bytes
lambda x:"".join(b.upper()if a in"aeiou"and b not in"aeiou"else b for a,b in zip(" "+x,x))
Would be 71 bytes if didn't have to deal with repetitive vowels, still got 90 bytes though. Try it online!
Pip, 21 16 bytes
aRXV.XC;@_.UC_@1
-5 bytes thanks to @DLosc
Regex solution, ported from @Steffan's regex, with some pip builtin regex patterns used to save bytes
Pip, 21 17 bytes
{Iy>YaNVWUC:aa}Ma
-4 bytes thanks to @DLosc
Non-regex alternative
Japt, 13 bytes
r"%v%c"ÈÎ+XÌu
r"%v%c"ÈÎ+XÌu :Implicit input of string
r :Replace
"%v%c" :RegEx /[aeiou][b-df-hj-np-tv-z]/gi
È :Pass each match through the following function as X
Î : First character
+ : Append
XÌ : Last character
u : Uppercased
Zsh --extendedglob, 52 bytes
<<<${1//(#m)[aeiou][^aeiou]/$MATCH[1]${(U)MATCH[2]}}
Jelly, 12 bytes
Œue€ØḄ<ƝŻTƲ¦
A monadic Link that accepts a list of lowercase characters and yields a list of characters.
How?
Œue€ØḄ<ƝŻTƲ¦ - Link: list of lowercase characters, S
¦ - sparse application (to S)...
Ʋ - ...to indices: last four links as a monad - f(S):
ØḄ - lowercase consonants
€ - for each (character in S):
e - exists in? -> 1 if a consonant else 0
Ɲ - for neighbours:
< - less than? -> 1 if [0,1] else 0
Ż - prepend a zero
T - truthy indices -> indices of consonants directly after a vowel
Œu - ...action: convert to uppercase
Dart (v2.18.4), 149 80 bytes
f(s,[d=0])=>String.fromCharCodes([for(s in s.runes)s^d&~(d=68174912>>s%32)&32]);
Extra test-cases:
| Input | Output |
|---|---|
| loremipsumdolorsitamet | loReMiPsuMdoLoRsiTaMeT |
| namauctoranteelementumarculaciniaaceuismodestiaculis | naMauCtoRaNteeLeMeNtuMaRcuLaCiNiaaCeuiSmoDeStiaCuLiS |
Thanks to @steffan who cut down to 80 bytes (!) by porting @arnauld answer.
Python 3.8 (pre-release), 78 66 65 bytes
d=0
for c in input():print(end=[c,c.upper()][d>(d:=c in"aeiou")])
Complete program. Thanks to @Neil and @Steffan for making this more concise. Try it online!
Python 3, 73 bytes (@Steffan)
lambda x:re.sub("(?<=[aeiou])[^aeiou]",lambda a:a[0].upper(),x)
import re
Function solution. Try it online!
Charcoal, 22 bytes
⭆θ⎇№⌕A⭆θ№aeiouλ10⊖κ↥ιι
Try it online! Link is to verbose version of code. Explanation: Maps each letter to its vowel-ness as a binary flag, then searches for the substring 10 in the result, the second character of which is where the consonants that needs to be uppercased are.
θ Input string
⭆ Map over letters and join
№ Count of
κ Current index
⊖ Decremented
θ In input string
⭆ Map over letters and join
№ Count of
λ Inner letter in
aeiou Literal string `aeiou`
⌕A Find all matches of
10 Literal string `10`
⎇ If found then
ι Current consonant
↥ Uppercased
ι Else current letter
Implicitly print
Go, 170 164 bytes
import(."regexp";."strings")
func f(s string)string{return MustCompile(`[aeiou][^aeiou]`).ReplaceAllStringFunc(s,func(x string)string{return x[:1]+ToUpper(x[1:])})}
No (?<=), non-capturing groups only work with Find(All)String(Submatch) which leads to a longer solution, so this mess is what I've had to come with.
- -6 bytes for simplifying the regex.
Retina 0.8.2, 25 bytes
T`aeioul`aeiouL`[aeiou]+.
Try it online! Explanation: Transliterates vowels to themselves and other lowercase letters to uppercase letters, but only the letter after a run of vowels. (This is so that a double vowel doesn't confuse the transliteration.)
Alternative, also 25 bytes:
rT`aeioul`aeiouL`[aeiou].
Try it online! Explanation: The r makes it match the pattern from right to left solving the double vowel problem.
Both programs work in Retina 1 but 8 bytes can be saved because the aeiou can be replaced by v in the transliteration patterns.
Vim, 23 keystrokes
:s/[aeiou]\+\zs./\u&/g<cr>
:s/ # Search and replace...
[aeiou]\+ # A string of one or more vowels
\zs # (start the match here)
. # Any character
# (because of greedy matching, this will always be the first consonant)
/ # Replace with
\u # Make uppercase
& # The matched string (after \zs)
/g<cr> # Replace all occurrences
JavaScript (Node.js), 56 bytes
x=>x.replace(/(?<=[aeiou])[^aeiou]/g,x=>x.toUpperCase())
Perl 5 -p, 30 27 26 bytes
s/[aeiou]\K[^aeiou]/\U$&/g
-3 bytes thanks to Sisyphus
-1 byte thanks to Jo King
C (clang), 48 bytes
d;f(*s){for(d=1;*s;)*s++^=d-(d='Xz'%*s>0)&32;}
dingledooper's answer as a function.
JavaScript (Node.js), 47 bytes
Expects and returns a string.
s=>Buffer(s).map(c=>c^s&~(s=68174912>>c)&32)+''
How?
The constant \$68174912\$ (which I've already used here) is a bitmask describing the positions of the vowels:
00000100000100000100010001000000
v v v v v
zyxwvutsrqponmlkjihgfedcba`_^]\[
Commented
s => // s = input string
Buffer(s) // turn it into a buffer
.map(c => // for each ASCII code c:
c ^ // toggle the case if
s & // the previous letter was a vowel
~( // and the current letter is a consonant
s = // save in s the new state obtained by
68174912 // right-shifting the bit-mask
>> c // by c positions (mod 32)
) & 32 // isolate the case bit
) + '' // end of map(), coerce back to a string
JavaScript (ES6), 38 bytes
Expects and returns an array of ASCII codes.
a=>a.map(p=c=>c^p&~(p=68174912>>c)&32)
Ly, 30 bytes
"aeiou"0>ir[sp<l~!' **lf-ol~>]
This isn't even close to the smallest, but the way it works is probably very different from other languages, so I thought it was worth posting.
It uses two stacks, one with a list of vowels, and one with the STDIN string. Each character on the STDIN stack is copied to the vowel stack and the code search to see if there's a match. That "am I a vowel" result is combined with a "was the last char as vowel" result that lives on the stack to decide whether or not to capitalize the current character before printing it.
"aeiou" - push "is a vowel" comparison data on stack
0 - push "0" as "was last char a vowel" starter val
>i - switch to new stack, read STDIN onto it
r - reverse stack
[ ] - for each input char/codepoint
sp<l - stash the char, delete, switch stacks and restore
~! - search for the char in "aeiou", negate result
' - push " " (32), the "capitalize" codepoint offset
* - multiple to clear if not this IS a vowel
* - multiple against "was previous char vowel?" result
l - reload the current char/codepoint
f- - flip stack and subtract to capitalize if needed
o - output current char
l~ - reload char, search against vowels
> - switch back to the STDIN stack
C (clang), 61 bytes
A full program that takes input from STDIN, and outputs to STDOUT.
c;main(d){for(;read(0,&c,1);)putchar(c^d-(d='Xz'%c>0)&32);}
I use the same formula to check for vowels as in this other task. Here, (d='Xz'%c>0) sets d equal to \$ 0 \$ if the current letter c is a vowel, and \$ 1 \$ otherwise. c should be uppercased if and only if the current d is \$ 1 \$, and the previous d is \$ 0 \$. To apply the uppercasing, c is XOR'ed with \$ 32 \$, but only when the conditions are met. Below is a table to visualize what is happening:
| prev_d | d | prev_d - d | & 32 | ^ c |
-+--------+---+------------+------+------+-
| 0 | 0 | 0 | 0 | c |
| 0 | 1 | -1 | 32 | 32^c |
| 1 | 0 | 1 | 0 | c |
| 1 | 1 | 0 | 0 | c |
Vyxal, 11 bytes
`° ß`$‡ǐNøṙ
An alternate 11 byter that uses regex
See this golfing tip of mine that explains why the string "° ß" is "[aeiou] [bcdfghjklmnpqrstvwxyz]"
Explained
`° ß`$‡ǐNøṙ
`° ß` # The string `[aeiou] [bcdfghjklmnpqrstvwxyz]`
$ # Make the stack input, ^
‡ǐN # Push a function that title cases a string and then swapscase.
# This is because regex matches will be vowel-consonant, and title case makes the vowel uppercase, consonant lowercase, swapcase inverts that for the desired result
øṙ # Apply that function to regex matches in the input
Vyxal, 11 bytes
\zp⁽AḊ⁽ǐẆṅḢ
This is a terrible way to do it but it works.
\zp⁽AḊ⁽ǐẆṅḢ
\zp # Prepend "z" so that there is a leading consonant
⁽AḊ # Adjacent-group by is-vowel
⁽ǐẆ # Title-case every second item, starting on the first item
ṅḢ # Join by nothing and remove the leading "z"