(Feel free to skip, doesn't really matter for the algorithmic explanation of the task)
European Portuguese is a fairly complicated language to learn, mostly because of its grammar. One particular annoying thing is conjugating the verbs correctly:
We have this mechanism that, when we have a verb followed by a noun, we may replace the noun by a pronoun and create a contraction with the verb, by means of a hyphen (-).
This introduces a problem because many verb tenses sound like verb-pronoun contractions and many verb-pronoun contractions sound like verb tenses... And then, (Portuguese!) people want to write Portuguese and they know how it should sound, but they don't know if they should insert a hyphen or not... (Strictly speaking, the two variants have subtle differences in intonation.)
So we are taught a decent method to help us discern if we should use a hyphen or not, that revolves around putting the sentence in the negative form.
When the hyphen belongs there, the negative form makes the contracted pronoun go before the verb. When the hyphen doesn't belong there (and it is really just a verb tense) the verb doesn't change. So you negate the sentence and try placing the suspect pronoun in both places. What sounds right is probably the right choice.
Given a Portuguese sentence, perform the basic test to help discern if a sentence should use a hyphen in a contraction or not.
Basic algorithm for the challenge
We are going to simplify things a bit here. Your code should do the following (check below for two worked examples)
- Look for the only hyphen in the input sentence (the hyphen that we are unsure about), between two words, like so:
- Output the two following modified sentences:
- in the place of the
"nao" verbpronoun, i.e. prepend "nao" and drop the hyphen;
- in the place of the
"nao" pronoun verbswhere
verbsis the verb (with an extra "s" if the verb ended in a vowel "aeiou").
- in the place of the
"sei que apanhas-te um susto" [~I know you were scared] be the input. We find the hyphen and extract
verb = "apanhas" and
pronoun = "te". The
verb does not end in a vowel, so there will be no need to add an "s" for the second sentence. The two sentences will be of the form
"sei que _ um susto". Indeed, they are:
"sei que nao apanhaste um susto"[~I know you were not scared]
"sei que nao te apanhas um susto"[~I know were you not scared]
So clearly we should go with number 1.
Now let us take
"da-me um upvote" [~give me an upvote]. The hyphen is in
"da-me" so we take
verb = "da" and
pronoun = "me". The verb ends in a vowel so we will need to use
verbs = "das" in the second sentence:
"nao dame um upvote"[~give me an upvote not]
"nao me das um upvote"[~you don't give me an upvote]
So clearly the right Portuguese sentence would be number 2.
A string composed of spaces, characters in the range
[a-z] and a single hyphen surrounded by two words.
The input string can be in any sensible format, like a string, a list of words or a list of characters.
The two modified sentences, as described above. These can be printed separately, returned in a list, or whatever is sensible in your programming language.
- The two sentences can be interchanged, i.e. order doesn't matter.
- The two sentences can be in a single string, as long as they are separated by a character that is not in
"sei que apanhas-te um susto" -> "sei que nao apanhaste um susto", "sei que nao te apanhas um susto" "da-me um upvote" -> "nao dame um upvote", "nao me das um upvote" "conta-me no que estas a pensar" -> "nao contame no que estas a pensar", "nao me contas no que estas a pensar" "pensei em bater-te" -> "pensei em nao baterte", "pensei em nao te bater" "isto custa-me a crer" -> "isto nao custame a crer", "isto nao me custas a crer" "passeia-te pela rua" -> "nao passeiate pela rua", "nao te passeias pela rua"
This is code-golf so shortest submission in bytes, wins! If you liked this challenge, consider upvoting it... And happy golfing!
This is the third challenge of the RGS Golfing Showdown. If you want to participate in the competition, you have 96 hours to submit your eligible answers. Remember there is still 350 reputation in prizes! (See 6 of the rules)
Also, as per section 4 of the rules in the linked meta post, the "restricted languages" for this third challenge are only Pyth, MATL, Husk and CJam so submissions in these languages are not eligible for the final prize. But they can still be posted!!
Otherwise, this is still a regular code-golf challenge, so enjoy!