CodeEval: Detecting Cycles (completed solution)