| Bytes | Lang | Time | Link |
|---|---|---|---|
| 433 | Ĺx̑rgy | 240718T204113Z | bigyihsu |
| 071 | Ŕṭn̄ 0.8.2 | 191017T010430Z | Sara J |
| 062 | CJam | 150717T194355Z | Dennis |
| 085 | GNU sed | 150716T112232Z | Toby Spe |
| 269 | Julia | 150717T181836Z | Alex A. |
Ĺx̑rgy, 480 459 433 byt̖s
feature v(a,b,e,f,i,j,o,p,u,v)
diacritic ̄ [a]
diacritic ̠ [b]
diacritic ́ [e]
diacritic ̖ [f]
diacritic ̇ [i]
diacritic ̣ [j]
diacritic ̌ [o]
diacritic ̭ [p]
diacritic ̑ [u]
diacritic ̮ [v]
class t {b,d,f,h,k,l,t}
class v {a,e,i,o,u}
element c !@v
a:
{@t a,@t e,@t i,@t o,@t u,@c a,@c e,@c i,@c o,@c u}=>{[b] *,[f] *,[j] *,[p] *,[v] *,[a] *,[e] *,[i] *,[o] *,[u] *}
* {a,e,i,o,u}=>o {[a],[e],[i],[o],[u]}
b:
o [$v]=>[$v] *
An actually pretty idiomatic (for Lexurgy at least) solution. Mainly does a bunch of select-replaces. This amount of duplication is due to Lexurgy not supporting rules like @c @v=>{[a],[e],[i],[o],[u]} *, due to the number of alternatives for each element not matching.
The solution first does the following all at once, and stops going down the list of alternatives when it succeeds:
- Deletes a vowel following a tall consonant, and replaces it with the low version of the diacritic.
- Deletes a vowel following any consonant, and replaces it with the default diacritic.
- Takes a vowel and replaces it with the placeholder and itself with the diacritic.
Finally, the solution removes the leftover vowel-with-diacritic and places the diacritic on the placeholder vowel.
- -21 bytes by compressing down into two rules
- -26 by using one-letter names for lower diacritics
Ŕṭn̄ 0.8.2, 71 byt̖s
T`aei\ou`̄́̇̌̑
T`̄́̇̌̑`̠̖̣̭̮`[bdfhklt]*.
+`([^a-z])([̠̖̣̭̮̄́̇̌̑])
$1o$2
Óxpl̠n̄ṭǒn
T`aei\ou`̄́̇̌̑ ŕpl̠ćs th̖ ch̠r̄ct̖rs aeiou ẇth th̖ črŕsp̌nṡng ḍōcṙṭcs ōb̭v́.
T`̄́̇̌̑`̠̖̣̭̮`[bdfhklt]+. ŕpl̠ćs th̖ ḍōcṙṭcs ōb̭v́ ẇth ḍōcṙṭcs b̖ḽw ȯf pŕćd̖d by ǒń ǒr śv́r̄l ch̠r̄ct̖rs ẇth ōsćnd̖rs.
+`([^a-z])([̠̖̣̭̮̄́̇̌̑]) ȏnṭl th̖ ȯnp̑t sṱps ch̠nġng, ŕpl̠ć óv́ry ḍōcṙṭc ňt pŕćd̖d by ō l̖tt̖r...
$1o$2 ...ẇth th̖ s̄ḿ ch̠r̄ct̖rs b̮t ẇth ōn o b̖tẃón th̖m.
CJam, 63 62 bytes
Qq{_"aeiou"#:I){;___eu='o*\"bdfhklt"&"F<IST""*'-27"?I=730+}&}/
Try it online in the CJam interpreter.
How it works
Qq e# Push an empty string and read from STDIN.
{ e# For each character in the input:
e# Push a copy of the character.
"aeiou"# e# Find its index in "aeiou" (-1 for not found).
:I) e# Save in I and add 1.
{ e# If I + 1 != 0:
; e# Discard the character.
___ e# Copy the previous character (or the empty array) three times.
eu= e# Convert the last copy to uppercase and check for equality.
e# This pushes 1 for non-letters and 0 for letters.
'o* e# Push a string of that many o's.
\ e# Swap the last copy with the string of o's.
"bdfhklt"& e# Intersect with that string.
"F<IST" e# Push that string.
"*'-27" e# Push that string.
? e# Select the first iff the intersection is non-empty.
I= e# Retrieve the character at index I.
730+ e# Add 730 to its code point.
}& e#
}/ e#
GNU sed, 168 158 134 105 98 85 byt̖s
ǒr 75 ch̠rs (b̭th ȯncl̮ḍng +1 f̭r th̖ -r fl̠g).
s/([bdfhklt])([aeiou])/\1\u\2/g;y/aeiouAEIOU/̠̖̣̭̮̄́̇̌̑/;s/\B[^ ,a-z]/o&/g
óxpl̠n̄ṭǒn
Wó s̄v́ ō ḅt ȏṡng th̖ čnstr̄ȯnt th̠t ȯnp̑t ȯs ōll ḽẃr-c̄ś. Wó ȏpc̄ś ōny v̌ẃl f̭lḽẇng ō čnšn̄nt, b̖f̭ŕ čnv́rṭng ōll v̌ẃls ṱ ōcćnts.
#!/bin/sed -rf
s/([bdfhklt])([aeiou])/\1\u\2/g # upcase vowel following ascender
y/aeiouAEIOU/̠̖̣̭̮̄́̇̌̑/
s/\B[^ ,a-z]/o&/g # precede with 'o' if needed
Th̖ ǒdd-ḽǒḳng ch̠r̄ct̖rs ōŕ // čnt̠ȯṅng ōll t̖n ōcćnts (/̠̖̣̭̮̄́̇̌̑/). óxp̄nd̖d ǒȏt ẇth sp̄ćs, th̖y w̌ȏld ḽǒk ḷk̖ / ̄ ́ ̇ ̌ ̑ ̠ ̖ ̣ ̭ ̮ /.
ǒȏtp̑t
přgr̄mṁng p̑zzl̖s ōnd čd̖ ǧlf th̖ q̑ȯck břwn f̭x j̑mps ǒv́r th̖ l̠zy ḓg b̖ōȏṭf̮l ǒń ṙng ṱ ȓl̖ th̖m ōll, ǒń ṙng ṱ f̣nd th̖m, ǒń ṙng ṱ bṙng th̖m ōll ōnd ȯn th̖ d̠rkńss ḅnd th̖m
Julia, 269 bytes
This is really long and can probably be golfed further, but I'm just psyched that I was able to come up with a working solution at all!
s->(u=700+[72,69,75,80,85];l=800+[0,-10,3,13,14];R=replace;r(m)=(i=findin("aeiou",m[2])[1];j=m[1]∈"bdfhklt"?l[i]:u[i];string(m[1],char(j)));t(m)=string("o",char(u[findin("aeiou",m)[1]]));R(R(R(s,r"(?![eiou])[b-z][aeiou]",r),r"(?<=^| )[aeiou]",t),r"(?<=\S)[aeiou]",r))
This creates an unnamed function that accepts a string and returns a string.
Ungolfed + explanation:
function f(s)
# Construct arrays of integers representing the unicode accents
# u is for the upper accents and l is for the lower
u = 700 + [72,69,75,80,85]
l = 800 + [0,-10,3,13,14]
# Define a function to accent consonants followed by vowels
r(m) = begin
# m is the consonant-vowel pair from the regex match
i = findin("aeiou", m[2])[1]
j = m[1] ∈ "bdfhklt" ? l[i] : u[i]
string(m[1], char(j))
end
# Define a function to accent vowels
t(m) = string("o", char(u[findin("aeiou", m)[1]]))
# Accent consonants
rep1 = replace(s, r"(?![eiou])[b-z][aeiou]", r)
# Accent vowels at the start of a string or before a space
rep2 = replace(rep1, r"(?<=^| )[aeiou]", t)
# Accent remaining unaccented vowels
rep3 = replace(rep2, r"(?<=\S)[aeiou]", t)
# Return
rep3
end
Examples:
julia> println(f("beautiful"))
b̖ōȏṭf̮l
julia> println(f("programming puzzles and code golf"))
přgr̄mṁng p̑zzl̖s ōnd čd̖ ǧlf
Note that if you look at the raw text in the post, the "t" in the first example is accented correctly but for some reason it doesn't display that way in the rendered markdown, at least for me.