Reverse a few words

Hi all,

I would like to reverse a few words and print them out. For example:

olleH, woh era uoy
Hello, how are you

What’s the best way to accomplish this?

How define which ones should be reversed?

They all should be reversed. The word should be… not the sentence. Almost, like letter shifting.

Have you tried anything in Go to achieve this? We could write this code for you but you learn more if you try to solve the problem first. We will be glad to help you with any problems if we see that you have tried.

Some hints:

  • think about what could be a word boundary
  • split the input on word boundaries to get words
  • reverse each word
  • output the reversed word followed by the boundary

This is not the easiest problem but doably. Try!


ahh, right. Your words about a few confused me :slight_smile:

You can easily achieve it with methods from strings package.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.