Instead of using mathematical induction in Solution 1, one can also show that and by construction.
To show that , we can construct a one-to-one mapping from strings of length to strings of length . The mapping is defined as below by extending the two digits in the middle of length to the three digits in the middle of length .
“00” -> “000” (e.g. 1089001089 -> 10890001089)
“08” -> “098” (e.g. 1089 -> 10989)
“91” -> “901” (e.g. 10891089 -> 108901089)
“99” -> “999” (e.g. 109989 -> 1099989)
To show that , we construct strings of length from strings of length and strings of length using the following rules:
First if the input string is in the form , regardless of the length , we will generate an output string of length in the form . Note that here we have a 2-to-1 mapping.
If the input string is of length and is not in the form , then we construct an output string of length based on the two digits in the middle of length :
“99” -> “9999” (e.g. 10999989 -> 1099999989)
“00” -> “0000” (e.g. 1089001089 -> 108900001089)
“08” -> “0998” (e.g. 108910891089 -> 10891099891089)
“91” -> “9001” (e.g. 10891089 -> 1089001089)
Note that the middle two digits are either 99 or 00 in this case.
If the input string is of length and is not in the form , then we construct an output string of length based on the two digits in the middle of length :
“99” -> “989109” (e.g. 10999989 -> 109989109989)
“00” -> “010890” (e.g. 1089001089 -> 10890108901089)
“08” -> “089108” (e.g. 108910891089 -> 1089108910891089)
“91” -> “910891” (e.g. 10891089 -> 108910891089)
Note that the middle two digits are either 91 or 08 in this case.
Finally we do a special handling for the unique input string of length and in the form , there is a corresponding unique output string of length and in the form . Note that this unique string CANNOT be generated from any string of length using the rules above (because no additional 1 is added).
This additional 1-to-2 mapping compensates the 2-to-1 mapping of , Therefore we have