(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)

  1. Look for the only hyphen in the input sentence (the hyphen that we are unsure about), between two words, like so: verb-pronoun
  2. Output the two following modified sentences:
    • in the place of the verb-pronoun, use "nao" verbpronoun, i.e. prepend "nao" and drop the hyphen;
    • in the place of the verb-pronoun, use "nao" pronoun verbs where verbs is the verb (with an extra "s" if the verb ended in a vowel "aeiou").

Worked examples

Let "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:

  1. "sei que nao apanhaste um susto" [~I know you were not scared]
  2. "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:

  1. "nao dame um upvote" [~give me an upvote not]
  2. "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 [a-z \-].

Test cases

"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 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 challenge, so enjoy!

  • 8
    \$\begingroup\$ Thank you for sticking to ASCII :-) \$\endgroup\$
    – Luis Mendo
    Mar 3 '20 at 8:17
  • \$\begingroup\$ We don't need to capitalize the first word of the output? \$\endgroup\$ Mar 3 '20 at 8:28
  • \$\begingroup\$ @MitchellSpector not really, why? But you can do it, for extra imaginary internet style points. \$\endgroup\$
    – RGS
    Mar 3 '20 at 8:38
  • \$\begingroup\$ No real reason, except that the sentences look strange not starting with a lower-case letter. (But the input sentences are all lower-case anyway, so I won't worry about it.) It might have been interesting for both the input and the output sentences to have to start with a capital letter (sometimes "Nao" is the first word of the output sentence, and sometimes it's not). \$\endgroup\$ Mar 3 '20 at 8:40
  • 4
    \$\begingroup\$ @MitchellSpector thanks for your feedback. That would've made for a nice subtlety, but maybe also steer the focus a bit from the core challenge, which was to use the "rule"... That is why I tried to make things as simple as possible in terms of input characters and etc :) \$\endgroup\$
    – RGS
    Mar 3 '20 at 8:51

27 Answers 27


Python 3, 112 bytes


Try it online!

  • 5
    \$\begingroup\$ This is some voodoo python right here \$\endgroup\$
    – Cruncher
    Mar 4 '20 at 14:43

Python 3.8, 167 \$\cdots\$ 143 142 bytes

Saved a byte thanks to Kevin Cruijssen!!!

lambda p:((n:=(g:=re.match(r'(.*)\b(\w+)-(\w+)(.*)',p).group)(1)+'nao ')+(v:=g(2))+g(3)+g(4),n+g(3)+' '+v+'s'*(v[-1]in'aeiou')+g(4))
import re

Try it online!

Inputs a string and returns a tuple of two strings.

  • 2
    \$\begingroup\$ Gosto do teste em português! \$\endgroup\$ Mar 3 '20 at 12:17
  • 1
    \$\begingroup\$ @MitchellSpector Muito obrigado! :-) \$\endgroup\$
    – Noodle9
    Mar 3 '20 at 12:21
  • 1
    \$\begingroup\$ @KevinCruijssen Figured out a way to golf that: use the entire string + 's' times a test for the last letter in 'aeiou' instead of the regex sub. Thanks for drawing my attention to it! :-) \$\endgroup\$
    – Noodle9
    Mar 3 '20 at 15:36
  • 1
    \$\begingroup\$ @Noodle9 Ah, nice. Glad I could help. :) In that case 1 more byte can be saved with (t:=g(2)) and replacing the other two g(2) with t. Cool to see Python finally has inline variable assignments with (variable:=...) in v3.8! \$\endgroup\$ Mar 3 '20 at 15:40
  • 1
    \$\begingroup\$ @RGS (facepalm) kinda had a dreadful feeling this would be the outcome... \$\endgroup\$
    – Noodle9
    Mar 3 '20 at 16:11

05AB1E, 57 55 53 51 41 40 39 38 bytes

-3 bytes thanks to @KevinCruijssen

-1 byte thanks to @Grimmy

#ʒa_}н©¡D®'-¡Âðý¤žMså's×«sJ‚vy"nao ÿ"ý

Try it online!


#                                           - split input on spaces
 ʒ'-¢}н©                                    - get the hyphenated word
        ¡D                                  - split the input on this word (removing it)          
          ®'-¡                              - split the hyphenated word into its two parts
              Âðý                           - Swap and join with space 
                                            - (e.g. custa-me -> me custa)  
                 ¤žMså's×«                  - if the last char is a vowel add an 's' 
                            sJ              - swap and join the other hyphenated word
                                            - (e.g. custa-me -> custame)
                              ‚             - put these in an array so ["custame","me custa"]
                               vy"nao ÿ"    - for each of these add nao in front
                                        ý   - then join the split input with them


