7

A crate of eggs is stacked with eggs such that eggs are stacked on eggs in the crate until it is fully occupied and no egg can sit on another egg comfortably

Derive a mathematical formula to determine the total number of eggs stacked on the crate hence using your formula calculate how many eggs can be stacked on a crate that can contain 6 eggs per row and 5 eggs per column as the base

I was able to solve this in python programming by looking at the problem this way: For a crate that can contain n eggs by x eggs, The first layer(ground layer) will contain a total of n*x eggs The second layer will contain (n-1) * (x-1) eggs The third layer will contain (n-2) * (x-2) eggs In that order until n=0 or x=0 Now taking the sum of the total number of eggs on the 1st, 2nd, 3rd,…nth layers, we get the total number of eggs in the stack

Now how do I generate a mathematical formula for this problem?

Here is my python code

def eggCount(row,column):
    totalEggs = 0
    while row>0 and column>0:
        eggs_on_layer = row * column
        totalEggs += eggs_on_layer
        row -= 1
        column -= 1
    return totalEggs

print(eggCount(6,5))

image of eggs stacked on crate

3 Answers3

4

Hint Suppose that the bottom layer is an array of $m \times n$ eggs (and without loss of generality, suppose that $m \geq n$). Your formula says that the $k$th layer from the bottom (indexing the bottom layer with $k = 0$) has $$(m - k)(n - k)$$ eggs, and there are a total of $n$ layers (the top layer thus has index $k = n - 1$), so the total number of eggs is $$S_{m,n} := \sum_{k=0}^{n - 1} (m - k) (n - k) = \sum_{k=0}^{n - 1} k^2 - (m + n) \sum_{k = 0}^{n - 1} k + mn\sum_{n = 0}^{n - 1} 1 .$$

Taking $\ell = n - 1$ in the familiar formulas $$\sum_{k = 0}^l k^2 = \frac{1}{6} (2 \ell + 1) (\ell + 1) \ell, \qquad \sum_{k = 0}^\ell k = \frac{1}{2} (\ell + 1) \ell, \qquad \sum_{k=0}^\ell 1 = \ell + 1,$$ and simplifying gives $$S_{m,n} = \frac{1}{6} (3m - n + 1) (n + 1) n .$$ This double sequence is the content of OEIS A082652, and its generating function is $$F(x, y) := \frac{(1+xy-2x^2 y)xy}{(1-xy)^4(1-x)^2} .$$ By definition $S_{m, m}$ is the $m$th square pyramidal number.

Travis Willse
  • 108,056
2

If you had $n \le m$ with $n$ the lower of the number of rows and columns and $m$ as the higher,

then you could say this was a square pyramid of eggs (with an $n\times n$ base) with $m-n$ extra triangles of eggs (each with base $n$) resting on one side of the pyramid,

so with a total number of eggs of: $$\sum\limits_{i=1}^n i^2 + (m-n)\sum\limits_{j=1}^n j\\ = \tfrac16n(n+1)(2n+1)+(m-n)\times \tfrac12n(n+1) \\= \frac16n(n+1)(3m-n+1)$$

Henry
  • 169,616
1

One way to do this is via a recursive formula. The good thing is you have already worked out both the base and recursive steps for such a formula.

As you said if row or column is zero then there are no eggs in that layer.

You also understand that the number of total eggs is equal to the number of eggs on the bottom layer plus all the eggs on the layers above. And that the layers above is just another crate of eggs.

From that information you can create a recursive formula.

$$ E(n,m) = \begin{cases} 0 & n = 0 \vee m = 0 \\ mn + E(n-1,m-1) & \text{otherwise} \end{cases} $$