puzzle solved

iterative version