Skip to content

Latest commit

 

History

History
32 lines (22 loc) · 764 Bytes

File metadata and controls

32 lines (22 loc) · 764 Bytes
  1. initialize a 2D array
  • 0th row : 1 glass
  • 1th row : 2 glasses

so [0.0] * (i+1) glasses are in the row

glasses = []
for i in range(query_row +1):
  glasses.append([0.0]*(i+1))
  1. pour the champagne
glasses[0][0] = poured # top glass
  1. iterate through each row and glass
  • When the topmost glass is full, any excess liquid poured will fall equally to the glass immediately to the left and right of it.
    • overflow = (glasses[i][j] - 1.0) / 2.0
  • (1, 1) -> (2, 1) (2, 2)
    • (i, j) -> (i+1, j), (i+1, j+1)
  1. one glass can't hold more than 1.0
  • min(1.0 glasses[query_row][query_glass])
  • maybe more than 1.0 champagne poured onto the floor.. :(