1

How many ten digits whole number satisfy the following property they have 2 and 5 as digits, and there are no consecutive 2's in the number (ie. any two 2's are separated by at least one 5).

So I know pretty good way of solving this question

Now let $A_n$ represent all number that can be formed following above condition for n digit number

For $A_n$ there are two possibility

Number ending in 2

_ _ _ . . . . (2/5), 5 , 2 (n digit number)

So here last 2 digit are fixed so here all permutations are equal to $A_{(n-2)}$

Number ending in 5

_ _ _ . . . . (2/5), 5 (n digit number)

So here last digit is fixed so all permutations are equal to $A_{n-1}$

Now we have the recursive relation That

$A_n=A_{n-1}+A_{n-2}$(n>2)

Now

a1= 2

a2 = 3

Now we can use the recursive relation to find a10=144

But the thing is if I didn't read it I wasn't able to quite solve it without counting same cases again so is there any other way apart from this method to solve this question..

Guess
  • 151
  • I think the recursive method is best, but if you want another method: Note that your number can't have six $2's$ (why?). So just count those with five $2's$, four $2's$, and so on and sum those up. Each of those counts is a routine Stars and Bars Problem, so you can write the answer as a sum of binomial coefficients. – lulu Mar 27 '24 at 11:07
  • The recursive method shows these are Fibonacci numbers (offset) and that will probably be quicker than any other method – Henry Mar 27 '24 at 11:36
  • @Henry I agree. However, lulu's Stars and Bars method (i.e. Method 1 in my answer) runs a close second when the # of digits $~ = 10,~$ and is (perhaps) better when the # of digits is $~\geq 25.~$ Also, inclusion-exclusion (i.e. Method 2 in my answer), while far inferior to the Stars and Bars method, still permits manual computations (as I construe them) to be avoided. – user2661923 Mar 28 '24 at 07:28

2 Answers2

1

You can analyse and see that the number of 2's cannot exceed 5, as then there will be atleast 1 pair of 2. If you want to explain your problem to a high schooler,you can make a event specific formula.

Say there are n number of 2s.Hence there are 10-n number of 5s. Our favourable arrangement is like this

$$× 5 × 5 × 5 × 5 × 5 × ...5 × $$

where $×$ represents possible spaces where 2 can be placed

The number of empty spaces = 10-n+1

Number of 2's=n

So total number of arrangements = $$\sum_{n=0}^{5}\frac{^{(10-n+1)}P_n}{n!}$$

(n=0 for 5555555555) Dividing by $n!$ because of repitition of 2

My answer from this is coming to 144

Gwen
  • 506
1

I just edited the Inclusion-Exclusion section (i.e. Method 2), to try to make it easier to understand.


Extending the comment of lulu, you know that a satisfying solution will have $~k~$ 2's, where $~k \in \{0,1,2,\cdots,5\}.~$ There are two alternate methods that generalize well, Stars and Bars and inclusion-exclusion.

$\underline{\text{Method 1: Stars and Bars}}$

Hold $~k~$ as a fixed constant.

First, for Stars and Bars theory, see this article and this article.

Consider the following tableau, which assumes $~k = 3,~$ for illustrative purposes:

___2__2___2__

The placement of the $~3~$ 2's creates (k+1 = 4) islands of 5's. Let $~x_1,x_2,x_3,x_4~$ denote the size of these islands. Then the number of satisying placements of exactly $~3~$ 2's is exactly equal to the number of solutions to

  • $x_1 + x_2 + x_3 + x_4 = (10 - k) = 7.$

  • $x_1, \cdots, x_4 \in \Bbb{Z_{\geq 0}}.$

  • $x_2, x_3 \geq 1.$

The idea is that with the end variables $~x_1,x_4~$ ignored, there will be no occurrence of consecutive 2's if and only if each of the other islands is of size $~\geq 1.~$

The standard adjustment here is to set

  • $y_i = x_i - 1 ~: ~i \in \{2,3\}.~$

  • $y_i = x_i ~: ~i \in \{1,4\}.$