Regex would be a fine thing, a fine thing indeed


V (vim),  38  37 bytes

My first ever V answer I believe ...props to the inventor, James A.K.A. DJMcMayhem!

f-dbeá pí-

Try it online!


ÄÎf-binao <CR>ó¨[aeiou]©-/±s-<CR>f-dbeá pí- | implicit read from STDIN
Ä                                           | copy line, paste below
 Î        <CR>                              | for all lines:
  f-                                        |   find "-"
    b                                       |   back one word
     i                                      |   enter insert mode
      naoS                                  |   "nao "
                                            |   (<CR>: implicit exit from insert mode)
              ó          /   <CR>           | single substitution on line:
                                            |    pattern.../:
               ¨       ©                    |      group (1):
                [     ]                     |        any of:
                 aeiou                      |          "aeiou"
                        -                   |      + "-"
                                            |    /...replacement:
                          ±                 |      group (1)
                           s-               |      + "s-"
                                 f-         | find "-"
                                   db       | cut back a word
                                     e      | move to end of word
                                      áS    | insert a space character
                                        p   | paste
                                         í  | single substitution on every line:
                                            |   pattern.../:
                                          - |     "-"
                                            |   /...replacement: (implicit)
                                            |     ""
                                            | implicit print to STDOUT

Retina, 47 bytes

nao $1$3$"nao $3 $1$#2*s

Try it online!

The verb consists of some characters \w*? and an optional vowel ([aeiou])?. The pronoun is just some characters \w+ after the hyphen.

