I think you shouldn't have change a thing.
This is actually a problem on the student side, he should have referenced that question in his report in the first place, at with point they cannot accuse him for plagiarism.
If his homework is all about that question, well I think he shouldn't have asked it in the first place.If his homework is all about that question, well I think he shouldn't have asked it in the first place. I put it in the "give a man a fish, he eats for a day; teach a man to fish, he eats for a lifetime" category.
Changing variable name was kind of you, but it is also the first thing everybody does to make it look different, which fails most of the time if his instructor his clever. Although, that could help him not finding your answer, but he may find the question anyway.