My solution for the number game problem on algorithm courses