solved turn algorithm