So, assuming that $~k = 3,~$ there is a bijection between the set of solutions to the original problem, and the set of solutions to the problem

  • $y_1 + y_2 + \cdots + y_4 = (10 - 3) - (3 - 1) = 11 - (2 \times 3) = 5.$

  • $y_1,\cdots,y_4 \in \Bbb{Z_{\geq 0}}.~$

For general $~k \in \{1,2,\cdots,5\},~$ this conversion translates to the number of solutions to

  • $y_1 + y_2 + \cdots + y_{k+1} = 11 - (2k).$

  • $y_1, y_2, \cdots, y_{k+1} \in \Bbb{Z_{\geq 0}}.$

By Stars and Bars theory, the number of solutions is

$$f(k) = \binom{[11 - 2k] + k}{k} = \binom{11 - k}{k}.$$

Note that if $~k~ = 0,~$ then the number of solutions is $~f(0) = \displaystyle 1 = \binom{11}{0}.$

Therefore, the final computation is

$$\sum_{k=0}^5 f(k) = \sum_{k=0}^5 \binom{11-k}{k}$$

$$= \binom{11}{0} + \binom{10}{1} + \binom{9}{2} + \binom{8}{3} + \binom{7}{4} + \binom{6}{5}$$

$$= 1 + 10 + 36 + 56 + 35 + 6 = 144.$$


$\underline{\text{Method 2: Inclusion-Exclusion}}$

The analysis here will be more complicated than that of Method 1, so I regard this method as somewhat inferior for this particular problem. However, despite the complication, the method will still allow you to avoid manual computation.

First, see this article for an introduction to Inclusion-Exclusion. Then, see this answer for an explanation of and justification for the Inclusion-Exclusion formula.

Following the syntax in the 2nd link in the previous paragraph, let $~S~$ denote the collection of all possible $~10~$ digit numbers, where each digit is an element of $~\{2,5\}.~$ That is, $~S~$ (also) includes those $~10~$ digit numbers that violate the constraint of no consecutive 2's.

For $~p \in \{1,2,3,\cdots,9\},~$ let $~S_p~$ denote the subset of $~S~$ where the 10 digit numbers specifically contain a $~2~$ in digit positions $~p~$ and $~p+1.~$ Note that for each element in the subset $~S_p,~$ there may or may not be a consecutive 2's violation elsewhere in the 10 digit number.

Then, the desired computation is

$$|S| - |S_1 \cup S_2 \cup \cdots \cup S_9|. \tag1 $$

Let $~T_0 = |S| \implies T_0 = 2^{10} = 1024.~$

Let $~\displaystyle T_1 = \sum_{i_1 = 1}^9 |S_{i_1}| \implies T_1 = 9 \times 2^{10 - [2 \times 1]} = 9 \times 2^8 = 2304.~$

For $~r \in \{2,3,\cdots,9\},~$ let $~T_r~$ denote

$\displaystyle \sum_{1 \leq i_1 < i_2 < \cdots < i_r \leq 9} |S_{i_1} \cap S_{i_2} \cap \cdots \cap S_{i_r}|.$

That is, $~T_r~$ denotes the sum of $~\displaystyle \binom{9}{r}~$ terms.

Then, following inclusion-exclusion theory, the computation in (1) above is equivalent to

$$\sum_{r=0}^9 (-1)^r T_r. \tag2 $$

The difficulty in this method is that although symmetrical considerations facilitated the computation of $~T_1,~$ these considerations break down, for $~r > 1.~$


$\underline{\text{Manual Computation of} ~T_2}$

The manual way of computing $~T_2~$ is to recognize that of the $~36~$ terms involved in the computation of $~T_2,~$ you will have:

  • $~|S_{i_1} \cap S_{i_2}| = 2^{10 - 3} = 2^7,$
    if and only if $~i_1 + 1 = i_2,~$ which will occur in exactly $~8~$ of the $~36~$ terms.

  • $~|S_{i_1} \cap S_{i_2}| = 2^{10 - 4} = 2^6,$
    if and only if $~i_1 + 1 < i_2,~$ which must therefore occur in the other $~(36 - 8) = 28~$ terms in the computation of $~T_2.~$

