To solve the problem, we need to determine how many days it took for X, Y, and Z to complete the work together, given that Y left 4 days before the work was completed.
### Step-by-Step Solution:
1. **Determine the Work Rates of X, Y, and Z:**
- X can complete the work in 30 days, so X's work rate is \( \frac{1}{30} \) of the work per day.
- Y can complete the work in 40 days, so Y's work rate is \( \frac{1}{40} \) of the work per day.
- Z can complete the work in 50 days, so Z's work rate is \( \frac{1}{50} \) of the work per day.
2. **Calculate the Combined Work Rate:**
- The combined work rate of X, Y, and Z when they work together is:
\[
\text{Combined Rate} = \frac{1}{30} + \frac{1}{40} + \frac{1}{50}
\]
- To add these fractions, we need a common denominator. The least common multiple (LCM) of 30, 40, and 50 is 600.
- Convert each fraction:
\[
\frac{1}{30} = \frac{20}{600}, \quad \frac{1}{40} = \frac{15}{600}, \quad \frac{1}{50} = \frac{12}{600}
\]
- Now add them:
\[
\text{Combined Rate} = \frac{20 + 15 + 12}{600} = \frac{47}{600}
\]
3. **Determine the Total Work Done:**
- Let the total work be represented as 600 units (as we assumed).
- Since Y leaves 4 days before the work is completed, let \( D \) be the total number of days taken to complete the work.
- This means Y worked for \( D - 4 \) days.
4. **Calculate Work Done by Each Worker:**
- Work done by X in \( D \) days: \( \frac{D}{30} \)
- Work done by Y in \( D - 4 \) days: \( \frac{D - 4}{40} \)
- Work done by Z in \( D \) days: \( \frac{D}{50} \)
5. **Set Up the Equation:**
- The total work done by all three workers must equal 600 units:
\[
\frac{D}{30} + \frac{D - 4}{40} + \frac{D}{50} = 1
\]
- To eliminate the fractions, multiply through by 600 (the common denominator):
\[
20D + 15(D - 4) + 12D = 600
\]
6. **Simplify the Equation:**
- Distributing the terms:
\[
20D + 15D - 60 + 12D = 600
\]
- Combine like terms:
\[
47D - 60 = 600
\]
- Add 60 to both sides:
\[
47D = 660
\]
- Divide by 47:
\[
D = \frac{660}{47} \approx 14.04 \text{ days}
\]
7. **Conclusion:**
- Since the number of days must be a whole number, we round up to the nearest whole number, which is 15 days.
### Final Answer:
The work was completed in **15 days**.