In this challenge, you must take a string matching the regex ^[a-zA-Z]+$
or whatever is reasonable (you don't have to consider uppercase or lowercase letters if you want) (you may assume the string is long enough, and has the right structure for all the operations), and output another string, produced similarly to word at the end of a recent dadaist tweet by the POTUS ("Despite the constant negative press covfefe"
).
How to covfefify a string:
First, get the first sound group (made up terminology).
How do you do this? Well:
Find the first vowel (
y
is also a vowel)v creation
Find the first consonant after that
v creation
Remove the rest of the string
creat
That is your first sound group.
Next step:
Get the last consonant of the sound group
t
and replace it with the voiced or voiceless version. To do this, find the letter in this table. Replace with the letter given (which may be the same letter)
b: p
c: g
d: t
f: v
g: k
h: h
j: j
k: g
l: l
m: m
n: n
p: b
q: q
r: r
s: z
t: d
v: f
w: w
x: x
z: s
so, we get
d
Then, take the next vowel after that consonant. You can assume that this consonant is not at the end of the string. Join these two together, then repeat it twice:
didi
Concatenate this to the first sound group:
creatdidi
You're done: the string is covfefified, and you can now output it.
Test cases:
coverage: covfefe
example: exxaxa
programming: progkaka (the a is the first vowel after the g, even though it is not immediately after)
code: codtete
president: preszizi
This is code-golf, so please make your program as short as possible!
-
8\$\begingroup\$ "x" should technically map onto "gz". "qu" should map onto "gw". \$\endgroup\$Steve Bennett– Steve Bennett2017年06月05日 05:34:49 +00:00Commented Jun 5, 2017 at 5:34
-
83\$\begingroup\$ Answers over 140 characters should be disqualified \$\endgroup\$Sandy Gifford– Sandy Gifford2017年06月07日 15:27:53 +00:00Commented Jun 7, 2017 at 15:27
-
19\$\begingroup\$ Unfortunately it is impossible to do this in TrumpScript :( \$\endgroup\$user69279– user692792017年06月14日 22:09:21 +00:00Commented Jun 14, 2017 at 22:09
-
6\$\begingroup\$ @ThePlasmaRailgun dude... \$\endgroup\$Sandy Gifford– Sandy Gifford2017年12月20日 14:57:02 +00:00Commented Dec 20, 2017 at 14:57
-
14\$\begingroup\$ @ThePlasmaRailgun It was a joke, since tweets have to be 140 characters or less. \$\endgroup\$Esolanging Fruit– Esolanging Fruit2017年12月31日 22:14:50 +00:00Commented Dec 31, 2017 at 22:14
50 Answers 50
Jelly, (削除) 58 (削除ここまで) 57 bytes
<TḢị
e€Øyμ¬TĖEÐḟḢṪ;ç\T
ḣÇḢ8ÇịμḢØYiị"ßȷ%Hẹrȧq’œ?ØY¤)cgy;ẋ2
A full program that accepts a list of lowercase characters and prints the result.
How?
<TḢị - Link 1, extract first value from y not less than x: number, x; list of numbers, y
- e.g. 5, [3,4,7]
< - x less than vectorised across y [0,0,1]
T - truthy indices [ 3]
Ḣ - head 3
ị - index into y 7
e€Øyμ¬TĖEÐḟḢṪ;ç\T - Link 2, indices of the letters to manipulate: list of characters, w
Øy - vowel+ yield = "AEIOUYaeiouy" e.g. "smouching"
e€ - exists in for €ach letter in w 001100100
μ - monadic chain separation, call that v
¬ - not vectorised across v 110011011
T - truthy indices 12 56 89
Ė - enumerate [[1,1],[2,2],[3,5],[4,6],[5,8],[6,9]]
Ðḟ - filter discard if:
E - elements are equal [[3,5],[4,6],[5,8],[6,9]]
Ḣ - head [3,5]
Ṫ - tail 5
T - truthy indices of v 34 7
\ - last 2 links as a dyad
ç - call last link (1) as a dyad 7
; - concatenate 5,7
- ...i.e the indexes of 'c' and 'i'
ḣÇḢ8ÇịμḢØYiị"ßȷ%Hẹrȧq’œ?ØY¤)cgy;ẋ2 - Main link: list of characters, w
- e.g. "smouching"
Ç - call the last link (2) as a monad [5,7]
ḣ - head to index (vectorises) ["smouc","smouchi"]
Ḣ - head "smouc"
- implicit print due to below leading constant chain
8 - link's left argument, w
Ç - call the last link (2) as a monad [5,7]
ị - index into w "ci"
μ - monadic chain separation, call that p
Ḣ - head p 'c'
ØY - consonant- yield = "BCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz"
i - first index 22
¤ - nilad followed by link(s) as a nilad:
"ßȷ%Hẹrȧq’ - base 250 number = 1349402632272870364
ØY - consonant- yield = "BCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz"
œ? - nth permutation = "BCDFGHJKLMNPQRSTVWXZpctvkhjglmnbqrzdfwxs"
ị - index into (special case ->) 'c'
)cg - literal ['c','g']
y - translate (change 'c's to 'g's) 'g'
; - concatenate with the headed p "gi"
ẋ2 - repeat list twice "gigi"
- implicit print ...along with earlier = smoucgigi
-
14\$\begingroup\$ This is amazing... \$\endgroup\$Klangen– Klangen2017年05月31日 14:23:44 +00:00Commented May 31, 2017 at 14:23
-
\$\begingroup\$ Incredible work. \$\endgroup\$JF it– JF it2017年06月02日 13:22:49 +00:00Commented Jun 2, 2017 at 13:22
-
11\$\begingroup\$ I'm jelly. Upvoted. \$\endgroup\$DeepS1X– DeepS1X2017年06月05日 05:01:29 +00:00Commented Jun 5, 2017 at 5:01
-
7\$\begingroup\$ This is the weirdest programming language I've ever seen. \$\endgroup\$Ryan– Ryan2017年06月07日 16:57:28 +00:00Commented Jun 7, 2017 at 16:57
-
\$\begingroup\$ @Ryan it's intended for golfing. \$\endgroup\$Esolanging Fruit– Esolanging Fruit2017年07月17日 22:39:31 +00:00Commented Jul 17, 2017 at 22:39
JavaScript (ES6), (削除) 107 (削除ここまで) 103 bytes
Saved 4 bytes thanks to GOTO 0
s=>([,a,b,c]=s.match`(.*?[aeiouy]+(.)).*?([aeiouy])`,a+(b=(a="bcdfgszkvtgp")[11-a.search(b)]||b)+c+b+c)
Test cases
let f =
s=>([,a,b,c]=s.match`(.*?[aeiouy]+(.)).*?([aeiouy])`,a+(b=(a="bcdfgszkvtgp")[11-a.search(b)]||b)+c+b+c)
console.log(f("creation"))
console.log(f("coverage"))
console.log(f("example"))
console.log(f("programming"))
console.log(f("president"))
-
6\$\begingroup\$ You can save a few bytes like this:
s=>([,a,b,c]=s.match`(.*?[aeiouy]+(.)).*?([aeiouy])`,a+(b=(a="bcdfgszkvtgp")[11-a.search(b)]||b)+c+b+c)
\$\endgroup\$GOTO 0– GOTO 02017年06月01日 00:13:39 +00:00Commented Jun 1, 2017 at 0:13 -
\$\begingroup\$ @GOTO0 Thanks, updated. \$\endgroup\$Arnauld– Arnauld2017年06月01日 05:11:25 +00:00Commented Jun 1, 2017 at 5:11
Jelly, (削除) 45 (削除ここまで) 39 bytes
Øa"œṣ$b|0Ḃ’ṃ,Ṛ$yṫμfØyḢṭḢẋ2
e€ØyIi-‘ɓḣ;ç
How it works
e€ØyIi-‘ɓḣ;ç Main link. Argument: s (string)
Øy Vowels with y; yield "AEIOUYaeiouy".
e€ Test each character in s for membership.
I Increments; compute the forward differences of the
resulting array of Booleans.
i- Find the first index of -1.
‘ Increment this index to find the index of the first
consonant that follows a vowel.
Let's call this index j.
ɓ Begin a new chain. Left argument: s. Right argument: j
ḣ Head; yield the first j characters of s.
ç Call the helper link with arguments s and j.
; Concatenate the results to both sides.
Øa"œṣ$b|0Ḃ’ṃ,Ṛ$yṫμfØyḢṭḢẋ2 Helper link. Left argument: s. Right argument: j
Øa Alphabet; set the return value to "abc...xyz".
"œṣ$b|0Ḃ’ Yield 7787255460949942. This is a numeric literal in
bijective base 250. The value of each digit matches its
1-based index in Jelly's code page.
ṃ Convert 7787255460949942 to base 26, using the digts
a = 1, b = 2, ..., y = 25, z = 0.
This yields "bcdfkszgvtgp".
,Ṛ$ Pair the result with its reverse, yielding
["bcdfkszgvtgp", "pgtvgzskfdcb"].
ṫ Call tail with arguments s and j, yielding the j-th and
all following characters of s.
y Translate the result to the right according to the
mapping to the left, i.e., replace 'b' with 'p', 'c'
with 'g', etc. 'g' appears twice in the first string
of the mapping; only the first occurrence counts.
Let's call the resulting string r.
μ Begin a new chain. Argument: r
fØy Filter; remove non-vowels from r.
Ḣ Head; take the first vowel.
Ḣ Head; take the first character/consonant of r.
ṭ Tack; append vowel to the consonant.
ẋ2 Repeat the resulting string twice.
-
5\$\begingroup\$ sorry, buddy, looks like you missed out on the mega jelly rep \$\endgroup\$Destructible Lemon– Destructible Lemon2017年06月15日 12:17:36 +00:00Commented Jun 15, 2017 at 12:17
-
\$\begingroup\$ tfw an answer looks overly simplistic but is in fact really wonderful...simple is beautiful \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2017年06月16日 09:29:22 +00:00Commented Jun 16, 2017 at 9:29
CJam, (削除) 59 (削除ここまで) (削除) 58 (削除ここまで) (削除) 57 (削除ここまで) 56 bytes
q_{"aeiouy":V&,_T|:T^}#)/(_W>"cbdfkszgvtpg"_W%er@sV&0=+_
Explanation
q_ e# Read the input and copy it.
{ e# Find the index of the first char for which the following is true:
"aeiouy":V e# Push "aeiouy" and store it in V.
&, e# Check if the current char is in the vowel string (0 or 1).
_T|:T e# Copy the result and OR with T (T is initially 0), storing back in T.
^ e# XOR with the original result. This will be 1 for the first
e# consonant appearing after a vowel.
}# e# (end find)
)/ e# Increment the index and split the string into chunks of that size.
( e# Pull out the first chunk.
_W> e# Copy it and get the last character (the consonant).
"cbdfkszgvtpg"_W%er e# Transliterate the consonant to voiced/voiceless alternative.
@s e# Bring all the other split chunks to the top and join them together.
V&0= e# First char of the set intersection of that and the vowels.
e# (i.e. the first vowel in the second half)
+ e# Concatenate the new consonant and the vowel.
_ e# Duplicate the result of that.
e# Implicit output of stack contents.
-
3\$\begingroup\$ CJam beats Jelly? :O (At least, it beats the Jelly answer everybody seems to be upvoting.) \$\endgroup\$Esolanging Fruit– Esolanging Fruit2017年07月17日 22:41:54 +00:00Commented Jul 17, 2017 at 22:41
C, (削除) 219 (削除ここまで) (削除) 213 (削除ここまで) (削除) 206 (削除ここまで) (削除) 179 (削除ここまで) 175 bytes
#define p putchar
#define q(a)for(;a strchr("aeiouy",*s);p(*s++));
f(s,c,h)char*s;{q(!)q()p(*s);p(c="pgt vkh jglmn bqrzd fwx s"[*s-98]);p(h=s[strcspn(s,"aeiouy")]);p(c);p(h);}
-
\$\begingroup\$ Does *p=putchar work as the first line? \$\endgroup\$k_g– k_g2017年06月03日 23:25:32 +00:00Commented Jun 3, 2017 at 23:25
-
8\$\begingroup\$ Sorry disqualified. Can't fit in a tweet. \$\endgroup\$2017年06月09日 06:46:28 +00:00Commented Jun 9, 2017 at 6:46
-
2\$\begingroup\$ 171 bytes \$\endgroup\$ceilingcat– ceilingcat2018年11月30日 19:21:49 +00:00Commented Nov 30, 2018 at 19:21
-
1\$\begingroup\$ 12 or so bytes can be shaved off by replacing
#define
s and the function with preprocessor flags (-D...
). \$\endgroup\$user77406– user774062018年12月01日 15:53:09 +00:00Commented Dec 1, 2018 at 15:53 -
1\$\begingroup\$ Actually tweetable now because twitter allows 280 chars. \$\endgroup\$2020年01月22日 07:32:55 +00:00Commented Jan 22, 2020 at 7:32
Perl 5, (削除) 81 (削除ここまで) (削除) 72 (削除ここまで) 71 bytes
-1 byte thanks to Xcali!
s![aeiouy]+(.)\K.*!(1ドル=~y/bdfgpstvzck/ptvkbzdfsg/r.$&x/[aeiouy]/g)x2!ge
-
\$\begingroup\$ You and I had the same idea with
\K
, but you did it 9 bytes better than I did. Good answer! \$\endgroup\$Silvio Mayolo– Silvio Mayolo2017年06月06日 23:25:21 +00:00Commented Jun 6, 2017 at 23:25 -
\$\begingroup\$ This can save a byte by reordering the translation: Try it online! \$\endgroup\$Xcali– Xcali2022年08月14日 04:40:30 +00:00Commented Aug 14, 2022 at 4:40
PHP, 121 Bytes
$v=aeiouy;preg_match("#(.*?[$v]+([^$v])).*?([$v])#",$argn,$t);echo$t[1],$z=strtr($t[2].$t[3],bcdfgkpstvz,pgtvkgbzdfs),$z;
-
3\$\begingroup\$ -2 bytes:
echo$t[1],$z=strtr($t[2].$t[3],bcdfgkpstvz,pgtvkgbzdfs),$z;
\$\endgroup\$Titus– Titus2017年06月01日 11:53:21 +00:00Commented Jun 1, 2017 at 11:53 -
\$\begingroup\$ @Titus I have not think about that. Thank You \$\endgroup\$Jörg Hülsermann– Jörg Hülsermann2017年06月01日 11:59:01 +00:00Commented Jun 1, 2017 at 11:59
-
\$\begingroup\$ why not rename
$argn
to something shorter?$a
, for example - that's -3 bytes \$\endgroup\$Tyler Sebastian– Tyler Sebastian2017年06月06日 22:37:08 +00:00Commented Jun 6, 2017 at 22:37 -
\$\begingroup\$ @TylerSebastian I must have an input variable that exists. Yes I can create a function but if I do it it raise the byte count more as use the three bytes \$\endgroup\$Jörg Hülsermann– Jörg Hülsermann2017年06月06日 22:44:07 +00:00Commented Jun 6, 2017 at 22:44
-
\$\begingroup\$ ah ok sorry I forgot how PHP does command line args - I just saw that you had defined it in the header section but failed to realize it was a reserved variable. \$\endgroup\$Tyler Sebastian– Tyler Sebastian2017年06月06日 22:45:29 +00:00Commented Jun 6, 2017 at 22:45
Pyth, 54 bytes
L+hb?>F}RJ"aeiouy"<b2+hKtb*2+XhK"cgdsfbpvztkg")h@JKytb
This defines a function y
, that expects a string.
Try it online: Test Suite
Python 3, (削除) 155 (削除ここまで) 139 bytes
import re
def f(x,k='aeiouy])'):b,c,v=re.findall(f'(.*?[{k}([^{k}.*?([{k}',x)[0];return b+c+(('bcdfgkpstvz'+c)['pgtvkgbzdfs'.find(c)]+v)*2
removed 16 bytes thanks to @ovs
removed 1 byte thanks to Gábor Fekete
-
2\$\begingroup\$ You could create a variable which has the value
'aeiouy]'
, maybe that will save some bytes. Also you can remove some characters from the replacement strings as there are the same. \$\endgroup\$Gábor Fekete– Gábor Fekete2017年05月31日 12:41:52 +00:00Commented May 31, 2017 at 12:41 -
2\$\begingroup\$ I can't remove the identical characters from the replacement string, because that would be an
IndexError
, and savingaeiouy])
doesn't save any bytes. \$\endgroup\$L3viathan– L3viathan2017年05月31日 13:14:35 +00:00Commented May 31, 2017 at 13:14 -
2\$\begingroup\$ if you pull out something like
s='aeiouy])'
, you could useb,c,v=re.findall('(.*?[%s([^%s.*?([%s'%(s,s,s)
. It's not shorter, but might lead towards a way to shorten it overall. \$\endgroup\$Jeremy Weirich– Jeremy Weirich2017年05月31日 19:50:33 +00:00Commented May 31, 2017 at 19:50 -
6\$\begingroup\$ Shortened to 139 bytes \$\endgroup\$ovs– ovs2017年05月31日 20:34:39 +00:00Commented May 31, 2017 at 20:34
-
3\$\begingroup\$ Using f-strings will save 1 byte:
k='aeiouy])'
andf'(.*?[{k}([^{k}.*?([{k}'
\$\endgroup\$Gábor Fekete– Gábor Fekete2017年06月01日 07:48:16 +00:00Commented Jun 1, 2017 at 7:48
Java 8, (削除) 243 (削除ここまで) (削除) 236 (削除ここまで) 222 bytes
s->{String q="[a-z&&[^aeiouy]]",a=s.replaceAll("(^"+q+"*[aeiouy]+"+q+").*","1ドル"),b="pgtvkhjglmnbqrzdfwxs".charAt("bcdfghjklmnpqrstvwxz".indexOf(a.charAt(a.length()-1)))+s.replaceAll(a+q+"*([aeiouy]).*","1ドル");return a+b+b;}
Uses .replaceAll
regexes with capture groups to filter out the parts we don't want.
Explanation:
s->{ // Method with String parameter and String return-type
// Temp String we use multiple times:
String q="[a-z&&[^aeiouy]]",
// Regex to get the first part (i.e. `creation` -> `creat` / `example` -> `ex`)
a=s.replaceAll("(^"+q+"*[aeiouy]+"+q+").*","1ドル"),
// Get the trailing consonant and convert it
b="pgtvkhjglmnbqrzdfwxs".charAt("bcdfghjklmnpqrstvwxz".indexOf(a.charAt(a.length()-1)))
// Get the next vowel after the previous consonant from the input-String
+s.replaceAll(a+q+"*([aeiouy]).*","1ドル");
// Return the result:
return a+b+b;
} // End of method
Haskell, (削除) 143 (削除ここまで) (削除) 141 (削除ここまで) (削除) 138 (削除ここまで) (削除) 137 (削除ここまで) 136 bytes
z h=elem h"aeiouy"
f i|(s,(m,c:x))<-span z<$>break z i,j:_<-filter z x,d<-"pgt.vkh.jglmn.bqrzd.fwx.s"!!(fromEnum c-98)=s++m++[c,d,j,d,j]
-
1\$\begingroup\$ Awesome! Replacing
nx
with something one-lettered will save 2 bytes. \$\endgroup\$tomsmeding– tomsmeding2017年06月01日 07:08:40 +00:00Commented Jun 1, 2017 at 7:08 -
\$\begingroup\$ declaring
z
outside off
and switching to guards instead of alet
saves another two bytes: Try it online! \$\endgroup\$Laikoni– Laikoni2017年06月01日 07:52:37 +00:00Commented Jun 1, 2017 at 7:52 -
2\$\begingroup\$ And two more by combining
(s,v)<-break z i,(m,c:x)<-span z v
into(s,(m,c:x))<-span z<$>break z i
. \$\endgroup\$Laikoni– Laikoni2017年06月01日 07:55:30 +00:00Commented Jun 1, 2017 at 7:55 -
\$\begingroup\$ Could shave one more by putting the opening parenthesis next to the
let
, thanks! \$\endgroup\$bartavelle– bartavelle2017年06月01日 08:15:17 +00:00Commented Jun 1, 2017 at 8:15 -
\$\begingroup\$ @Laikoni I don't understand the part about moving
z
out off
? \$\endgroup\$bartavelle– bartavelle2017年06月01日 08:18:00 +00:00Commented Jun 1, 2017 at 8:18
Python, (削除) 261 (削除ここまで) 260 bytes
def c(s,t='bpcgdtfvgksz'):
q,r,t='aeiouy',range(len(s)),t+t[::-1]
c=[i for i in r if i>[j for j in r if s[j]in q][0]and s[i]not in q][0]
C=([t[2*i+1]for i in range(12)if s[c]==t[i*2]]or s[c])[0]
return s[:c+1]+(C+s[[i for i in r if i>c and s[i]in q][0]])*2
A Non regex, Not esoteric solution. Took about 20 minutes to make, and an hour more to golf.
It probably has more list comprehension than the entire python standard library, mostly because I don't know regex...
Python 2, (削除) 251 (削除ここまで) (削除) 246 (削除ここまで) (削除) 245 (削除ここまで) (削除) 239 (削除ここまで) (削除) 237 (削除ここまで) (削除) 234 (削除ここまで) (削除) 229 (削除ここまで) 211 bytes
First submission here.
def f(s):
r=c='';n=0;w='aeiouy';a='bcdfghjklmnpqrstvwxz'
for i in s:
if n<2:r+=i
if n<1and i in w:n=1
if n==1and i in a:c='pgtvkhjglmnbqrzdfwxs'[a.index(i)];n=2
if n==2and i in w:r+=c+i+c+i;break
return r
Fellow golfers that helped me:
Destructible Lemon / Wheat Wizard - 5 bytes
Hubert Grzeskowiak - 1 byte
musicman523 - 16 bytes
-
2\$\begingroup\$ Welcome to the site! I see you tried using tabs for indentation. If you replace each tab with a single space, it is functionally identical and actually shows up properly instead of as extra bytes \$\endgroup\$Destructible Lemon– Destructible Lemon2017年06月01日 10:43:36 +00:00Commented Jun 1, 2017 at 10:43
-
4\$\begingroup\$ While what Destructible Lemon said is correct, you can save even more bytes in you source by indenting the first level of your code with a single space and the second level with a single tab, this will make it a bit hard to display, but will save you 5 bytes. \$\endgroup\$2017年06月01日 10:45:26 +00:00Commented Jun 1, 2017 at 10:45
-
1\$\begingroup\$ Is the semicolon at the end of line 4 necessary? \$\endgroup\$Hugo G– Hugo G2017年06月03日 17:54:47 +00:00Commented Jun 3, 2017 at 17:54
-
1\$\begingroup\$ @WaitndSee I think you can shorten some of your conditionals. First: you can change
not n
ton<1
for 2 bytes, since you known
will never be negative. Also you can changen==3
ton>2
since you known
will never be greater than3
. You can also use the Python tricks for conditionals to shorten the first and second-last even further:n=[n,1][i in w and n<1]
;r+=[0,r][n<2]
\$\endgroup\$musicman523– musicman5232017年06月08日 04:33:14 +00:00Commented Jun 8, 2017 at 4:33 -
2\$\begingroup\$ You can change
r,v,c=('',)*3
tor=v=c=''
, since strings are immutable. I've tried a bunch of other clever tricks but frustratingly they are exactly as long. Also it may be worth adding a Try it online! link to your post \$\endgroup\$musicman523– musicman5232017年06月08日 13:14:36 +00:00Commented Jun 8, 2017 at 13:14
Ruby, 90 bytes
->x{x[/(.*?#{$v='[aeiouy]'}+.).*?(#$v)/];1ドル+(1ドル[-1].tr('bcdfgkpstvz','pgtvkgbzdfs')+2ドル)*2}
Ungolfing it a bit, we have something equivalent to:
def covfefefify(x)
v = '[aeiouy]'
# Match x to a regular expression capturing:
# Group 1:
# some characters (non-greedy)
# followed by some (greedy) non-zero number of vowels
# followed by exactly one character
# Ungrouped:
# Some more (non-greedy) characters
# Group 2
# Exactly one other vowel
# By switching between greedy and non-greedy matches, we can capture longest and shortest vowel/consonant sequences without writing out all the consonants
x[/(.*?#{v}+.).*?(#{v})/]
# Glue it back together, replace the necessary consonants, duplicate where needed
1ドル+(1ドル[-1].tr('bcdfgkpstvz','pgtvkgbzdfs')+2ドル)*2
end
Ruby, (削除) 175 (削除ここまで) (削除) 141 (削除ここまで) 110 bytes
->s{s=~/(.*?#{v='[aeiouy]'}+(#{c='[^aeiouy]'}))#{c}*(#{v})/;"#1ドル#{(2ドル.tr('bcdfgkpstvz','pgtvkgbzdfs')+3ドル)*2}"}
- Saved 34 bytes thanks to Eric Duminil
- Saved 31 bytes thanks to Value Ink + optimized suggested
tr
arguments
Ungolfed
covfefify = -> (s) {
from = 'bcdfgkpstvz'
to = 'pgtvkgbzdfs'
vowels = "[aeiouy]"
consonants = "[^aeiouy]"
s.match(/(.*?#{vowels}+(#{consonants}))#{consonants}*(#{vowels})/)
d = (2ドル.tr(from, to) + 3ドル) * 2
"#1ドル#{d}"
}
-
4\$\begingroup\$ -34 bytes with
Hash[*"bpcgdtfvgkkgpbsztdvfzs".chars]
\$\endgroup\$Eric Duminil– Eric Duminil2017年05月31日 13:30:40 +00:00Commented May 31, 2017 at 13:30 -
1\$\begingroup\$ Since input seems guaranteed to be all alphabetical characters,
c=[^aeiou]
is shorter. Have the first interpolation for each variable assign it simultaneously for -2 bytes:/^(.*?${v='[aeiou]'}+(#{c='[^aeiou]})).../
. Finally,2ドル.tr("b-z","pgtevkhijgl-obqrzdufwxys")
instead of the Hash solution. \$\endgroup\$Value Ink– Value Ink2017年05月31日 18:42:52 +00:00Commented May 31, 2017 at 18:42 -
\$\begingroup\$ You can save 14 bytes by using subexpressions (
\g<n>
) instead of interpolation, plus another 14 using @ValueInk's[^aeiou]
suggestion:s=~/^(.*?([aeiouy])+([^aeiou]))\g<3>*(\g<2>)/
. \$\endgroup\$Jordan– Jordan2017年05月31日 20:02:16 +00:00Commented May 31, 2017 at 20:02 -
\$\begingroup\$ Actually, that has a bug with
programming
->progkaka
, which I can't quite figure out. \$\endgroup\$Jordan– Jordan2017年05月31日 20:19:32 +00:00Commented May 31, 2017 at 20:19 -
\$\begingroup\$ @Jordan unfortunately the subexpression call
\g<3>
updates the value of 3,ドル so we can't use this shortcut. \$\endgroup\$sudee– sudee2017年06月01日 09:15:42 +00:00Commented Jun 1, 2017 at 9:15
Lexurgy, (削除) 288 (削除ここまで) (削除) 286 (削除ここまで) 281 bytes
Docs here.
Lexurgy is an online tool meant for conlangers (people who make constructed languages) to apply sound changes to their conlangs via a series of programmable rules. As such, this tool involves many string operations.
- -2: remove the
u
andw
classes and replace them with one-time substitutions. - -5: fix a bug with the
example
case, combine some rules into a single step
Class v {a,e,i,o,u}
Class c {p,t,k,f,s,c,b,d,g,v,z,g,h,j,l,m,n,q,r,w,x}
a:
@c *=>@c ;/$ @c* @v* _//{$ _,$ @c _}
b:
@c=>* /; _
c:
{@v,@c}=>* /; @v {@v,@c}* _
* {{p,t,k,f,s,c,x},{b,d,g,v,z,g,x}}1ドル=>1ドル {{b,d,g,v,z,g,x},{p,t,k,f,s,c,x}}/_ ;
e:
@c1ドル ;=>; 1ドル
f:
(@c @v)1ドル=>1ドル 1ドル/; _
;=>*
Ungolfed:
Class vowel {a,e,i,o,u}
Class unvoiced {p,t,k,f,s,c}
Class voiced {b,d,g,v,z,g}
Class consonant {@unvoiced,@voiced,h,j,l,m,n,q,r,w,x}
# find first consonant after first vowel
part-1:
@consonant * => @consonant ; / $ @consonant* @vowel* _ // {$ _, $ @consonant _}
romanizer-a:
unchanged
# delete the consonant after the seperator
part-2:
@consonant => * / ; _
romanizer-b:
unchanged
# remove everything except the second vowel
part-3:
{@vowel, @consonant} => * / ; @vowel {@vowel, @consonant}* _
romanizer-c:
unchanged
# voicings
part-4:
* @voiced1ドル => 1ドル @unvoiced / _ ;
* @unvoiced1ドル => 1ドル @voiced / _ ;
romanizer-d:
unchanged
# swap mapped consonant and seperator
part-5:
@consonant1ドル ; => ; 1ドル
romanizer-e:
unchanged
# duplicate the `fe`
part-6:
(@consonant @vowel)1ドル => 1ドル 1ドル / ; _
romanizer-f:
unchanged
# remove the seperator
part-7:
; => *
Crystal, (削除) 203 (削除ここまで) (削除) 194 (削除ここまで) (削除) 187 (削除ここまで) (削除) 186 (削除ここまで) (削除) 184 (削除ここまで) 163 bytes
o=""
ARGV[v=c=0].each_char{|a|r=/#{a}/
"aeiouy"=~r&&(v=x=1)||(c=v)
o+=a if c<2||x
c>0&&(x&&break||(o+=(i="pgtvkgbqrzdfs"=~r)?"bcdfgkpqrstvz"[i]: a))}
p o+o[-2..-1]
-
\$\begingroup\$ I think you can lose the parens around
c=v
ando+=<...>
\$\endgroup\$Cyoce– Cyoce2017年06月19日 15:24:36 +00:00Commented Jun 19, 2017 at 15:24
Retina, 68 bytes
r`\B(?>([^aeiouy])+)([aeiouy]).*
1ドル1ドル2ドル1ドル2ドル
T-5>`fs\dbgcgk\ptzv`Ro`.
!@#$%^&*()_+, (削除) 102 (削除ここまで) (削除) 101 (削除ここまで) (削除) 100 (削除ここまで) (削除) 99 (削除ここまで) 80 bytes
`33554(_(^1%)%)$pgtevkhijglmnobqrzdufwxys(0*!@&)^(0*!!@&_^)Q++&!@%(0*!^&)+!@0&@@
42nd answer of this question, it looks like. Just one byte longer than BQN! It took much more time than it should. I'm pretty sure there are still some simple tricks that I'm missing.
Accept lowercase characters. The program does not actually contain digits - 01345Q
in the code above are unprintable characters with ASCII code 0, 1, 3, 4, 5 and 25 respectively.
-
1\$\begingroup\$ How does this work? \$\endgroup\$emanresu A– emanresu A2022年01月17日 18:22:05 +00:00Commented Jan 17, 2022 at 18:22
-
\$\begingroup\$ @emanresuA It's very naive. Two lookup tables at the beginning: "is consonant" (with unprintable characters
\x00
and\x01
) and "voiced or voiceless". Then three do-while loops to find a vowel (and output along the way), consonant (and output along the way), and vowel. \$\endgroup\$TwilightSparkle– TwilightSparkle2022年01月18日 06:16:05 +00:00Commented Jan 18, 2022 at 6:16 -
\$\begingroup\$ Oh, and explaining that made me realize I wasted a very dumb byte. I've fixed it now. \$\endgroup\$TwilightSparkle– TwilightSparkle2022年01月18日 06:41:16 +00:00Commented Jan 18, 2022 at 6:41
-
\$\begingroup\$ ...Damn, one completely unnecessary byte. Two-digits!!! \$\endgroup\$TwilightSparkle– TwilightSparkle2022年02月03日 05:00:24 +00:00Commented Feb 3, 2022 at 5:00
-
\$\begingroup\$ 80!!! (19 chars) EXPLANATION COMIN' SOON \$\endgroup\$TwilightSparkle– TwilightSparkle2022年03月11日 05:55:46 +00:00Commented Mar 11, 2022 at 5:55
MATLAB / Octave - (削除) 159 (削除ここまで) 158 bytes
The following works assuming the input string is all lowercase.
a=input('','s');m=ismember(a,'aeiouy');s='pgt vkh jglmn bqrzd fwx s';m(1:find(m,1))=1;i=find(~m,1);f=a(1:i);d=s(f(end)-97);m(1:i)=0;v=a(find(m,1));[f d v d v]
Explanation
a = input('','s');
: Gets a string from STDIN and stores it into the variablea
.m=ismember(a,'aeiouy');
: Returns a Boolean array that is the same size as the stringa
determining where vowels are locateds='pgt vkh jglmn bqrzd fwx s';
Thecovfefe
mapping of consonants as a string. This string is 25 characters long and omitting the vowels. The first position where the vowel'a'
is supposed to be is removed while the other positions where the vowels are located are placed with a dummy space character. This is so that when we determine the first consonant appearing after the vowel, we will convert the consonant to a position to access a character in this string to determine the first component of the converted word.m(1:find(m,1))=1
: Sets the first position of the Boolean array up to where we have found the first vowel as all vowels. This will be so that when we search for the next consonant that follows the first vowel, we will ignore these characters.i=find(~m,1);
: Finds the first position of the string that is a consonant after the first vowel.f=a(1:i)
: Removes the string after the first consonant that follows the vowel. We simply sample from the first position of the string up to this point.d=s(f(end)-97);
: Take the last character of the string that is remaining and finds where we need to sample from the lookup string and gets that character. Subtracting a character and a number in MATLAB or Octave coalesces to form an integer by converting the character into its ASCII code. In this case, we subtract the last character by the character at the beginning of the alphabet to give us the position relative to the beginning. However, instead of subtracting byb
(98), we subtract bya
as MATLAB starts indexing by 1 instead of 0.'a'
's ASCII code is 97.m(1:i)=0;
: Takes the Boolean mask and sets all characters in the input string from the first position to the first consonant following a vowel to false.v=a(find(m,1));
: Finds the next vowel that follows the first consonant from the input string.[f d v d v]
: Output ourcovfefe
ied string.
Example Runs
>> a=input('','s');m=ismember(a,'aeiouy');s='pgt vkh jglmn bqrzd fwx s';m(1:find(m,1))=1;i=find(~m,1);f=a(1:i);d=s(f(end)-97);m(1:i)=0;v=a(find(m,1));[f d v d v]
coverage
ans =
covfefe
>> a=input('','s');m=ismember(a,'aeiouy');s='pgt vkh jglmn bqrzd fwx s';m(1:find(m,1))=1;i=find(~m,1);f=a(1:i);d=s(f(end)-97);m(1:i)=0;v=a(find(m,1));[f d v d v]
example
ans =
exxaxa
>> a=input('','s');m=ismember(a,'aeiouy');s='pgt vkh jglmn bqrzd fwx s';m(1:find(m,1))=1;i=find(~m,1);f=a(1:i);d=s(f(end)-97);m(1:i)=0;v=a(find(m,1));[f d v d v]
programming
ans =
progkaka
>> a=input('','s');m=ismember(a,'aeiouy');s='pgt vkh jglmn bqrzd fwx s';m(1:find(m,1))=1;i=find(~m,1);f=a(1:i);d=s(f(end)-97);m(1:i)=0;v=a(find(m,1));[f d v d v]
code
ans =
codtete
>> a=input('','s');m=ismember(a,'aeiouy');s='pgt vkh jglmn bqrzd fwx s';m(1:find(m,1))=1;i=find(~m,1);f=a(1:i);d=s(f(end)-97);m(1:i)=0;v=a(find(m,1));[f d v d v]
president
ans =
preszizi
Try it online!
http://www.tutorialspoint.com/execute_octave_online.php?PID=0Bw_CjBb95KQMdjROYVR0aFNrWXM
When you hit the Execute button at the top, wait a few moments, then enter the desired string. Enter the string slowly as there seems to be a delay when entering in text.
Clojure, (削除) 182 (削除ここまで) 156 chars
#(let[v #{\a\e\i\o\u\y}p(partition-by v %)[s m[c][n]](if(v(first %))(cons[]p)p)z[(or((zipmap"bcdfgkpstvz""pgtvkgbzdfs")c)c)n]](apply str(concat s m[c]z z)))
How It Works
(partition-by v "president")
Returns a seq of ((\p \r) (\e) (\s) (\i) (\d) (\e) (\n \t))
[s m [c] [n]] (if (v (first x)) (cons [] p) p)
Destructures the seq into s=(\p \r)
, m=(\e)
, c=\s
, n=\i
.
Or for "example" it's s=[]
, m=(\e)
, c=\x
, n=\a
.
(apply str (concat s m [c] [(l c) n] [(l c) n]))
Returns the output string by concatenating the pieces together and stringifying it.
And then I just removed as much whitespace as I could while still making it compile.
De-uglified:
(defn covfefify [x]
(let [vowel? #{\a\e\i\o\u\y}
parts (partition-by vowel? x)
[start mid [consonant] [last-vowel]] (if (vowel? (first x)) (cons [] parts) parts)
lookup #(or ((zipmap "bcdfgkpstvz" "pgtvkgbzdfs") %) %)]
(apply str (concat start mid [consonant] [(lookup consonant) last-vowel] [(lookup consonant) last-vowel]))))
-
\$\begingroup\$ Welcome to PPCG, and great first answer! We hope you'll stay and have fun participating in more challenges. :-) \$\endgroup\$ETHproductions– ETHproductions2017年06月06日 22:23:10 +00:00Commented Jun 6, 2017 at 22:23
-
\$\begingroup\$ If you're defining a function, its name should probably be as short as possible. You could just call the main function
c
, for example. (We also allow anonymous functions, which are shorter in many languages; I'm not sure whether they are in Clojure). I see you've made that improvement in the interior of your code already, though, so probably not much needs changing here. \$\endgroup\$user62131– user621312017年06月06日 22:31:34 +00:00Commented Jun 6, 2017 at 22:31
BlitzMax, 190 bytes
s$=Input()For i=1To s.Length
f="aeiouy".Contains(s[i-1..i])If f v=i If c Exit
If v And c|f=0c=i
Next
t$="bpdtfvgkcgsz"x$=s[c-1..c]r=t.Find(x)~1If r>=0x=t[r..r+1]
x:+s[v-1..v]Print s[..c]+x+x
Takes a word from stdin and prints the result to stdout. The input word is assumed to be lowercase and to contain at least one vowel followed by a consonant.
A more readable version of the progam with formatting and variable declarations:
SuperStrict
Framework BRL.StandardIO
Local s:String = Input()
Local v:Int
Local c:Int
For Local i:Int = 1 To s.Length
Local f:Int = "aeiouy".Contains(s[i - 1..i])
If f Then
v = i
If c Then Exit
End If
If v And c | f = 0 Then c = i
Next
Local t:String = "bpdtfvgkcgsz"
Local x:String = s[c-1..c]
Local r:Int = t.Find(x) ~ 1
If r >= 0 Then x = t[r..r + 1]
x :+ s[v - 1..v]
Print s[..c] + x + x
How it works:
BlitzMax doesn't have any builtin regex functionality or similar, so a loop is used to iterate over the characters of the input word until it finds a vowel followed by a chain of at least one consonant. The variable c stores the position of the last of those consonants, v that of the vowel. The loop continues to see if there is another vowel after the chain and if so, v is updated accordingly. Then the consonant at c is looked up in the string "bpdtfvgkcgsz", which acts as a replacement table. If the consonant is found in the table at any position, then that position is XOR-ed with 1 and the character at the resulting position gets used as its replacement. The XOR operation turns 0 into 1, 2 into 3, 4 into 5 etc. and vice versa, so that b gets swapped with p, d with t and so on. Finally, the original string up to c, the replacement character and the vowel at v are put together as required and printed.
Example results:
coverage covfefe
creation creatdidi
programming progkaka
stupidity stupbibi
blah blahhaha
-
\$\begingroup\$ link to blitzmax repo? \$\endgroup\$Destructible Lemon– Destructible Lemon2017年06月03日 06:29:19 +00:00Commented Jun 3, 2017 at 6:29
-
\$\begingroup\$ @DestructibleLemon BlitzMax was created as a language primarily for amateur game delevopment and with a proprietary compiler sold for money. While it is now free and available from here, I believe the compiler is still not open source. There exists an alternative implementation (repo here, builds here), which will however only run the ungolfed version of above code due to the lack of a "non-strict" setting that allows omitting variable declarations. \$\endgroup\$FireballStarfish– FireballStarfish2017年06月03日 07:55:15 +00:00Commented Jun 3, 2017 at 7:55
-
\$\begingroup\$ Clever use of XOR on index -- I'll probably be using that someday. Thank you. \$\endgroup\$A. I. Breveleri– A. I. Breveleri2017年06月08日 03:42:57 +00:00Commented Jun 8, 2017 at 3:42
R, 341 characters
f=function(x){g=function(x,y)el(strsplit(x,y));a=g(x,'');v=g('aeiouy','');n=letters[-c(1,5,9,15,21,25)];l=data.frame(n,g('pgtvkhjglmnbqrzdfwxs',''));y=min(match(n,a)[which(match(n,a)>min(match(v,a),na.rm=T))]);m=l[which(l$n==a[y]),2];e<-a[-c(1:y)][min(match(v,a[-c(1:y)]),na.rm=T)];paste0(paste0(a[c(1:y)],collapse=''),m,e,m,e,collapse="")}
Horrendous R attempt, why are strings so hard
Readable version:
f = function(x) {
g = function(x, y)el(strsplit(x, y))
a = g(x, '')
v = g('aeiouy', '')
n = letters[-c(1, 5, 9, 15, 21, 25)]
l = data.frame(n, g('pgtvkhjglmnbqrzdfwxs', ''))
y = min(match(n, a)[which(match(n, a) > min(match(v, a), na.rm = T))])
m = l[which(l$n == a[y]), 2]
e <-a[-c(1:y)][min(match(v, a[-c(1:y)]), na.rm = T)]
paste0(paste0(a[c(1:y)], collapse = ''), m, e, m, e, collapse = "")
}
-
\$\begingroup\$ I believe your count it is off - I count 340 bytes \$\endgroup\$Taylor Raine– Taylor Raine2017年07月22日 20:03:59 +00:00Commented Jul 22, 2017 at 20:03
-
\$\begingroup\$ Got it down to 304 bytes \$\endgroup\$Giuseppe– Giuseppe2017年07月25日 20:54:01 +00:00Commented Jul 25, 2017 at 20:54
Python 3.8 (pre-release), 142 bytes
s=input()
g=lambda i,f='aeiuoy':i if s[i]in f else g(i+1,f)
q=g(g(0),c:='pgtcvkh jglmn bqrzd fwx s')
exit(s[:-~q]+(c[ord(s[q])-98]+s[g(q)])*2)
A little late to the party, but here's yet another non-regex Python answer! I interpreted the rules to allow printing to STDERR which saves a byte (exit
/print
). Using Python 3.8 over 3<=3.7 saves me a total of 1 byte with the walrus operator as opposed to defining the c
variable elsewhere.
Thanks a lot to Post Rock Garf Hunter (-21 bytes) for the help!
-
2\$\begingroup\$ Looks good! +1 for the good job :D also, you are never late for a code-golf party! \$\endgroup\$RGS– RGS2020年02月13日 14:08:16 +00:00Commented Feb 13, 2020 at 14:08
-
1\$\begingroup\$ You can take off some bytes by having
b
look for the index instead of the character since indexing is shorter than.find
. Try it online! \$\endgroup\$2020年02月13日 15:03:38 +00:00Commented Feb 13, 2020 at 15:03 -
\$\begingroup\$ I really, really like this, but does it not break on input words such as
peeled
? Try it online! I need a bit of time to properly understand it, I can't quite figure out how to fix it but I have a feeling that it is possible! \$\endgroup\$chinatsu– chinatsu2020年02月13日 15:49:21 +00:00Commented Feb 13, 2020 at 15:49 -
-
1\$\begingroup\$ You can save a few bytes with short-circuiting \$\endgroup\$squid– squid2020年02月13日 16:51:07 +00:00Commented Feb 13, 2020 at 16:51
Perl, 71 bytes
s#[aeiouy]+(.)\K.*?([aeiouy]).*#"1ドル2ドル"=~y/bcdfgkpstvz/pgtvkgbzdfs/rx2#e
Also run with perl -pe
. A few bytes less than the previous Perl solution. Admittedly I got some inspiration from there as well.
05AB1E, (削除) 101 (削除ここまで) (削除) 104 (削除ここまで) 88 bytes
-16 bytes thanks to Okx
I somehow hope this can be done way more efficiently.
žOÃćIsk>[DIs£¤žPså#\>]s[DIsèDžOså#\>]ŠŠ"bpcgdtfvgkhhjjkgllmmnnpbqqrrsztdvfwwxxzs"S2ôDí«ø`Šs¤sŠksŠès×ばつ«
Explanation
Argument: s
žOÃ0èk Get index of first vowel in s
>[DIs£¤žPså#\>] Increment index and split s until last character of substring is a consonant
s[DIsèDžOså#\>] Increment index an get character at index in s until character is a vowel
ŠŠ Rearrange stack
.•7¶ëÒ—Öb ́ƒ≠Ä"šʒÆμJ^ÝV"Îpи•S2ôDí«ø` Prepare character substitution map
Šs Rearrange stack
¤ Last character of substring
sŠ Rearrange stack (yes, again)
k Index of last character in substitution key list
sŠ Rearrange stack (it won't stop)
è Character at index in character substitution value list
sŠ Rearrange stack (ONE LAST TIME)×ばつ« Prepend substitution consonant before vowel, duplcicate and concatenate with the substring from the very beginning
-
\$\begingroup\$ You can replace
"bpcgdtfvgkhhjjkgllmmnnpbqqrrsztdvfwwxxzs"
with.•7¶ëÒ—Öb´ƒ≠Ä"šʒƵJ^ÝV"Îpи•
to save 15 bytes \$\endgroup\$Okx– Okx2017年06月19日 09:41:11 +00:00Commented Jun 19, 2017 at 9:41 -
\$\begingroup\$ You can also replace
žOÃćIsk
withžOÃ0èk
to save another byte. \$\endgroup\$Okx– Okx2017年06月19日 09:47:30 +00:00Commented Jun 19, 2017 at 9:47 -
\$\begingroup\$ @Okx I think I really need to learn some String compression techniques. Thanks! \$\endgroup\$kalsowerus– kalsowerus2017年06月19日 12:41:06 +00:00Commented Jun 19, 2017 at 12:41
-
\$\begingroup\$ @kalsowerus I know it's been a while, but you can golf 8 bytes from your answer like this:
žOÃнk>[DIs£¤žPså#\>]©s[DIsèDžOså#\>]s\.•7¶ëÒ—Öb´ƒ≠Ä"šʒƵJ^ÝV"Îpи•S2ôDí«ø`®θkèìDJ
Try it online. I mainly got rid of all the swaps and triple-swaps by using a variable instead. And0è
can beн
, and I've replaced2׫
withDJ
to join the entire stack together. PS: I've also posted a 55 bytes 05AB1E answer using a different technique. (Which also includes a link to better understand compression in 05AB1E. :D) \$\endgroup\$Kevin Cruijssen– Kevin Cruijssen2018年12月01日 11:27:37 +00:00Commented Dec 1, 2018 at 11:27
Vim, 107 keystrokes
Who needs Java, Python 3, Modern Pascal 2.0, C#, Python 2, R, Go, C, BlitzMax, Javascript, Crystal, Clojure, Lua, Matlab/Octave, Haskell and PHP when you have vim?
i ⎋o⏎bcdfghjklmnpqrstvwxz⏎pgtvkhjglmnbqrzdfwxs⎋1Ghqy/[aeiouy]⏎q/[^aeiouy]⏎mz@yyl`zpld$yhjpg*jyl`zpy2lPjdGX
⎋
is the Escape key and ⏎
is the Return key
Explanation
i ⎋ Insert a space before the first character
o⏎bcdfghjklmnpqrstvwxz⏎ Insert the character data
pgtvkhjglmnbqrzdfwxs⎋1Gh
qy/[aeiouy]⏎q Find the first vocal after the space
/[^aeiouy]⏎mz Find the next consonant and add a marker
@yyl`zp Find the next vocal and put it after the consonant
ld$ Delete the rest of the world
yhjpg* Search for the consonant in the first row of the character data
jyl Copy the character in the same position in the second row
`zpy2lPjdGX Paste it after the last vowel and repeat the two last characters
-
\$\begingroup\$ I may be wrong, but it doesn't look like
[aeiou]
and[^aeiou]
account for the fact that, in this challenge,y
is considered a vowel. \$\endgroup\$FlipTack– FlipTack2018年01月03日 16:32:02 +00:00Commented Jan 3, 2018 at 16:32
05AB1E, (削除) 55 (削除ここまで) 42 bytes
η.ΔžOSåàyžPSÅ¿à*}ÐIsKžOÃнsθ.•gÍĆdQ ̧G•‡ìDJ
-13 bytes thanks to @Grimmy.
Try it online or verify all test cases.
Explanation:
η # Suffixes of the (implicit) input
# i.e. "creation" → ["c","cr","cre","crea","creat","creati","creato","creatio","creation"]
.Δ } # Find the first for which the following is truthy:
žO # Push vowels (including y): "aeiouy"
S # Convert it to a list of characters: ["a","e","i","o","u","y"]
å # Check for each if they're in the current (implicit) suffix
# i.e. "creat" → [1,1,0,0,0,0]
à # Pop and push the max (basically check if any are truthy)
# i.e. [1,1,0,0,0,0] → 1
y # Push the suffix again
žP # Push the consonants (excluding y): "bcdfghjklmnpqrstvwxz"
S # Convert to a list of characters: ["b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","v","w","x","z"]
Å¿ # Check for each if the suffix ends with it
# i.e. "creat" → [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0]
à # Pop and push the max (basically check if any are truthy)
# i.e. [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0] → 1
* # Check if both are truthy
# i.e. 1 and 1 → 1
Ð # Triplicate the found suffix
I # Push the input
s # Swap the top two items on the stack
# i.e. stack contains now: "creat","creat","creation","creat"
K # Remove the suffix from the input
# i.e. "creation" and "creat" → "ion"
žOÃ # Only leave the vowels
# i.e. "ion" → "io"
н # Pop and push the first character
# i.e. "io" → "i"
s # Swap again so the prefix is a the top of the stack again
θ # Pop and push the last character
# i.e. "creat" → "t"
.•gÍĆdQ ̧G• # Push string "bcdfkszgvtgp"
 # Bifurcate it (short for Duplicate & Reverse copy): "pgtvgzskfdcb"
‡ # Transliterate the character of "bcdfkszgvtgp" to the same index in "pgtvgzskfdcb"
ì # Prepend the second character in front of the first
# i.e. "d" and "i" → "di"
D # Duplicate it
J # Join the stack together (and output implicitly)
# i.e. "creat" and "di" and "di" → "creatdidi"
See this 05AB1E tips of mine (section How to compress strings not part of the dictionary?) to understand why .•gÍĆdQ ̧G•
is "bcdfkszgvtgp"
.
-
1\$\begingroup\$ I ended up making my own answer, since even though I used your answer as a starting point, the result is very different. Unfortunately couldn’t get it below 35. \$\endgroup\$Grimmy– Grimmy2020年02月01日 12:44:58 +00:00Commented Feb 1, 2020 at 12:44
Crystal, 130 Bytes
c=/[aeiouy]/
x,y,z=ARGV[0].partition /[^aeiouy]*#{c}*/
k=z[0]
b=((i="pgtvkgbqrzdfs"=~/#{k}/)?"bcdfgkpqrstvz"[i]: k)+z[c]
p y+k+b*2
How it works
c = /[aeiouy]/
store a regex for searching first vowel to c
.
x, y, z = ARGV[0].partition /[^aeiouy]*#{c}*/
split the first argument into three parts {"", String until one character before the first consonant after first vowel, rest of string} and store each of the elements into x, y and z.
k = z[0]
get the first character, the relevant consonant.
i = "pgtvkgbqrzdfs" =~ /#{k}/
get the index of the consonant inside the left string or nil
.
b = ((i = ...) ? "bcdfgkpqrstvz"[i] : k) + z[c]
if i
is not nil
, use this index for the second string (kind of a golfed hash).
if i
is nil
, use the original character.
next, append the first vowel of z
.
p y + k + (b * 2)
finally, print first part from first regex y
, the first consonant k
and two times the previous calculated string b
.
sed, 106 (105+1) bytes
This is sed with the -E
flag, which apparently counts for one byte.
s/([aoeuiy][^aoeuiy])[^aoeuiy]*(.).*/1円2円/
h
s/.*(..)/1円1円/
y/bcdfgkpstvz/pgtvkgbzdfs/
x
s/.$//
G
s/\n//g