The point of any homework exercise is two-fold. First, learn any new techniques or methods related to the coursework. Second, practice those techniques!
If you have previously solved the same problem before, you've already completed the first point. Great! Now for the second point: it still matters. See this as an opportunity to master the material even further.
Now, I wouldn't say you can't refer to your own code that you have the rights to as a reference. Only use it as such though. Map out a new approach without referring to your old code. Code the challenging aspects again. Then, only after you've solved the essential aspects of the assignment, refer to whatever resources you have at your disposal. Go ahead and make adjustments, but at that point it's probably unnecessary to copy and paste anything, you'll only need to tweak your new code. You might improve on your original material!
Now, there is a rule in programming: Don't reinvent the wheel. I would say that takes a backseat when education is involved. You are reinventing all the time, that's the point of learning. If it is a lot of work and you really want to re-use some code, make sure it's OK with your professor, and explain what would be re-used.