Consequently, $~\displaystyle T_2 = \left[ ~8 \times 2^7 ~\right] + \left[ ~28 \times 2^6 ~\right].~$

The above analysis represents the manual computation of $~T_2.~$ What is needed is an analytical method of obtaining a formula for $~T_r ~: ~r \geq 2.~$


$\underline{\text{Analytical (i.e. non-manual) Computation of} ~T_r ~: ~2 \leq r \leq 9}$

In the previous section, manual consideration was given to the $~\displaystyle \binom{9}{2}~$ terms in the computation of $~T_2,~$ in order to determine how many of these terms had $~7~$ digits unspecified, and how many of these terms had $~6~$ digits unspecified.

This section provides an analytical shortcut to the process, which may be used when computing $~T_r,~$ for any value of $~r \in \{2,3,\cdots,9\}.~$

Suppose, for example that you are computing $~T_5,~$ and consider the specific intersection of $~(P_1 \cap P_2 \cap P_4 \cap P_5 \cap P_9).~$ The following tableau represents this intersection:

 ____i-1=1____i-2=2____i-3=4____i-4=5____i-5=9____

The variables $~i_1, \cdots, i_5~$ are assigned the digit positions that correspond to the violation subsets that they represent. These $~5~$ digit positions create $~(5 + 1)~$ islands.

Let $~x_1, x_2, \cdots, x_6,~$ denote the size of these islands. Then, you have that $~(x_1, \cdots, x_6) = ~(0,0,1,0,3,0).~$ Note that in this example, there are exactly $~2~$ variables from the set $~\{x_2,x_3,x_4,x_5\},~$ that are equal to $~0.~$ Note further that the specific intersection of $~(P_1 \cap P_2 \cap P_4 \cap P_5 \cap P_9)~$ will leave exactly $~[ 10 - (2 \times 5) + 2 ~] = 2 ~$ digit positions unspecified, digit positions $~7~$ and $~8.$

In fact, in any selection of $~5~$ sets to be intersected, from the collection of sets $~\{P_1, \cdots, P_9\},~$ if the intersection causes exactly $~w~$ of the variables $~x_2, \cdots, x_5~$ to equal $~0,~$ then the number of digit positions left unspecified will be $~[ ~10 - (2 \times 5) + w ~].$

This is because each of the variables $~x_2, \cdots, x_5~$ that equals $~0,~$ represents a compressed intersection, that involved only $~3~$ digit positions, rather than $~4~$ digit positions.

This analysis generalizes to the characterization of any term in the computation of $~T_r,~$ for any value of $~r \in \{2,3,\cdots,9\}.~$ That is, if among the variables $~x_2,\cdots, x_r,~$ exactly $~w~$ of them are equal to $~0,~$ then the number of unspecified digit positions will equal $~[ ~10 - (2 \times r) + w ~].$

Therefore, you have that

