APPENDIX A: SOLUTION ALGORITHM