Optimizer code from Chapter 6 Problem Sets