Painfully long implementation of problem 60.