$$T_r = \sum_{\text{min value for} ~w}^{\text{max value for} ~w} \\ \left[ ~\text{# of intersections that yield} ~w ~\text{zeroes} ~\right] ~\times 2^{[ ~10 - (2 \times r) + w ~]}$$

For any value of $~r,~$ since there are $~(r-1)~$ variables represented by $~x_2, x_3, \cdots, x_r,~$ the variable $~w~$ must be some element in $~\{0,1,2,\cdots, (r-1) \}.$ So, $~(r - 1)~$ will always be the maximum allowable value for $~w.~$ Stars and Bars analysis will be used to derive the general formulas, in terms of $~r,~$ for the minimum allowable value of $~w,~$ and the $~\# ~$ of intersections that yield $~w~$ zeroes among the variables $~x_2, x_3, \cdots, x_r.$


Notice that the total size of the $~(r+1)~$ islands combined, plus the number of intersections, $~r,~$ must equal $~9.$ Therefore, you will always have that $~x_1 + x_2 + \cdots + x_r + x_{r+1} = (9-r).$

Let $~r~$ be some fixed element in $~\{2,3,\cdots,9\},~$ and assume that among the variables $~x_2, \cdots, x_r,~$ exactly $~w~$ of these variables are equal to $~0.~$

Then, in the computation of $~T_r,~$ the $~\#~$ of intersections that yield exactly $~w~$ zeroes will exactly equal the number of solutions to

  • $x_1 + x_2 + \cdots + x_{r+1} = 9 - r.~$

  • $x_1, x_2, \cdots, x_{r+1} \in \Bbb{Z_{\geq 0}}.$

  • Exactly $~w~$ of the variables $~x_2~$ through $~x_r~$ inclusive, are equal to $~0.~$

To enumerate the above problem, the first thing to notice is that there are $~\displaystyle \binom{r-1}{w}~$ ways of selecting the $~w~$ variables from the set $~\{x_2,x_3,\cdots,x_r\}~$ that will equal $~0.~$

So, reserve the factor $~\displaystyle \binom{r-1}{w},~$ and then assume, without loss of generality, that the first $~w~$ variables from the set $~{x_2,x_3,\cdots,x_r}~$ represent the variables that are set to the value $~0.~$

Then, exclude these $~w~$ variables from consideration, and re-index the remaining $~(r+1 - w)~$ variables, in ascending order, adopting the variable names $~z_1~$ through $~z_{(r+1 - w)}.~$

Then, the above problem bijects to enumerating the number of solutions to

  • $~z_1 + z_2 + \cdots + z_{(r+1 - w)} = (9 - r).~$

  • $~z_1, z_2, \cdots, z_{(r+1 - w)} \in \Bbb{Z_{\geq 0}}.$

  • For $~w < (r-1), ~z_2, \cdots, z_{r-w}~$ are each $~> 0.~$

At this point, you can employ the same standard method that was employed in Method 1.

That is, adopt the change of variables $~y_i = z_i~$ for $~i \in \{1,(r+1-w)\},~$ and for each variable $~z_i~$ such that $~2 \leq i \leq (r-w)~$ (if any), set $~y_i = z_i - 1.~$

So, the above enumeration problem bijects to enumerating

  • $~y_1 + y_2 + \cdots + y_{(r+1 - w)} = (9 - r) - [(r-w) - 1] = 10 + w - 2r.~$

  • $~y_1, y_2, \cdots, y_{(r+1 - w)} \in \Bbb{Z_{\geq 0}}.$

Since each of the variables $~y_1, \cdots, y_{(r+1 - w)}~$ is a non-negative integer, the minimum allowable value for the expression $~(10 + w - 2r)~$ is $~0.~$ Therefore, $~w~$ must be $~\geq (2r-10).~$ Therefore, the lower bound for $~w~$ is $~\max[ ~(2r - 10), ~0 ~].$

By Stars and Bars theory, for a fixed value of $~r,~$ and a specific value of $~w~$ that is between its lower and upper bounds, the enumeration of the number of solutions, [ignoring the reserved factor of $~\displaystyle \binom{r-1}{w} ~$] is

$$\binom{[10 + w - 2r] + [r - w]}{r - w} = \binom{10 - r}{r - w}.$$

Therefore, for each $~r \in \{2,3,\cdots,9\},~$

$$T_r = \sum_{w = \max\left[ ~(2r - 10), ~0 ~\right]}^{r-1} \left[ ~\binom{r-1}{w} \times ~\binom{10 - r}{r - w} \times 2^{(10 - 2r + w)} ~\right]. \tag3 $$


$~\underline{\text{Final Computation For Method 2}}$

The number of $~10~$ digit numbers, where each digit is an element in $~\{2,5\}~$ and there is no occurrence of any consecutive 2's is

$$\sum_{r = 0}^9 (-1)^r T_r,$$

where:

$$T_0 = 2^{10} = 1024.$$

$$T_1 = 9 \times 2^8 = 2304.$$

Then, employing the formula in (3) above:

$$T_2 = \sum_{w = 0}^1 \left[ ~\binom{1}{w} \times \binom{8}{2 - w} \times 2^{6 + w} ~\right]$$

$$ = \left[ ~1 \times \binom{8}{2} \times 2^6 ~\right] + \left[ ~1 \times \binom{8}{1} \times 2^7 ~\right] = 2816.$$


$$T_3 = \sum_{w = 0}^2 \left[ ~\binom{2}{w} \times \binom{7}{3 - w} \times 2^{4 + w} ~\right]$$

$$ = \left[ ~1 \times \binom{7}{3} \times 2^4 ~\right] + \left[ ~2 \times \binom{7}{2} \times 2^5 ~\right] + \left[ ~1 \times \binom{7}{1} \times 2^6 ~\right]= 2352.$$


$$T_4 = \sum_{w = 0}^3 \left[ ~\binom{3}{w} \times \binom{6}{4 - w} \times 2^{2 + w} ~\right]$$

$$ = \left[ ~1 \times \binom{6}{4} \times 2^2 ~\right] + \left[ ~3 \times \binom{6}{3} \times 2^3 ~\right] + \left[ ~3 \times \binom{6}{2} \times 2^4 ~\right] $$

$$+ \left[ ~1 \times \binom{6}{1} \times 2^5 ~\right]= 1452.$$


$$T_5 = \sum_{w = 0}^4 \left[ ~\binom{4}{w} \times \binom{5}{5 - w} \times 2^w ~\right]$$

$$ = \left[ ~1 \times \binom{5}{5} \times 2^0 ~\right] + \left[ ~4 \times \binom{5}{4} \times 2^1 ~\right] + \left[ ~6 \times \binom{5}{3} \times 2^2 ~\right]$$ $$+ \left[ ~4 \times \binom{5}{2} \times 2^3 ~\right] + \left[ ~1 \times \binom{5}{1} \times 2^4 ~\right]= 681.$$


$$T_6 = \sum_{w = 2}^5 \left[ ~\binom{5}{w} \times \binom{4}{6 - w} \times 2^{w - 2} ~\right]$$

$$ = \left[ ~10 \times \binom{4}{4} \times 2^0 ~\right] + \left[ ~10 \times \binom{4}{3} \times 2^1 ~\right] + \left[ ~5 \times \binom{4}{2} \times 2^2 ~\right] $$ $$+ \left[ 1 \times ~\binom{4}{1} \times 2^3 ~\right] = 242.$$


$$T_7 = \sum_{w = 4}^6 \left[ ~\binom{6}{w} \times \binom{3}{7 - w} \times 2^{w - 4} ~\right]$$

$$ = \left[ ~15 \times \binom{3}{3} \times 2^0 ~\right] + \left[ ~6 \times \binom{3}{2} \times 2^1 ~\right] + \left[ ~1 \times \binom{3}{1} \times 2^2 ~\right] = 63.$$


$$T_8 = \sum_{w = 6}^7 \left[ ~\binom{7}{w} \times \binom{2}{8 - w} \times 2^{w - 6} ~\right]$$

$$ = \left[ ~7 \times \binom{2}{2} \times 2^0 ~\right] + \left[ ~1 \times \binom{2}{1} \times 2^1 ~\right] = 11.$$


$$T_9 = \sum_{w = 8}^8 \left[ ~\binom{8}{w} \times \binom{1}{9 - w} \times 2^{w - 8} ~\right] = 1.$$


So,

$$\sum_{i = 0}^9 (-1)^r T_r$$

$$= (T_0 + T_2 + T_4 + T_6 + T_8) - (T_1 + T_3 + T_5 + T_7 + T_9)$$

$$=(1024 + 2816 + 1452 + 242 + 11) - (2304 + 2352 + 681 + 63 + 1)$$

$$= 144.$$

user2661923
  • 35,619
  • 3
  • 17
  • 39
  • I really appreciate your answer Steve, you always elaborated in each answer. I think it is because of the discipline of old generation (+1) – Not a Salmon Fish Mar 28 '24 at 09:11