VERB-PRONOUN gets replaced by nao VERBPRONOUN (nao $1$3), POST_MATCH NEWLINE PRE_MATCH ($"), nao PRONOUN VERB (nao $3 $1) and, if ([aeiou])? had a match, a trailing s ($#2*s).


Java 8, 107 121 119 107 bytes

s->s.replaceAll("(.*?)(\\w+)-(\\w+)(.*)","$1nao $2$3$4;$1nao $3 $2"+(s.matches(".*[aeiou]-.*")?"s$4":"$4"))

+14 bytes for a bugfix (thanks to @ovs for mentioning it)
-12 bytes thanks to @Arnauld. Now we're back to the initial -bugged- byte-count again. xD

Outputs with ; delimiter between the two sentences.

Try it online.


s->               // Method with String as both parameter and return-type
  s.replaceAll(   //  Replace in the input-String:
                  //   This regex match
                  //   With this replacement,
     +(           //   which is appended with:
                  //    If the input-String matches this regex fully:
         "s$4"    //     Append "s$4" to the replacement
        :         //    Else:
         "$4"))   //     Append "$4" to the replacement instead

Regex explanation:

(.*?)(\\w+)-(\\w+)(.*)        # MATCH:
(   )                         #  Capture group 1:
 .*                           #   Any amount of (optional) leading characters
   ?                          #   Which are optional (to lower their priority in comparison
                              #                       to the next groups)
     (   )                    #  Followed by capture group 2:
      \w+                     #   Any amount of alphanumeric characters
          -                   #  Followed by a literal "-"
            (   )             #  Followed by capture group 3:
             \w+              #   Any amount of alphanumeric characters
                 (  )         #  Followed by capture group 4:
                  .*          #   Any amount of (optional) leading characters
$1nao $2$3$4;$1nao $3 $2s$4   # REPLACEMENT:
$1                            #  Content of capture group 1
  nao                         #  Followed by a literal "nao "
      $2$3$4                  #  Followed by the contents of capture groups 2, 3, and 4
            ;                 #  Followed by a literal ";" as separator
             $1               #  Followed by the content of capture group 1
               nao            #  and a literal "nao " again
                   $3         #  Followed by the content of capture group 3
                              #  Followed by a literal " "
                      $2      #  Followed by the content of capture groups 2
                        s     #  Followed by a literal "s", iff the match below is truthy
                         $4   #  Followed by the content of capture group 4

 .*[aeiou]-.*                 # Check if the string matches this string:
^            $                #  It tries to match the ENTIRE string (which is done
                              #  implicitly by the `String#matches` method)
 .*                           #  Any amount of leading characters
   [aeiou]                    #  Followed by a single vowel character
          -                   #  Followed by a literal "-"
           .*                 #  Followed by any amount of trailing characters


Bash + Core utilities, 85 84 82 75 72 71 bytes

p=";s/(\w*)-(\w*)/nao "
sed -E "h$p\1\2/p;g;s/([aeiou])-/\1s-/$p\2 \1/"

Try it online!

1 byte shorter, thanks to @user41805: Using the p flag in the first substitution permits one ; to be omitted.

Down to 72 bytes now: Added the -E option to sed for extended regexes, eliminating the need to escape the various parentheses.

Thanks to @Neil for shaving off 7 bytes, leaving 75 bytes!

Improvements: (1) Eliminating the \< and \>, which are unnecessary because of sed's greedy regex matching. (2) Appending the s (if needed) before reversing the order of the verb and the pronoun, which eliminates the need for adding the identifying % character and later deleting it.

Input is on stdin, and output is on stdout.

How it works:

  1. The value of p is essentially the beginning of a sed substitute command that finds the verb-pronoun combination and replaces it with a string starting with nao (the command is incomplete -- it will need to filled in with the rest of the desired substitute and then a final /). At the very beginning of p, preceding the command, is a ;, which will separate it from the previous sed command. (p will be used twice -- once for each output string.)

  2. The sed command starts by reading one line of input (one Portuguese sentence) into sed's pattern space. (This is automatic with sed.)

  3. The first sed command, h, copies the pattern space into the hold space, so we've saved a copy of the input string for use later to compute the 2nd output.

  4. Next comes $p\1\2/, which expands to ;s/(\w*)-(\w*)/nao \1\2. The command after the sed command separator (;) inserts the nao in the right place and removes the -.

  5. The sed command p prints the pattern space. That's the first output string.

  6. The sed command g copies the hold space to the pattern space. Now the pattern space contains the original input string again.

  7. The next sed command, s/([aeiou])-/\1s-/ appends an s to the verb if the verb ends with a vowel.

  8. Next comes $p\2 \1, which expands to a sed command that inserts nao, reverses the order of the verb and the pronoun, and replaces the hyphen with a space.

  9. Finally, the pattern space is printed (no command needed -- by default, sed does this automatically at the end). That's the second output string.

Note that the sed command is run on each input line separately, so you can process as many sentences as you want in a single run of the program.

  • \$\begingroup\$ This seems to work for 75 bytes somehow? \$\endgroup\$
    – Neil
    Mar 3 '20 at 22:55
  • \$\begingroup\$ @Neil -- That's clever; it looks like you're taking care of appending the s (if needed) before rearranging. Thank you! \$\endgroup\$ Mar 4 '20 at 0:11
  • \$\begingroup\$ Since the input is guaranteed to have a -, you can pass p as a flag to the first s command to print after substitution, thus saving a byte. \$\endgroup\$
    – user41805
    Mar 5 '20 at 18:15
  • \$\begingroup\$ @user41805 Thank you! \$\endgroup\$ Mar 5 '20 at 19:09

SNOBOL4 (CSNOBOL4), 145 bytes

	INPUT ARB . L W . V '-' W . P REM . R
	L =L 'nao '
	V ANY('aeiou') . E RPOS(0) =E 's'
	OUTPUT =L P ' ' V R

Try it online!


	W =SPAN(&LCASE)				;* Alias for SPAN(&LCASE), which matches at least one character from &LCASE,
						;* the lowercase letters, so I guess it's [a-z]+
	INPUT ARB . L W . V '-' W . P REM . R	;* match the input against the following pattern:
		;* ARBitrary match, save as L, the Left part of the sentence
		;* SPAN(&LCASE) save as V, the verb
		;* hyphen
		;* SPAN(&LCASE) save as P, the pronoun
		;* REMainder of the match, save as R, the Right part of the sentence
	L =L 'nao '				;* concatenate 'nao ' to the end of L
	OUTPUT =L V P R				;* print L V P R
	V ANY('aeiou') . E RPOS(0) =E 's'	;* if V ends (RPOS(0)) in aeiou, add S to the end
	OUTPUT =L P ' ' V R			;* and output the new sentence.

Excel, 311 Bytes

B2 <- Input
B3 =LEN(B2)
B4 nao <- Required trailing space
B5 aeiou
B6  <- Cell contains a single space
C3 -
C4 '<- Single results in empty (text formatted) cell
C5 :
D2 =TEXTJOIN(B6,,IF(ISERR(SEARCH(C3,D3#:C3)),D3#:C3,D4#:D5#:C5))<- Output
D5 =D6#&IF(ISERR(SEARCH(RIGHT(D6#,1),B5)),"","s")
D6 =B4&RIGHT(D3#,LEN(D3#)-D7#)&B6&LEFT(D3#,D7#-1)

This answer would be so much shorter if SUBSTITUTE was renamed to SUBS (Microsoft pls fix)

Sample Image

sample image

  • 3
    \$\begingroup\$ I like the "Microsoft pls fix" as if it were a bug or something ! \$\endgroup\$
    – RGS
    Mar 3 '20 at 17:39
  • 1
    \$\begingroup\$ Yeah, it's not like people are using Excel for SUBStractions, so there can't be any confusion. \$\endgroup\$
    – Cœur
    Mar 5 '20 at 16:04

Jelly, 37 bytes

ṚKÇ,ṭ€“nao ”

Try it online!

A full program that takes a list of words and prints a the output separated by newlines.


Japt, 41 bytes

2ÆË=q-)ÊÉ?X?DÔ¸r"%v$""$&s":Dq)i"nao ":D}S

Try it

Alternative, with output being list of words:

Japt -R, 40 bytes

2ÆË=q-)ÊÉ?X?DÔ¸r"%v$"_+'s:Dq)i"nao " ¸:D

Try it

  • \$\begingroup\$ Nicely golfed but I do question the output format. \$\endgroup\$
    – Shaggy
    Mar 6 '20 at 23:57
  • \$\begingroup\$ This output format isn't acceptable for this challenge, sorry. \$\endgroup\$
    – RGS
    Mar 7 '20 at 8:12
  • \$\begingroup\$ I see in your answer history that the 41 byte solution still had an acceptable format. You are welcome to rollback to that one, if you please. \$\endgroup\$
    – RGS
    Mar 7 '20 at 8:26
  • \$\begingroup\$ @RGS I have rolled back to my old answer. However, I have attached another answer which actually outputs a list of words \$\endgroup\$
    – Gymhgy
    Mar 7 '20 at 20:40
  • \$\begingroup\$ @RGS May I ask why this answer was marked as non-compteting in the scoreboard? \$\endgroup\$
    – Gymhgy
    Mar 11 '20 at 23:12

JavaScript (ES6),  81 80  79 bytes

Returns a single string with the two sentences separated by a /.

s=>s.replace(/(\w+)-(\w+)/,"nao $1$2$'/$`nao $2 $"+(/[aeiou]-/.test(s)?'1s':1))

Try it online!


s =>                       // s = input string
  s.replace(               // replace in s
    /(\w+)-(\w+)/,         //   (verb)-(pronoun) with
    "nao $1$2$'" +         //   1st sentence:
                           //     implicit left context
                           //     + "nao verbPronoun"
                           //     + explicit right context ($')
    "/" +                  //   append our separator
    "$`nao $2 $" + (       //   2nd sentence:
                           //     explicit left context ($`)
                           //     + "nao pronoun verb",
                           //     where 'verb' is built as follows:
      /[aeiou]-/.test(s) ? //       if there's a vowel before the '-' in s,
                           //       i.e. if the verb ends with a vowel:
        '1s'               //         append '1s' (which gives "$1s")
      :                    //       else:
        1                  //         just append '1' (which gives "$1")
    )                      //     + implicit right context
  )                        // end of replace()

Ruby, 94 87 83 81 bytes

->s{['\1\2','\2 \1'+"#{s=~/[aeiou]-/&&?s}"].map{|r|s.sub /(\w+)-(\w+)/,'nao '+r}}

Try it online!


Julia 1.0, 121 118 116 bytes

s->((x=(r=match(r"(.*)\b(\w+)-(\w+)(.*)",s))[1]*"nao ")*(y=r[2])*r[3]*r[4],x*r[3]*" "*y*"s"^(y[end]∈"aeiou")*r[4])

Try it online!

  • \$\begingroup\$ Your TIO link produces no output at all. Is this supposed to happen? \$\endgroup\$
    – RGS
    Mar 3 '20 at 15:58
  • 1
    \$\begingroup\$ @RGS if all the tests pass it produces no output, if any of them fail it throws an error \$\endgroup\$
    – wilkben
    Mar 3 '20 at 16:06

Perl 5 -p, 67 58 bytes

s%(\w*)-(\w+)%"nao $1$2$'
$`nao $2 $1"=~s/[aeiou]\K$/s/r%e

Try it online!


Japt, 42 bytes

2Ær7î"%w+-" _X?Zq- Ô¸r"%v$"_+'s:Zr-)i"nao 

Try it

  • \$\begingroup\$ Thanks for your submission. What is the -R in the end of the input? \$\endgroup\$
    – RGS
    Mar 4 '20 at 8:20
  • \$\begingroup\$ @RGS It's actually a flag; I don't know why he put it in the input box, but you can move it to the flag box and it works fine. \$\endgroup\$
    – Neil
    Mar 4 '20 at 11:42
  • \$\begingroup\$ @Neil, Japt can takes flags in its input field by default but I added a dedicated field to my interpreter. When they're not relevant to my solution, though, I generally place them in the input field. In this instance, the -R flag is just formatting the output for easier reading. \$\endgroup\$
    – Shaggy
    Mar 4 '20 at 13:17
  • \$\begingroup\$ Had @RGS required that output be a newline separated string, on the other hand ... \$\endgroup\$
    – Shaggy
    Mar 4 '20 at 13:28

Python 3, 111 bytes

for c in[v+p,p+' '+v+'s'*(v[-1]in'aeiou')]:print(*a,"nao",c,*b)

Try it online!

Method of taking input thanks to @ovs. I felt that this is a big enough change to warrant its own answer, however.


R, 111 bytes

cat(sub(r<-"(\\w+)-(\\w+)","nao \\1\\2",s<-scan(,"")),1,sub(r,paste0("nao \\2 \\1","s"[grep("[aeiou]-",s)]),s))

Try it online!

I am pretty bad at regexing, so there is probably inspiration for something better to be found in other answers.

Note that scan(,"") splits words on spaces, making it easier to manipulate the strings. In the output, the two sentences are separated by a 1.

More readable :

r <- "(\\w+)-(\\w+)"                       # regex to match the word with a dash
s <- scan(, "")                            # stdin
cat(sub(r, "nao \\1\\2", s),              
                 "s"[grep("[aeiou]-", s)]) # add an s or NULL, depending on whether the letter before the dash is a vowel or not
        , s))

sed 4.2.2 -E, 72 bytes

h;s/(\w*)-(\w*)/nao \1\2/p;g;s/([aeiou])-/\1s-/;s/(\w*)-(\w*)/nao \2 \1/

Port of Mitchell Spector's Bash answer.

Try it online!

  • \$\begingroup\$ It looks like it worked :) why did you only have 15 minutes? \$\endgroup\$
    – RGS
    Mar 6 '20 at 7:13
  • \$\begingroup\$ @RGS The 96-hour limit. \$\endgroup\$
    – S.S. Anne
    Mar 6 '20 at 11:56
  • \$\begingroup\$ You still have almost one full day..! 96 hours is 4 days :) \$\endgroup\$
    – RGS
    Mar 6 '20 at 12:47
  • 1
    \$\begingroup\$ @RGS I don't think I'll try the C++ solution I was thinking of... This challenge is really hard without regex. \$\endgroup\$
    – S.S. Anne
    Mar 6 '20 at 12:54

PHP, 159 bytes

for($t=2;$t--;)echo preg_replace_callback('#(\w+?)([aeiou]?)-(\w+)#',fn($m)=>'nao '.$m[$t*2+1].($t?' ':'').$m[2-$t].$m[3-$t].($t&&$m[3-$t]?'s':''),$argn),"\n";

Try it online!

The array numbering is messy, there's more juice to be squeezed there.


Charcoal, 50 bytes

≔⊟Φ⪪θ №ι-η≔⪪η-ζＥ⟦⪫ζω⁺⪫⮌ζ ×s№aeiou§§ζ⁰±¹⟧⪫⪪θη⁺nao ι

Try it online! Link is to verbose version of code. Explanation:

≔⊟Φ⪪θ №ι-η

Split the input on spaces and extract the word that contains a -.


Split that word on its -.


Join the parts together.


Reverse the parts and join them with a space, then append as many ss as there are vowels in the last letter of the first word.

Ｅ⟦...⟧⪫⪪θη⁺nao ι

Prefix nao to each of the two above values and substitute them for the original word.

  • \$\begingroup\$ Thanks for your submission and explanation. I just explicitly allowed the input string to be a list of words, so you can save a couple of bytes by not doing the splitting by yourself. \$\endgroup\$
    – RGS
    Mar 3 '20 at 23:08
  • 1
    \$\begingroup\$ @RGS Actually it doesn't help because it's easier to replace the hyphenated word this way. \$\endgroup\$
    – Neil
    Mar 4 '20 at 0:11

Pure Bash, 118 117 bytes

v=${a##* }
p=${b%% *}
echo $h $v$p$t,$h $p $v${u:+s}$t

Try it online!

I decided to see what I could do with pure bash (no Unix utilities), and this is what I came up with. It can probably be golfed some more.

Input is passed as an argument.

The output is a comma-separated string containing the two desired results.


Batch, 265 bytes

@echo off
set m=
set n=
for %%w in (%*) do set w=%%w&call:w
if %w:-=%==%w% set m=%m% %w%&set n=%n% %w%&exit/b
set m=%m% nao %w:-=%
set v=%w:-=^&rem %
set n=%n% nao %w:*-=% %v%
for %%v in (a e i o u)do if %n:~-1%==%%v set n=%n%s

Takes input as command-line parameters. Explanation: The main work is done by the :w subroutine, which receives each word in turn passed in a variable so that substitutions can be performed on it. The first substitution is simply deleting the -; if this doesn't change the word then we're not interested in the word and we just concatenate it to the outputs. Otherwise, for the first output, we just add nao and the substituted word. For the second output things get a little more complicated. Although we can substitute all characters up to and including the - with the empty string to give us the pronoun, the verb is a bit tricker. Fortunately due to a quirk of Batch processing we effectively get to exec the result of the substitution, turning the pronoun into a comment. (This behaviour also eats the leading space in the output when we echo it.) It then remains to see whether the verb ended in a vowel and if so suffix an s. Example:

set m= nao dame             `m` becomes ` nao dame`
set v=da^&rem me            `v` becomes `da&rem me`
set n= nao me da&rem me     `n` becomes ` nao me da`,
                            as the `rem me` is now a comment.

GolfScript, 62 bytes

"-"/~2/(:f;:e;" ":s/.)" nao ":w\f\s\e++++\s*\+p~w\f e++++s\++p

Boy do I hate string parsing.

This is nowhere near optimised and can very easily be brought down below 50 bytes, I just don't have the bother right now.


TLDR of the process

Split along the hyphen. Remove the next two letters on the right side. Split the left half by spaces and duplicate it. Shove the "nao" and the two letters where they belong and print.

Try it online!


vi, 48 bytes

yyPf-xbinao ␛bj.:s/\([aeiou]\)-/\1s-/e␍f-r ldbwP

means the Enter key and means the Escape key. Explanation:


Duplicate the input line.


Delete the - on the first line.

binao ␛bj.

Insert the nao on both lines.


Append an s to the vowel if necessary.

f-r l

Change the - to a space.


Swap the verb and pronoun.


T-SQL, 304 bytes

I added some linebreaks to make it readable

SELECT substring(@,q,charindex(y,@+y,q-1)-q)w,len(@)
FROM(SELECT-~charindex('-', @)q,'nao 'f,' 'y,'-'d,'s'p,reverse(' '+@)S)Q)L

Try it online(ungolfed)


Jelly,  41 38 37  36 bytes

“nao ”;

A full program accepting a single argument, a list of words, which prints to STDOUT.

Try it online!


ṚKµe€ØẹṪ”sxṭÑ - Link 1: list of lists of characters, Parts
Ṛ             - reverse
 K            - join with space characters, call this R
  µ           - start a new monadic chain
     Øẹ       - lower-case vowels
    €         - for each character, C, in R:
   e          -   (C) exists in (vowels)?
       Ṫ      - tail (i.e. is the last character a vowel?)
        ”s    - 's' character
          x   - times (i.e. X = ['s'] or [])
           ṭ  - tack (X) to (R)
            Ñ - call the next link (Link 2) as a monad

“nao ”; - Link 2: list, V
“nao ”  - list of characters "nao "
      ; - concatenate ("nao " with V)

ṣ”-⁹Ŀ¹Ḋ?¥þ2K€Y - Main Link: list of lists of characters, words
          2    - literal two
         þ     - outer-product (W in words)*(N in implicit range of 2 = [1,2]) with:
        ¥      -   last two links as a dyad  - i.e. f(W, N):
ṣ              -     split (W) at any:
 ”-            -       hyphen character
       ?       -     if...
      Ḋ        -     ...condition: dequeue (empty is falsey)
    Ŀ          -     ...then: call Link at line number:
   ⁹           -           chain's right argument (N)
     ¹         -     ...else: identity - do nothing
           K€  - join each with space characters
             Y - join with newline characters
               - implicit print

Your Answer

