Alternate solution
The synergistic close packing of uniform spheres problem resulted in the discovery of a polyhedron that maximizes spheres around a central sphere.
If you place one sphere at the middle, a maximum of 12 spheres can be arranged around that central sphere. If you take a vector from the center of each of the spheres arranged around the middle sphere you'll get a
dodecahedron. But this dodecahedron is not a platonic solid. Instead of getting a dodecahedron of 12 pentagons, you get one with 6 squares and 6 equilateral triangles that is based upon an arrangement of 12 internal tetrahedrons. A common name for this polyhedron is the
quadray.
Sphere packing, using
quadray can be used to kinda find a solution for your problem if you make a "assuming a square hole" conjecture.
Anywho's here it goes.
A quadray is roughly spherical, so make the assumption that a spherical gumball machine is close enough. Now the gumball is 9 inches in radius and a gumball is 1 inch in diameter (R=1/2 inch), so a radial vector has a length of 9 gumballs plus ½ inch for the central gumball and the radius is 9.5 inches. But this won't fit in a 9 inch machine so the quadray consists of 8 layers of close packed gumballs around a central gumball.
Counting the gumballs
The zeroth layer consists of 1 gumball; the first layer consists of twelve gumballs, the second by 42, and the third by 92 and so on. Further study indicated a pattern (one that is supported by geometry and counting) that the number of gumballs in a layer (except for the zeroth) can be given by 10F^2+2 where F is layer. The total number of balls in a quadray of F layers can be determined by summing up the layers. A little algebra, gives this formula.
Tb=10n(n+1)(2n+1)/6+2n+1
Which rearranges to
Tb=10/3n^3+5n^2+11/3n+1
So if there are 8 layers of gumballs in the quadray that makes the spherical gumball machine, there are 642 gumballs in the outermost layer (F=8) and a total of 2057 gumballs.
OK now you say, that's real nice, but a hole may not be square and a sphere is not a polyhedron called a quadray. As a matter of fact if a sphere is going to be a polyhedron it would be a platonic one.
My answer---Oh so now you want a measurement! Wait a minute. I'll go get the technician.
This is what the tech does
Vs=4/3pi9^3=3053.63 in^3
Vgb=4/3pi(1/2)^3=0.5236 in^3
Vv=(3053.65-0.5236n) in^3 where n is the number of gumballs
Using a gas (nitrogen is good) and assuming the gumballs are gas impermeable introduce a known amount of nitrogen (m grams) into the gumball machine and measure the pressure change.
Assuming the ideal gas law then
Vv= (m/DelP)RT
The number of gumballs (n) is measured to be
n=[3056.63-(m/DelP)RT]/0.5236
Rap