taesik

how many times father see kid's falling and bouncing ball 본문

functions and trick/typescript_javascript

how many times father see kid's falling and bouncing ball

taesikk 2022. 1. 25. 14:31

A child is playing with a ball on the nth floor of a tall building. The height of this floor, 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 father looks out of a window 1.5 meters from the ground.

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

 

 

 

my solution

function bouncingBall(h,  bounce,  window) { 
  // your code here 
   
  if(bounce ===0||bounce < 0||bounce >1||bounce ===1 || window> h || window ===h || h===0 || h <0) return -1; 
   
  count = 1; 
   
  while(h>window) { 
    h=h*bounce; 
    if(h>window) count+=2; 
  } 
   
  return count; 
}
const bouncingBall=(h, b, w)=>(b>=1 || h<w || b<=0) ? -1 : Math.ceil(Math.log(w/h)/Math.log(b))*2-1;

https://people.richland.edu/james/lecture/m116/logs/properties.html

 

4.3 - Properties of Logarithms

4.3 - Properties of Logarithms Change of Base Formula One dilemma is that your calculator only has logarithms for two bases on it. Base 10 (log) and base e (ln). What is to happen if you want to know the logarithm for some other base? Are you out of luck?

people.richland.edu