I always wanted to know if there is any real-world application of Pascal's triangle than just coefficients of the binomial expansion.
I tried to solve this problem:
But, What if I am adding K units of water and wants to find a glass which has the least water in it:
Where, Glass will be found as: c
-th glass in r
-th row
And I believe. If we could find this then it will not be difficult for us to find amount of water in any glass for which {i<r and j<c}
Problem:
Input Water added- K units and capacity of each glass as 1- unit
Output Expected :
c
th glass inr
th row having least water in it.
I tried to solve problem by keeping note of capacity of each row when it starts overflow: and wants to know how to keep going with this method.
1 max = 1, cap = 1
1 1 max = 1, sum(coefficients)=2**1 = 2, cap = 2/1
1 2 1 max = 2, sum = 2**2, cap = 4/2 = 2 units
1 3 3 1 max = 3, sum = 2**3, cap = 8/3 units
1 4 6 4 1 max = 6, sum = 2**4, cap = 16/6 units
#Not sure but this is how it seems to me for the rate @which water is being added.
1
1/2 1/2
1/4 2/4 1/4
1/8 3/8 3/8 1/8
1/16 4/16 6/16 4/16 1/16
Should I use 2-D list and define as :
Δ1, Δ2 = 0, 0
if g(n-1, k)>1 and k <= n-1:
Δ1 = g(n-1, k) -1
if g(n-1, k-1)>1 and k-1 <= n-1:
Δ2 = g(n-1, k-1) - 1
g(n, k) = Δ1/2 + Δ2/2
g(n,k) = g(n-1, k-1) + g(n-1, k)
g = [[0]*(i+1) for i in range(11)]
def f(g, K):
g[1][1] += 1
K = K-1
d1, d2 = 0, 0
for n in range(2, 10):
for k in range(1, n+1):
if k ==1:
g[n][k] = g[n-1][k]/2
if k == n:
g[n][k] = g[n-1][k-1]/2
else:
if g[n-1][k-1]>1:
d1 = g[n-1][k-1] -1
if g[n-1][k] > 1:
d2 = g[n-1][k] -1
g[n][k] = d1/2 + d2/2
return g, K
k = int(input())
while k:
g, k = f(g, k)
for x in g:
print(x)
I don't know what is missing?