44
7
The challenge
Well, I think it is quite clear, isn't it? You have to make a function or a program that takes a string as an argument and outputs the corrispondent Yoda-speaking.
This is code-golf, so least number of bytes wins.
The input
The input could be any string without linefeed. You can translate a string if it is composed like this:
Subject + Verb + Something else.
Where Subject is a personal pronoun (I, you, he, she, it, we, they). You don't have to recognize that the second word is a verb.
If the first word isn't a pronoun, the input is valid but the output will be Too difficult, this sentence is.
You have to win this code challenge -> Translatable
Luke has to win this code challenge -> Untranslatable
Input can end with a letter, a . or a !, not with a ?.
Furthermore, strings can contain Non-Ascii, Parenthesis, commas, colons ...
The output
In case of a translatable sentence, the output is the same sentence, with the subject and the verb at the end of the sentence.
You have to win this code challenge -> To win this code challenge, you have.
Comma, period and lower-case on the pronoun are mandatory. (Except, of course, if the pronoun is I).
As stated before, if it is untranslatable you have to output the string Too difficult, this sentence is.
Examples
You have to win this code challenge -> To win this code challenge, you have.
He won this code challenge -> This code challenge, he won. (I know this is not yoda-speaking, but I don’t want to overcomplicate this challenge)
I ate an ice cream earlier! -> An ice cream earlier, I ate.
I liked the Star Wars original trilogy more than the prequel’s one. -> The Star Wars original trilogy more than the prequel’s one, I liked.
I find your lack of faith disturbing -> Your lack of faith disturbing, I find.
I think we are done with the examples -> We are done with examples, I think.
He is your son, Vader -> Your son, Vader, he is.
I think they’ll add new features -> They’ll add new features, I think.
I made a fantastic code challenge (I hope) -> A fantastic code challenge (I hope), I made.
I love constants like π -> Constants like π, I love.
I’ll be the next President, I swear! -> Too difficult, this sentence is.
This challenge is great! -> Too difficult, this sentence is.
Is this challenge great? -> Too difficult, this sentence is.
Luke is not ready for this task -> Too difficult, this sentence is.
Somebody loves constants like π -> Too difficult, this sentence is.
[Empty string] -> Too difficult, this sentence is.
@steveverrill you are right, i edited the post. Thank you very much! – Simone Chelo – 2016-01-04T11:20:04.883
9From a non-question point of view, shouldn't infinitives be moved as well? For example, the
You have to win this code challenge
should beThis code challenge, you have to win
. – Addison Crump – 2016-01-04T12:07:31.0339"To win this code challenge, you have." sounds really strange. – nicael – 2016-01-04T12:35:14.657
3Can the input contain commas? What if the input doesn't end in a letter, period or
!
? Is that guaranteed not to happen or should we handle that and print the same thing as when there is no leading pronoun. Can the input contain linefeeds? Apostrophes? Colons/parentheses/backticks? Non-ASCII characters? You say the "the input could be any string", but your test cases only cover very specific types of strings. – Martin Ender – 2016-01-04T13:08:55.153To FlagAsSpam and nicael, you are both right. I thought that adding those rule would unnecesseraly overcomplicate the task.
Martin Büttner: Yes, it can contain commas: added example. Nothing happens, as you can see in examples. No, the input cannot contain linefeed, you can assume that. added info. Apostrophe, parantheses, Non-ASCII .... yeah, why not? added examples. – Simone Chelo – 2016-01-04T13:36:29.753
@SimoneChelo Additional test case:
You will not win this challenge...! -> Not win this challenge..., you will.
. A bit tricky because you can't use a pattern like(pronoun word)(string that doesn't end with puctuation)
and then exchange them. – Rainer P. – 2016-01-04T14:59:52.8334'have to' is an odd helper-verb construction peculiar to English; it's unlikely Yoda would use it. "This code challenge, win, you must." On the other hand, Yoda has his own helper-verb constructions he tends to use: "This code challenge, won, he did." I can't picture Yoda saying "This code challenge, he won" or "to win this code challenge, you have". – LindaJeanne – 2016-01-04T15:16:22.467
@RainerP. "Win this challenge, you will not." (c.f. "when 900 years old you are, look as good, you will not.) – LindaJeanne – 2016-01-04T15:24:52.357
Object (optional), Comma (if object), Primary Verb, Comma, Subject, Helper verb or modifier. (Of course, all this is irrelevant, because there's no reason the parameters of the challenge need to be accurate to actual Yoda-speak to be a good challenge). – LindaJeanne – 2016-01-04T15:26:27.533
1@nicael
Win this code challenge, you must
is better... – wizzwizz4 – 2016-01-04T17:20:43.237@wiz Yeah, this sounds better. – nicael – 2016-01-04T17:21:26.593
It is not usually accepted by our community to accept an answer to the challenge 3 hours later. Give other people the chance to win! – TanMath – 2016-01-04T21:35:40.827
"I ate an ice cream" ? – Cyoce – 2016-01-05T03:09:10.020
@LindaJeanne I can't picture Yoda saying anything at all about a "code challenge"! – Cyoce – 2016-01-05T04:10:13.347
"Input can end with a letter, a . or a !, not with a ?." It looks like you're listing all characters the input can end with, yet the example "I love constants like π" does not correspond to any of those case. Maybe you should simplify your sentence to "Input can't end with a ?". – Aaron – 2016-01-05T10:06:00.237
@Cyoce The interests of someone who lived 800 years, you should not underestimate. – Aaron – 2016-01-05T10:26:15.453
4Don't the answers need more 'Mmmmm's? – Steve Ives – 2016-01-05T14:56:14.360