Problem 166141 · easy · Phase 01 Prerequisites & Setup

Bouncing Ball Bounces

loops · while · simulation · integer division

A ball is dropped from height centimetres. After every bounce it rises back up to half its previous height, rounded down (integer division). Write bounces(height, min_height) that counts how many bounces rise to at least min_height centimetres. A bounce that rises to less than min_height is not counted, and the ball stops there.

Examples

Input:  height = 100, min_height = 10
Output: 3
Explanation: bounces rise to 50, 25, 12 (three counted); the next would only be 6.

Input:  height = 5, min_height = 10
Output: 0

Constraints

  • 0 <= height <= 10**9
  • 1 <= min_height <= 10**9

Goals

  • Use a while loop that stops when a value becomes too small
  • Count the number of iterations a simulation takes
Starting Python…