1

$\text{What is the number of ways to form }24\text{ using }7,2,\text{ and }3,\text{ zero or more times?}$

We can write $24$ as $7a+3b+2c$ . Since $\lfloor\frac{24}{7}\rfloor = 3,$ $\lfloor\frac{24}{3}\rfloor = 8$ and $\lfloor\frac{24}{2}\rfloor = 12$ ,We can say $0 \le a \le 3$ , $0 \le b \le 8$ and $0 \le c \le 12$.Then I put $a = 0,1,2,3$ and I got $11$ ways.

They are

$1. 7*3+ 2*0 +3*1$

$2. 7*2+ 2*5+ 3*0$

$3. 7*2+ 2*2 +3*2$

$4. 7*1 +2*7+ 3*1$

$ 5. 7*1 +2*4 +3*3$

$ 6. 7*1+ 2*1+ 3*5$

$ 7. 7*0+ 2*12 +3*0$

$8. 7*0 +2*9 +3*2$

$9. 7*0+ 2*6+ 3*4$

$10. 7*0 +2*3+ 3*6$

$11. 7*0 +2*0 +3*8$

Is there any efficient way of calculating this kind of problem??

RobPratt
  • 50,938
  • 4
    It is not clear to me how you got $11$, so difficult to tell whether another method is more efficient. One approach would be to use generating functions and look at the coefficient of $x^{24}$ in the expansion of $\frac{1}{(1-x^7)(1-x^3)(1-x^2)}$ – Henry Jun 06 '22 at 12:47
  • In order to use the comment of @Henry to attack similar Math problems, you have to study generating functions, which I personally have never done. I suspect that there is a learning curve to it. Also, there is a separate issue. Typically, the idea behind attacking these problems is to do it manually, without computer assistance. When generating functions are involved, there is a middle ground. That is, one idea is to set up the generating functions, and then have some internet available computer software calculate the corresponding coefficient. – user2661923 Jun 06 '22 at 13:00

2 Answers2

1

As @user2661923 mentioned, we need to use generating functions. Take a look at this question first to get a grasp of the theory. In general, we need to construct a polynomial of sums, where the exponents correspond to the values our variables can take. For example, to calculate the number of non-negative solutions to your problem: $$7x_1 + 3x_2 + 2x_3 = 24$$ with constraints: $$0 \leq x_1 \leq 3$$ $$0 \leq x_2 \leq 8$$ $$0 \leq x_3 \leq 12,$$ we need to observe that this is the same, as the number of non-negative solutions to: $$y_1 + y_2 + y_3 = 24$$ with constraints $$y_1 \in \{0, 7, 14, 21\}$$ $$y_2 \in \{0, 3, \dots, 21, 24\}$$ $$y_3 \in \{0, 2, \dots, 22, 24\}.$$

Therefore, the corresponding generating function is $$ P(y) = (1 + y^7 + y^{14} + y^{21})(1+ y^3+\dots +y^{24})(1+y^2+\dots+y^{24})$$ Let us denote the factors as $p_7, p_3, p_2$ respectively, i.e. $P(y) = p_7 \cdot p_3 \cdot p_2$. Now, the number of the solutions is equal to the coefficient corresponding to $y^{24}$ in the extended form of $P(y)$ - we look at $y^{24}$, because we want our number to sum to $24$. In general, the way to do this is to expand the polynomial and check the coefficient. There are some tricks applicable to selected cases, but nothing that works for all of them. The coefficient corresponding to $y^{24}$ in $P(y)$ is equal to $11$, which confirms your result.

  • This solution may be mathematically correct, but is multiplying 24th-degree polynomials together "efficient"? – Dan Jun 06 '22 at 23:54
  • 2
    @Dan You don't multiply the $24$th-degree polynomials together. Instead, you simply compute the coefficient of the $y^{24}$ term. As NikoWielopolski indicated, often there are are shortcuts. In this problem, there doesn't appear to be any. So, you have two choices: [1] Manually compute the coefficient, which implies that you take virtually the same steps as you would, manually enumerating the original problem, without benefit of generating functions. [2] The other approach is the middle ground that I referred to: you use some internet based software to compute the pertinent coefficient. – user2661923 Jun 07 '22 at 21:54
  • 1
    @Dan In my opinion, the real power of generating functions, which allow the problem to not be pointless is when shortcuts are available. For example, suppose that you were trying to evaluate the coefficient of $y^8$ in the following computation: $$(1 + y)^8 \times (1 + y^4).$$ You know that the coefficients of $y^4$ and $y^8$ in $(1 + y)^8$ are $$\binom{8}{4}, ~\binom{8}{0} ~\text{respectively}.$$ Therefore, the coefficient of $y^8$ is $$\binom{8}{4} + \binom{8}{0}.$$ – user2661923 Jun 07 '22 at 22:05
1

Note that once you've found $a$ and $b$, you can calculate $c$ directly:

$$c = \frac{24-7a-3b}{2}$$

This limits your search space to the 36 possible combinations of $(a, b)$ with $0 \le a \le 3$ and $0 \le b \le 8$.

Also, we need $c \ge 0$, which means that once we've set a value for $a$, we can constrain $7a + 3b \le 24$, or $b \le \frac{24 - 7a}{3}$. This reduces the number of valid $(a, b)$ combinations to 21.

For $c$ to be an integer, we must have $24 - 7a - 3b$ be even. This means that $a$ and $b$ must be either both even or both odd.

This gives us a reasonably efficient algorithm for enumerating the solutions.

for a = 0 to 3:
    for b = (a mod 2) to floor((24 - 7a) / 3) step 2:
        c = (24 - 7a - 3b) / 2
        print(a, b, c)

Where a mod 2 equals 0 if a is even, or 1 if a is odd, thus ensuring that b has the same parity as a.

This can straightforwardly be converted to a computer program, or even done manually.

Dan
  • 18,262
  • Using a computer program is pointless, because then, any educational value that the problem composer might have intended is destroyed. The same can be said for manually counting the number of combinations. Again, the problem becomes pointless. – user2661923 Jun 07 '22 at 21:58