6 kyu

Bouncing Balls

10,487 of 93,560g964

Description:

A child is playing with a ball on the nth floor of a tall building. The height of this floor above ground level, h, is known.

He drops the ball out of the window. The ball bounces (for example), to two-thirds of its height (a bounce of 0.66).

His mother looks out of a window 1.5 meters from the ground.

How many times will the mother see the ball pass in front of her window (including when it's falling and bouncing)?

Three conditions must be met for a valid experiment:

  • Float parameter "h" in meters must be greater than 0
  • Float parameter "bounce" must be greater than 0 and less than 1
  • Float parameter "window" must be less than h.

If all three conditions above are fulfilled, return a positive integer, otherwise return -1.

Note:

The ball can only be seen if the height of the rebounding ball is strictly greater than the window parameter.

Examples:

- h = 3, bounce = 0.66, window = 1.5, result is 3

- h = 3, bounce = 1, window = 1.5, result is -1 

(Condition 2) not fulfilled).
Puzzles
Algorithms
Mathematics

More By Author:

Check out these other kata created by g964

Stats:

CreatedMay 2, 2015
PublishedMay 2, 2015
Warriors Trained207302
Total Skips44585
Total Code Submissions435606
Total Times Completed93560
Ruby Completions2199
Python Completions30941
Clojure Completions386
Java Completions10487
C# Completions5717
JavaScript Completions22614
Haskell Completions700
CoffeeScript Completions28
TypeScript Completions2336
C++ Completions6404
Elixir Completions314
PHP Completions2354
Crystal Completions37
F# Completions126
C Completions3524
Rust Completions1594
Swift Completions1077
Go Completions2316
R Completions281
Shell Completions133
OCaml Completions76
Kotlin Completions1270
Fortran Completions37
Julia Completions118
Scala Completions367
PowerShell Completions122
Nim Completions34
Racket Completions50
Reason Completions7
Prolog Completions30
Pascal Completions31
Factor Completions10
Raku Completions10
Perl Completions36
Elm Completions9
D Completions13
Erlang Completions18
Total Stars2601
% of votes with a positive feedback rating83% of 8182
Total "Very Satisfied" Votes5868
Total "Somewhat Satisfied" Votes1869
Total "Not Satisfied" Votes445
Ad
Contributors
  • g964 Avatar
  • Abbe Avatar
  • Ismail Avatar
  • Chrono79 Avatar
  • kazk Avatar
  • Blind4Basics Avatar
  • Firefly2002 Avatar
  • Madjosz Avatar
  • Bubbler Avatar
  • monadius Avatar
  • hobovsky Avatar
  • solitude Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • Just4FunCoder Avatar
  • KayleighWasTaken Avatar
Ad