Problem with gerund and infinitive [closed]

Solution 1:

In a comment John Lawler wrote:

Why do you assume only one can be correct? That's usually the wrong way to bet, unless there's an ESL textbook in the woodpile. Both are in fact grammatical and colloquial, and both mean the same thing. The infinitive to reverse a string will be interpreted as a purpose infinitive, and the for with the gerund is the normal purpose marker. As usual, there is a choice, and people will vary, often from minute to minute, in which one they use in which context.