Project Euler Problem 317

A firecracker explodes at a height of pu{100 m} above level ground.

Project Euler Problem 317

Solution

Answer: 1856532.8455

Let the explosion occur at height $h=100$ m above the ground, with all fragments launched at speed

$$v_0 = 20 \text{ m/s}$$

under gravity

$$g = 9.81 \text{ m/s}^2.$$

We want the volume of all points in space that are reached by at least one fragment before it hits the ground.


1. Mathematical analysis

A fragment launched with velocity components $(v_x,v_y,v_z)$ satisfies

$$v_x^2+v_y^2+v_z^2=v_0^2.$$

Because the problem is rotationally symmetric around the vertical axis, we use cylindrical coordinates:

  • $r=\sqrt{x^2+y^2}$
  • $z$ vertical height.

Let:

  • $u$ = horizontal speed,
  • $w$ = vertical speed,

so that

$$u^2+w^2=v_0^2.$$

The projectile equations are

$$r = ut,$$

$$z = h + wt - \frac12 gt^2.$$

Eliminate $u$ using $u=r/t$:

$$\left(\frac{r}{t}\right)^2 + w^2 = v_0^2.$$

Also,

$$w=\frac{z-h+\frac12 gt^2}{t}.$$

Substitute:

$$\frac{r^2}{t^2} + \left(\frac{z-h+\frac12 gt^2}{t}\right)^2 = v_0^2.$$

Multiply by $t^2$:

$$r^2 + \left(z-h+\frac12 gt^2\right)^2 = v_0^2 t^2.$$

We seek, for each $(r,z)$, whether there exists a $t>0$ satisfying this.


Envelope of reachable points

Define

$$A=z-h.$$

Then

$$r^2 + \left(A+\frac12 gt^2\right)^2 = v_0^2 t^2.$$

Expand:

$$r^2 + A^2 + Ag t^2 + \frac14 g^2 t^4 = v_0^2 t^2.$$

Let $s=t^2$:

$$\frac14 g^2 s^2 + (Ag-v_0^2)s + (A^2+r^2)=0.$$

Reachability requires a real solution $s\ge0$. Thus the discriminant must satisfy

$$(Ag-v_0^2)^2 - g^2(A^2+r^2)\ge0.$$

Expand:

$$A^2g^2 - 2Agv_0^2 + v_0^4 - g^2A^2 - g^2r^2 \ge 0.$$

The $A^2g^2$ terms cancel:

$$v_0^4 - 2Agv_0^2 - g^2r^2 \ge 0.$$

Recall $A=z-h$:

$$g^2r^2 \le v_0^4 - 2g v_0^2(z-h).$$

Solve for $z$:

$$z \le h + \frac{v_0^2}{2g} - \frac{g r^2}{2v_0^2}.$$

This is a paraboloid.

Hence the entire reachable region is the solid under

$$z(r)=H-\alpha r^2$$

where

$$H=h+\frac{v_0^2}{2g}, \qquad \alpha=\frac{g}{2v_0^2}.$$

The region ends where $z=0$:

$$0=H-\alpha R^2$$

so

$$R^2=\frac{H}{\alpha}.$$


2. Volume computation

The volume of a solid of revolution is

$$V=\int_0^R \pi r^2,dz$$

or more directly

$$V=2\pi\int_0^R r(H-\alpha r^2),dr.$$

Compute:

$$V = 2\pi \left[ \frac{H r^2}{2} - \frac{\alpha r^4}{4} \right]_0^R.$$

Using $R^2=H/\alpha$,

$$V = 2\pi \left( \frac{H(H/\alpha)}{2} - \frac{\alpha(H/\alpha)^2}{4} \right).$$

Simplify:

$$V = 2\pi \left( \frac{H^2}{2\alpha} - \frac{H^2}{4\alpha} \right) = \frac{\pi H^2}{2\alpha}.$$

Since

$$\alpha=\frac{g}{2v_0^2},$$

we obtain

$$V = \pi H^2\frac{v_0^2}{g}.$$

Now plug in values:

$$H = 100+\frac{20^2}{2\cdot 9.81} = 100+\frac{400}{19.62} = 120.3873598369\ldots$$

Thus

$$V = \pi \cdot H^2 \cdot \frac{400}{9.81}.$$


3. Python implementation

import math

# Given constants
h = 100.0
v0 = 20.0
g = 9.81

# Maximum height of the envelope paraboloid
H = h + v0**2 / (2 * g)

# Volume formula derived analytically
V = math.pi * H**2 * (v0**2 / g)

# Print rounded to 4 decimal places
print(f"{V:.4f}")

4. Code walkthrough

import math

Imports $\pi$.


h = 100.0
v0 = 20.0
g = 9.81

Stores the physical constants.


H = h + v0**2 / (2 * g)

Computes the peak height of the paraboloid envelope:

$$H = h + \frac{v_0^2}{2g}.$$


V = math.pi * H**2 * (v0**2 / g)

Uses the derived exact formula

$$V = \pi H^2 \frac{v_0^2}{g}.$$


print(f"{V:.4f}")

Prints the required value rounded to four decimals.

Running the code gives

$$1856532.8455$$


5. Final verification

The region is a very large paraboloid:

  • maximum height about $120$ m,
  • horizontal radius about $313$ m,

so a volume on the order of

$$\pi (300)^2 (100)\approx 3\times10^7$$

would be too large because the paraboloid tapers strongly. A result around $1.8\times10^6$ m$^3$ is reasonable.

The derivation is exact and dimensionally consistent.

Answer: 1856532.8455