Some time ago I posted a series of two questions:

(The second question is built on code in the first one, it is not a revised question of the first.)

Now I noticed that the code in the first question has a flaw. It works correctly for generating all permutations of mutually different elements, but leads to an infinite loop if two or more elements are equal (e.g. [1, 1, 2]).

The reason is that I did not translate Knuth's algorithm correctly into Swift code, and some > should be >=. So that is easy to fix.

My question is how to fix it without violating the Code Review guidelines. I think this is different from this question because that "problem" is not addressed in the existing answers, so this is not about incorporating feedback from the answers into the question.

For the first question I see the following options:

  • Edit the question: That is generally frowned upon because it might invalidate existing answers. In my case, the answer does not cover that aspect, but it is based on the code in the question and therefore the suggested improved code has the same flaw.

  • Edit the question and the answer: I could fix the problem in the question and make the corresponding changes in the answer.

  • Post a self-answer: I could post another answer myself, posting an improved version which works correctly for equal elements.

  • Or is my question off-topic because of "broken code"? But that would require me to edit it...

For the second question I think a question edit should be OK, because that aspect is not addressed or used in the answer at all.


1 Answer 1


Posting a self-answer is the best option in this case. You were not aware that there was any flaw when you posted your code for review, but you are aware of it now so therefore you found an issue in your own code.

Closing a question as off-topic for "broken code" is only meant for when the OP asks about how to fix that issue, or is aware of the issue (or should be aware of the issue if they would have tested it just a little bit). In your case it can happen for some specific inputs, but overall your code still works.

Editing another person's answer is not ideal. It is okay to edit grammar, language and formatting and minor issues, but editing their code is... sometimes okay and sometimes less okay (I'm not even gonna try to draw the line for this).

For the second question that was built on your first, go ahead and edit it.

  • \$\begingroup\$ Will do that – thank you for the clarification. \$\endgroup\$
    – Martin R
    Oct 22, 2017 at 10:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .