Code golf for my real friends
Retina, 119 bytes
The previous version didn't manage correctly the space in "platonic solids", this one works and is shorter :)
ew
rw
eds
ed
(\w+) ?([^oatr ]\w{3}.+)real
and real $2$1
C
S
gne
in
o
o-
ti
ty
T`TL`Tl
p\w+y.+
$&.
s$
s!
real -p
RealPl
Try it online!
This transforms the input into the output through a series of substitutions.
The most interesting part is this substitution (kind of a regex golf):
(\w+) ?([^oatr ]\w{3}.+)real
and real $2$1
Which does almost all the job, by splitting the first word, placing its pieces in the right places, removing extra spaces, and building the structure of the output. To work correctly on the "Tumbleweeds" test case this depends on the previous substitution "eds"->"ed".
The rest is mostly composed by substitutions that deal with special cases. Other interesting parts are:
T`TL`Tl
This turns everything except "T" (for Tumblr) to lowercase.
p\w+y.+
$&.
s$
s!
This places a "." at the end of each sentence containing a word with a "y" some letters after a "p" ("petty" and "payer" in practice). Then places a "!" at the end of all sentences ending with an "s" (all the others).
Python 2, 291 269 293 255 247 bytes
Thanks to Erik the Outgolfer
for saving 22 bytes!
+24 bytes to account for some outputs ending in .
instead of !
lambda x:'and '+['real '+'pain%ssham ,pods%spseudo-,coats%spetty ,strife%sloose ,bugs%slady ,weed%sTumblr ,hawks%sfaux ,solids%splatonic '.split(',')['noarsekc'.find(x[7])],'RealPlayer%ssingle ']['-'in x]%' for my '+x[-7:]+'!.'['-'in x or'tt'in x]
Simple solution to start things off. Checks the eighth letter of the input, as suggested in the comments, and looks up the corresponding output in a dictionary an array.
Try it Online!
Python 3, 788, 403, 359 396 bytes
Latest Version
This is now my fifth attempt. I've managed to half the size of my original program. It now includes the missing "-" and I believe is a complete solution. Still I suspect on the bulky side; but much closer to the goal. I've had a lot of help. Thanks for all the helpful guidance.
s=input()
x=0
l= "Ch,pain,Sham,Ps,pods,psuedo-,Pe,coats,petty,Lo,strife,loose,La,bugs,lady,Si,RealPlayer,single,Tu,weed,Tumblr,Fa,hawks,faux,Pl,solids,platonic".split(",")
a,b,c,d,e,f,g,h = " and real","for my","friends",".!","print(a,l[p+1],b,l[p+2]",",c+d[0])","+c+d[1])",",c+d[1])"
for p in range(0,27,3):
x+=1
if s[:2] == l[p]:
if x == 2: eval(e+g)
else: eval(e+f if x in(3,6) else e+h)
Try it online!
Original Posting
This is my first post on code golf so apologies in advance for my clumsy program. Can't see how a program could be made to convert "Champagne" to "pain", "sham" by parsing the words. However I would like to see someone else solve that. So, as my level of ability dictates that my program needs to know in advance that "Champagne" is "pain", "sham", there seemed little point in actually coding an input request. As a result I've left it out and been a bit literal with my print output. Hope that's ok : )
phraseList= [ ("Champagne","pain","Sham"),
("Psudeopods","pods","psuedo-"),
("Petticoats","coats","petty"),
("Loosestrife","strife","loose"),
("Ladybugs","bugs","lady"),
("Single-payer","coats","petty"),
("Petticoats","RealPlayer","single"),
("Tumbleweeds","weed","Tumblr"),
("Fauxhawks","hawks","faux"),
("Platonic solids","real solids","platonic")
]
for phrase in phraseList:
print("Input: ",phrase[0], "for my real friends.")
if "-" in phrase[2]:
print("Output: and real", phrase[1], "for my", phrase[2]+ "friends!")
else:
print("Output: and real", phrase[1], "for my", phrase[2], "friends!")