Codeing exercise for algorithm class