In this question I gave a good answer, and the OP was happy with it.
But then he asked me to remove the code from my post, since his instructor did a search for plagiarism. Presumably he was worried that my code would be found, compared to the project and discovered that it was very close to the same.
Given my understanding of the purpose of Stack Overflow, I declined to do so (with an explanation) and ended up changing my variable names (effectively obfuscating my code slightly) to try and help him out without compromising the answer. The discussion of this can be found in the comments.
What is the correct response in this situation? I don't want to cause trouble for the OP (who had clearly put forth some effort of his own) but I also don't want to ruin my answer, or act unethically.