| Bytes | Lang | Time | Link |
|---|---|---|---|
| 110 | AWK | 250409T193707Z | xrs |
| 035 | Perl 6 | 180327T173350Z | nwellnho |
| 106 | Elixir | 180327T181403Z | Okx |
| 165 | Excel | 180328T100216Z | Wernisch |
| 134 | Excel VBA | 180410T024836Z | Taylor R |
| 3634 | Pyth | 180330T151356Z | RK. |
| 154 | C# .NET Core | 180328T164328Z | Anderson |
| 098 | PowerShell Core | 180404T165635Z | Jeff Fre |
| 079 | Unix | 180402T192614Z | Ali ISSA |
| 155 | Clojure | 180329T184316Z | Bob Jarv |
| 134 | C++ 14 g++ | 180328T133616Z | O.O.Bala |
| 062 | APL Dyalog Classic | 180330T180227Z | Adalynn |
| 073 | Jelly | 180330T153705Z | Adalynn |
| 073 | APL Dyalog Classic | 180328T225917Z | Adalynn |
| 080 | Python 3 | 180330T135423Z | etene |
| 104 | Python | 180328T095519Z | dieter |
| 094 | JavaScript | 180327T182804Z | Shaggy |
| 049 | Ruby | 180327T193644Z | Reinstat |
| 132 | PHP | 180329T172842Z | Chris Fo |
| 059 | Pyth | 180328T185606Z | hakr14 |
| 106 | Java 8 | 180328T095613Z | Kevin Cr |
| 045 | PHP | 180329T091542Z | Berry M. |
| 142 | Red | 180328T084757Z | Galen Iv |
| 027 | Jstx | 180329T041450Z | Quantum6 |
| 039 | Perl 5 p | 180327T181627Z | Xcali |
| 069 | Ruby | 180327T200342Z | anna328p |
| 068 | K4 | 180327T202511Z | mkst |
| 087 | JavaScript Node.js | 180328T165522Z | DanielIn |
| 092 | Python 2 | 180327T192734Z | Chas Bro |
| 034 | vim | 180327T231440Z | Ray |
| 114 | Python 3 | 180327T201833Z | Dat |
| 027 | V | 180327T171726Z | user4180 |
| 030 | 05AB1E | 180328T092117Z | Emigna |
| 029 | Retina | 180327T213553Z | Martin E |
| 032 | V | 180327T181857Z | Endenite |
| 026 | Stax | 180327T184011Z | recursiv |
| 038 | SOGL V0.12 | 180327T170306Z | dzaima |
| 144 | Python | 180327T164405Z | touch my |
AWK, 110 bytes
{for(;i++<NF;)s=s (i~1?toupper($i):tolower($i))
t=sub(/ey$/,X,s)?2:sub(/y$/,X,s)}$0=s (t~2?"e":X)"y Mc"s"face"
{for(;i++<NF;) # for each char
s=s # create/append to string
(i~1?toupper($i) # 1st uppercase
:tolower($i)) # rest lower
t=sub(/ey$/,X,s)?2: # delete ey or
sub(/y$/,X,s)} # delete y
$0=s # set output to string
(t~2?"e":X) # put e back if nec
"y Mc"s"face" # add y and remainder
Elixir, 112 110 107 106 bytes
now as short as java
fn x->x=String.capitalize x;"#{x<>if x=~~r/y$/,do: "",else: "y"} Mc#{String.replace x,~r/e?y$/,""}face"end
Explanation:
x=String.capitalize x
Gets x with the first character in uppercase and all others lowercase.
#{ code }
Evaluate the code and insert it into the string.
#{x<>if x=~ ~r/y$/, do: "", else: "y"}
Concatenates x with y if it does not end with y (ie it does not match the regex y$).
#{String.replace x, ~r/e?y$/, "")}
Removes trailing ey and trailing y.
Excel, 204 144 137 165 bytes
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(REPT(REPLACE(LOWER(A1),1,1,UPPER(LEFT(A1)))&"~",2),"~","y Mc",1),"yy ","y "),"ey~","~"),"y~","~"),"~","face")
From the inside outwards:
REPLACE(LOWER(A1),1,1,UPPER(LEFT(A1))) Replaces PROPER to handle space-delimited cases
REPT(%&"~",2) Duplicate. Donkey~Donkey~
SUBSTITUTE(%,"~","y Mc",1) Replace first ~. Donkeyy McDonkey~
SUBSTITUTE(%,"yy ","y ") Handle words ending in 'y'. Donkey McDonkey~
SUBSTITUTE(%,"ey~","~") Handle words ending in 'ey' Donkey McDonk~
SUBSTITUTE(%,"y~","~") Handle words ending in 'y' Donkey McDonk~
SUBSTITUTE(%,"~","face") Adding face. Donkey McDonkface
Old answer, creating all bits separately, and then concatenating (176 bytes). Does not handle space-delimited cases correctly.
=PROPER(A1)&IF(LOWER(RIGHT(A1,1))="y",,"y")&" Mc"&IF(LOWER(RIGHT(A1,2))="ey",LEFT(PROPER(A1),LEN(A1)-2),IF(LOWER(RIGHT(A1,1))="y",LEFT(PROPER(A1),LEN(A1)-1),PROPER(A1)))&"face"
Excel VBA, 134 bytes
An anonymous VBE Immediate Window Function that takes input from range [A1] and outputs to the Immediate Window.
b=[Left(Upper(A1))]+Mid([Lower(A1)],2):l=len(b):y=[Right(A1)="y"]:?b;IIf(y,"","y")" Mc"IIf(y,Left(b,l-1+(InStrRev(b,"e")=l-1)),b)"face
Pyth, 36 34 bytes
++Jrz4*\yqJK:J"e?y$"k+" Mc"+K"face
Explanation:
++Jrz4*\yqJK:J"(e)?y$"k+" Mc"+K"face
Jrz4 Set J to the titlecase of z (input)
K:J"e?y$"k Set K to (replace all matches of the regex e?y$ in J with k (empty string))
qJ Compare if equal to J
*\y Multiply by "y" (if True, aka if no matches, this gives "y", else it gives "")
+ Concatenate (with J)
+K"face Concatenate K with "face"
+" Mc" Concatenate " Mc" with that
+ Concatenate
C# (.NET Core), 122 108 139 175 180 179 154 bytes
Thanks a lot, lee!
s=>((s.EndsWith("y")?s:s+"y")+" Mc"+(s+"$").Replace("ey$","")+"face").Replace(s,s.ToUpper()[0]+s.Substring(1).ToLower()).Replace("y$","").Replace("$","");
C# (.NET Core, with LINQ), 152 bytes
s=>((s.Last()=='y'?s:s+"y")+" Mc"+(s+"$").Replace("ey$","")+"face").Replace(s,s.ToUpper()[0]+s.Substring(1).ToLower()).Replace("y$","").Replace("$","");
PowerShell Core, 98 bytes
(("y$","e?(?=y)y$"|%{$o.ToUpper()[0]+$o.ToLower().Substring(1)-replace $_,""})-join "y Mc")+"face"
Many thanks to @Anderson Pimentel for inspiring a solution using regex replacements!
Unix (79 bytes)
Using Standard input :
rev|sed -r 's/(.*)(.)$/\L\1\U\2/;s/^(ye?)?(.*)$/ecaF\2cM y\1\2/;s/ yy/ y/'|rev
test :
echo -e "Lady\nFace\nDonkey\nyyy"|rev|sed -r 's/(.*)(.)$/\L\1\U\2/;s/^(ye?)?(.*)$/ecaF\2cM y\1\2/;s/ yy/ y/'|rev
Lady McLadFace
Facey McFaceFace
Donkey McDonkFace
Yyy McYyFace
or ( by Function) :
F(){ echo $1|rev|sed -r 's/(.*)(.)$/\L\1\U\2/;s/^(ye?)?(.*)$/ecaF\2cM y\1\2/;s/ yy/ y/'|rev;}
test :
F donkey
Donkey McDonkFace
Clojure: 161 155
(use '[clojure.string :as s])
(defn f[t](s/join[(s/capitalize(cond(=(last t)\y)t :else(s/join[t "y"])))" Mc"(s/capitalize(s/replace t #"e*y$" ""))"face"]))
Ungolfed:
(defn facegen [s0]
(let [ s1 (clojure.string/capitalize (cond
(= (last s0) \y) s0
:else (clojure.string/join [s0 "y"])))
s2 (clojure.string/capitalize (clojure.string/replace s0 #"e*y$" ""))]
(clojure.string/join [s1 " Mc" s2 "face"])))
C++ 14 (g++), 181 171 148 147 134 bytes
[](auto s){s[0]&=95;int i=1,b;for(;s[i];)s[i++]|=32;b=s[--i]-'y';return s+(b?"y":"")+" Mc"+(b?s:s.substr(0,s[i-1]-'e'?i:i-1))+"face";}
Note that clang will not compile this.
Credit goes to Kevin Cruijssen and Olivier Grégoire for the &95 trick.
Thanks to Chris for golfing 11 bytes.
Try it online here.
Ungolfed version:
[] (auto s) { // lambda taking an std::string as argument and returning an std::string
s[0] &= 95; // convert the first character to upper case
int i = 1, // for iterating over the string
b; // we'll need this later
for(; s[i] ;) // iterate over the rest of the string
s[i++] |= 32; // converting it to lower case
// i is now s.length()
b = s[--i] - 'y'; // whether the last character is not a 'y'
// i is now s.length()-1
return s + (b ? "y" : "") // append 'y' if not already present
+ " Mc"
+ (b ? s : s.substr(0, s[i-1] - 'e' ? i : i-1)) // remove one, two, or zero chars from the end depending on b and whether the second to last character is 'e'
+ "face";
}
APL (Dyalog Classic), 62 bytes
{'face',⍨(' Mc','e?y$'⎕r''⊢S),⍨S,(Y≠⊃⌽S←⍵(819⌶¨)⍨1=⍳⍴⍵)/Y←'y'}
Thanks to @ngn for this solution!
Jelly, 77 75 74 73 bytes
2ḶNṫ@€⁼"“y“ey”S
ØA;"ØaF
¢y⁸µ¢Uyµ1¦
Çṫ0n”yẋ@”y;@Ç;“ Mc”
⁸JU>ÑTị3Ŀ;@Ç;“face
Any golfing suggestions are welcome (and wanted)!
APL (Dyalog Classic), 95 90 88 87 86 85 84 82 80 78 77 73 bytes
{'face',⍨(' Mc',S↓⍨-+/∧/¨Y'ey'=¨↑∘S¨-⍳2),⍨S,(Y≠⊃⌽S←⍵(819⌶¨)⍨1=⍳⍴⍵)/Y←'y'}
This could be golfed down some more, and any suggestions are welcome!
Python 3, 80 bytes
Long time avid reader, my first submission at last !
lambda y:re.sub("([\w ]+?)((e)?y)?$",r"\1\3y Mc\1face",y.capitalize())
import re
Python, 105 104
import re;r=re.sub;c=str.capitalize;f=lambda s:r('([^e^y])$','\\1y',c(s))+' Mc'+r('ey$','',c(s))+'face'
thx @Berry M. from noticing my dyslexia
JavaScript, 103 96 94 bytes
Pretty naïve first pass at this.
s=>(g=r=>s[0].toUpperCase()+s.slice(1).toLowerCase().split(r)[0])(/y$/)+`y Mc${g(/e?y$/)}face`
Ruby, 61 49 bytes
->s{s.capitalize=~/(e)?y$|$/;"#$`#$1y Mc#$`face"}
Saved 12 sweet bytes thanks to @MartinEnder:
- a slimmer regular expression, which made use of
- some of Ruby's special global variables which I tend to forget, and
- bracketless string interpolation (see e.g. https://codegolf.stackexchange.com/a/52357/11071), which I never knew existed.
PHP: 132
<?php function f($s){$s=ucfirst(strtolower($s));return $s.(substr($s,-1)=='y'?'':'y').' Mc'.preg_replace('/(ey|y)$/','',$s).'face';}
Explanation:
<?php
function f($s)
{
// Take the string, make it all lowercase, then make the first character uppercase
$s = ucfirst(strtolower($s));
// Return the string, followed by a 'y' if not already at the end, then ' Mc'
// and the string again (this time, removing 'y' or 'ey' at the end), then
// finally tacking on 'face'.
return $s
. (substr($s, -1) == 'y' ? '' : 'y')
. ' Mc'
. preg_replace('/(ey|y)$/', '', $s)
. 'face';
}
Pyth, 60 59 bytesSBCS
K"ey"Jrz4Iq>2JK=<2J=kK.?=k\yIqeJk=<1J))%." s÷ WZÞàQ"[JkJ
They don't display here, but three bytes, \x9c, \x82, and \x8c are in the packed string between s and ÷. Rest assured, the link includes them.
K="ey"
J=input().capitalize()
if J[-2:]==K:
J=J[:-2]
k=K
else:
k="y"
if J[-1]==k:
J=J[:-1]
print("{}{} Mc{}face".format(J,k,J))
Java 8, 121 112 107 106 bytes
s->(s=(char)(s.charAt(0)&95)+s.toLowerCase().substring(1)).split("y$")[0]+"y Mc"+s.split("e?y$")[0]+"face"
-1 byte thanks to @OliverGrégoire.
Explanation:
s-> // Method with String as both parameter and return-type
(s= // Replace and return the input with:
(char)(s.charAt(0)&95) // The first character of the input as Uppercase
+s.toLowerCase().substring(1))
// + the rest as lowercase
.split("y$")[0] // Remove single trailing "y" (if present)
+"y Mc" // Appended with "y Mc"
+s.split("e?y$")[0] // Appended with the modified input, with "y" or "ey" removed
+"face" // Appended with "face"
Red, 143 142 bytes
func[s][s: lowercase s s/1: uppercase s/1
w: copy s if"y"<> last s[append w"y"]rejoin[w" Mc"parse s[collect keep to[opt["y"|"ey"]end]]"face"]]
Ungolfed:
f: func[s][
s: lowercase s ; make the entire string lowercase
s/1: uppercase s/1 ; raise only its first symbol to uppercase
w: copy s ; save a copy of it to w
if "y" <> last s[append w "y"] ; append 'y' to w if it doesn't have one at its end
rejoin[w ; assemble the result by joining:
" Mc"
; keep the string until "y", "ey" or its end
parse s[collect keep to [opt ["y" | "ey"] end]]
"face"
]
]
Jstx, 27 bytes
h</►yT↓►y/◙♂ Mc♀/◄eyg►yg/íå
Explanation
# Command line args are automatically loaded onto the stack
h # Title case the top of the stack
< # Duplicate the top value on the stack twice
/ # Print the top value on the stack
►y # Load 'y' onto the stack
T # Returns true if the 2nd element on the stack ends with the top
↓ # Execute block if the top of the stack is false
►y # Load 'y' onto the stack
/ # Print the top value on the stack
◙ # End the conditional block
♂ Mc♀ # Load ' Mc' onto the stack
/ # Print the top value on the stack
◄ey # Load 'ey' onto the stack
g # Delete the top of the stack from the end of the 2nd element on the stack if it exists
►y # Load 'y' onto the stack
g # Delete the top of the stack from the end of the 2nd element on the stack if it exists
/ # Print the top of the stack
íå # Load 'face' onto the stack
# Print with newline is implied as the program exits
Perl 5 -p, 47 39 bytes
Saved 6 bytes with @OlegV.Volkov's suggestions, 1 with @mwellnhof's, and 1 on my own
$_=lc^$";$_=s/y?$/y Mc/r.s/e?y$//r.face
Ruby, 69 bytes
->s{"#{(s.capitalize!||s)[-1]==?y?s:s+?y} Mc#{s.gsub /e?y$/,""}face"}
Explanation:
->s{ } # lambda
"#{ } Mc#{ }face" # string interpolation
(s.capitalize!||s) # returns string capitalized or nil, in that case just use the original string
[-1]==?y # if the last character == character literal for y
?s:s+?y # then s, else s + "y"
s.gsub /e?y$/,"" # global substitute
# remove "ey" from end
K4, 74 69 68 bytes
Solution:
{$[r;x;x,"y"]," Mc",_[r:0&1-2/:"ye"=2#|x;x:@[_x;0;.q.upper]],"face"}
Examples:
q)k)f:{$[r;x;x,"y"]," Mc",_[r:0&1-2/:"ye"=2#|x;x:@[_x;0;.q.upper]],"face"}
q)f each ("boat";"Face";"DOG";"Family";"Lady";"Donkey";"Player")
"Boaty McBoatface"
"Facey McFaceface"
"Dogy McDogface"
"Family McFamilface"
"Lady McLadface"
"Donkey McDonkface"
"Playery McPlayerface"
Explanation:
Figure out if the last characters are equal to "ey", convert result to base-2 so we can ignore words that end "e?". Index into a list of numbers of characters to trim.
Managed to shave 5 bytes off my code to determine whether the last two chars at "ey" but struggling to better it...
{$[r;x;x,"y"]," Mc",_[r:0&1-2/:"ye"=2#|x;x:@[_x;0;.q.upper]],"face"} / the solution
{ } / lambda function
,"face" / join with "face"
_[ ; ] / cut function
@[_x; ; ] / apply (@) to lowercased input
0 / at index 0
.q.upper / uppercase function
x: / save back into x
|x / reverse x
2# / take first two chars of x
"ye"= / equal to "ye"?
2/: / convert to base 2
1- / subtract from 1
0& / and with 0 (take min)
r: / save as r
," Mc", / join with " Mc"
$[r;x;x,"y"] / join with x (add "y" if required)
Bonus:
67 byte port in K (oK):
{$[r;x;x,"y"]," Mc",((r:0&1-2/"ye"=2#|x)_x:@[_x;0;`c$-32+]),"face"}
JavaScript (Node.js), 87 bytes
- thanks to @Shaggy for 5 reducing 5 bytes
s=>(g=r=>Buffer(s.replace(r,"")).map((x,i)=>i?x|32:x&~32))(/y$/)+`y Mc${g(/e?y$/)}face`
Python 2, 88 92 bytes
lambda s:(s+'y'*-~-(s[-1]in'yY')).title()+' Mc'+re.sub('e?y$','',s.title())+'face'
import re
vim, 35 34 bytes
Vu~Yp:s/ey$
:%s/y$
kgJiy Mc<ESC>Aface<ESC>
<ESC> is 0x1b
Ungolfed
Vu~ # Caseify McCaseface
Yp # dup line
:s/ey$
:%s/y$ # Get the suffixes right
kgJiy Mc<ESC>Aface<ESC> # Join lines and add the extra chars
Saved 1 byte thanks to DJMcMayhem
Python 3, 117 114 bytes
-3 bytes thanks to Dead Possum
def f(s):s=s.title();return s+'y'*(s[-1]!='y')+' Mc'+([s,s[:-1],0,s[:-2]][(s[-1]=='y')+((s[-2:]=='ey')*2)])+'face'
V, 27 28 30 bytes
Vu~Ùóe¿y$
Hóy$
ÁyJaMc<Esc>Aface
<Esc> represents 0x1b
Golfed two bytes after learning that we did not need to support inputs with less than 3 characters.
1 byte saved thanks to @DJMcMayhem by working on the second line before the first one, thus removing the
G
The input is in the buffer. The program begins by converting everything to lowercase
V selects the line and u lowercases it
~ toggles the case of the first character (converting it to uppercase)
and Ù duplicates this line above, leaving the cursor at the bottom line
ó and replaces e¿y$, compressed form of e\?y$ (optional e and a y at the end of the line), with nothing (happens on the second line)
H goes to the first line
ó replaces y$ (y at the end of the line) with nothing on the first line
Á appends a y to the end of the first line
J and joins the last line with the first with a space in the middle, and the cursor is moved to this space
a appends Mc (<Esc> returns to normal mode)
A finally, appends face at the end of the line
V, 38 36 32 bytes
-5 byte thanks to @Cows quack
Vu~hy$ó[^y]$/&y
A Mc<esc>póe¿y$
Aface
<esc> is a literal escape character and [^ is encoded as \x84
Stax, 26 bytes
ëO╛εh╕⌠î&!}∞┌C^U╟«äδ◙Bg⌠└¿
^ convert input to upper case "FACE"
B~ chop first character and push it back to input 70 "ACE"
v+ lowercase and concatenate "Face"
c'yb copy, push "y", then copy both "Face" "Face" "y" "Face" "y"
:] string ends with? "Face" "Face" "y" 0
T trim this many character "Face" "Face" "y"
+ concatenate "Face" "Facey"
p output with no newline "Face"
"e?y$"z push some strings "Face" "e?y$" ""
" Mc`Rface execute string template; `R means regex replace " Mc Faceface"
result is printed because string is unterminated
Python, 144 bytes
def f(s):
s=s[0].upper()+s[1:].lower()
y=lambda s:s[:-1]if s[-1]=='y'else s
t=y(s)
u=s[:-2]if s[-2:]=='ey'else y(s)
return t+'y Mc%sface'%u