- #126

etotheipi

12. Given a positive integer in decimal representation without zeros. We build a new integer by concatenation of the number of even digits, the number of odd digits, and the number of all digits (the sum of the former two). Then we proceed with that number.

Determine whether this algorithm always comes to a halt. What is or should be the criterion to stop?

I don't really know if this is what you're after, but for any given integer with 4 or more digits there will be either at least 2 even digits or at least 2 odd digits, and the next pass of the algorithm will always reduce the length of that string by at least one digit. You can just keep doing this until you get down to 3 digits, which are either

##\{\text{even}, \text{even}, \text{even}\} \implies 303 \implies 123##

##\{\text{even}, \text{even}, \text{odd}\} \implies 213 \implies 123##

##\{\text{even}, \text{odd}, \text{odd}\} \implies 123##

##\{\text{odd}, \text{odd}, \text{odd}\} \implies 033 \implies 123##

And I guess if you start off with an integer with 1 or 2 digits, the next pass gives you a 3 digit number and we're back to the above.

Last edited by a moderator: