I would like to reuse code I provided as answer in one question for testing code in another question.

As example in one question, I ask students to implement Newton's method so solve an algebraic equation. In another question (perhaps other quiz) I ask them to implement the Backward Euler method which requires a working Newton method. So to test it I need to use (in the 'question extra' field for example) my implementation of Newton's method. That leads to code duplication and if I decide to change the prototype for the Newton method for example then I would need to change that in many questions. Is it possible to somehow reduce this code duplication?