# The Challenge

Write a program that can calculate how many times and how long a ball will bounce based on a few input variables.

# Input

There are three variables that will be passed. You can accept these however you like (user input, function call, etc). The variables are as follows:

1. height
2. velocity
3. "bounciness"

They must be passed in this order.

### Height

Height will be expressed as an integer, H, where 10^6 ≥ H ≥ 10. The height is measured in arbitrary units, u, which have no effect on your program's output.

### Velocity

The velocity of the ball will be represented by an integer, V, where 10^6 ≥ V ≥ 1. It is expressed as Vu/s (V units per second).

### Bounciness

The "bounciness" will be expressed as a decimal, B, where 0.00 ≤ B < 1.00. The maximum precision of B will be the hundredths place (two digits after the decimal point).

# Output

You output will be two integers representing:

• number of times the ball will bounce before coming to rest, N

• how long it takes the ball to complete all of these bounces, T

# Calculation

To calculate the number of times the ball will bounce, you would continuously multiply the current height by the "bounciness" until it dipped below 1. Once the result gets below 1, you should round the height down to 0, and stop calculating.

Each time these two are multiplied, the time is incremented by the quotient of the current height and velocity.

Intermediary calculations should have a minimum precision to the ten-thousandths (four digits after the decimal).

# Example 1

If the input is:

10 10 0.5


The following table shows the necessary calculations for each bounce:

Height          Next       Height             Bounces
------        -------      ------             -------
10.0000       10.0000    *   0.5    = 5.0000        1
5.0000        5.0000    *   0.5    = 2.5000        1
2.5000        2.5000    *   0.5    = 1.2500        1
1.2500        1.2500    *   0.5    = 0.6250        1

-------
Total Bounces:      4

----------------
10.0000    /  10   =   1.0000
5.0000    /  10   =   0.5000
2.5000    /  10   =   0.2500
1.2500    /  10   =   0.1250

------
Total Time: 1.8750


At this point, the computation terminates because the height is less than 1. The time is rounded up to yield 2. These two integers should then either be returned or output as a string in this form:

4 2


# Example 2

If the input is:

50 15 0.7


The following table shows the necessary calculations for each bounce:

Height      Next                  Height     Bounces
------     -------                -------    -------
50.0000    50.0000  *   0.7    =  35.0000          1
35.0000    35.0000  *   0.7    =  24.5000          1
24.5000    24.5000  *   0.7    =  17.1500          1
17.1500    17.2500  *   0.7    =  12.0050          1
12.0050    12.0050  *   0.7    =   8.4035          1
8.4035     8.4035  *   0.7    =   5.8825          1
5.8825     5.8825  *   0.7    =   4.1177          1
4.1177     4.1177  *   0.7    =   2.8824          1
2.8824     2.8824  *   0.7    =   2.0177          1
2.0177     2.0177  *   0.7    =   1.4124          1
1.4124     1.4124  *   0.7    =   0.9887          1

--------
Total Bounces:      11

-----------
50.0000    /  15   =     3.3333
35.0000    /  15   =     2.3333
24.5000    /  15   =     1.6333
17.1500    /  15   =     1.1433
12.0050    /  15   =     0.8003
8.4035    /  15   =     0.5602
5.8825    /  15   =     0.3922
4.1177    /  15   =     0.2745
2.8824    /  15   =     0.1922
2.0177    /  15   =     0.1345
1.4124    /  15   =     0.0942

----------
Total Time:   10.8913


At this point, the computation terminates because the height is less than 1. The time is rounded up to give 11. These two integers should then either be returned or output as a string in this form:

11 11


# Scoreboard

For your score to appear on the board, it should be in this format:

# Language, Score


Or if you earned a bonus:

# Language, Score (Bytes - Bonus%)


function getURL(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function getAnswers(){$.ajax({url:getURL(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),useData(answers)}})}function getOwnerName(e){return e.owner.display_name}function useData(e){var s=[];e.forEach(function(e){var a=e.body.replace(/<s>.*<\/s>/,"").replace(/<strike>.*<\/strike>/,"");console.log(a),VALID_HEAD.test(a)&&s.push({user:getOwnerName(e),language:a.match(VALID_HEAD)[1],score:+a.match(VALID_HEAD)[2],link:e.share_link})}),s.sort(function(e,s){var a=e.score,r=s.score;return a-r}),s.forEach(function(e,s){var a=$("#score-template").html();a=a.replace("{{RANK}}",s+1+"").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SCORE}}",e.score),a=$(a),$("#scores").append(a)})}var QUESTION_ID=58319,ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",answers=[],answer_ids,answers_hash,answer_page=1;getAnswers();var VALID_HEAD=/<h\d>([^\n,]*)[, ]*(\d+).*<\/h\d>/;
body{text-align:left!important}table thead{font-weight:700}table td{padding:10px 0 0 30px}#scores-cont{padding:10px;width:600px}#scores tr td:first-of-type{padding-left:0}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"><div id="scores-cont"><h2>Scores</h2><table class="score-table"><thead> <tr><td></td><td>User</td><td>Language</td><td>Score</td></tr></thead> <tbody id="scores"></tbody></table></div><table style="display: none"> <tbody id="score-template"><tr><td>{{RANK}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SCORE}}</td></tr></tbody></table>

• I have two comments on the use of the sandbox: 1. If you're going to use the sandbox, use the sandbox. There is no point posting something there for 4 hours. 24 hours is the minimum which makes sense. 2. Once you post a question which has been sandboxed, you should replace the body of the sandbox post with a link to the live question. This reduces clutter and avoids confusion. – Peter Taylor Sep 20 '15 at 7:53
• Why must the inputs be given in that order? – Beta Decay Sep 20 '15 at 9:21
• Simplicity between answers. @BetaDecay – Zach Gates Sep 20 '15 at 15:19

# CJam, 3128 29 bytes

Latest version rounds up time to next integer. I had missed that in the requirements. This adds 2 bytes, and saves 1 byte based on a suggestion by Dennis.

l~_3$W#2$mLm]@1$#(@(/@/@*m]S\  Try it online Thanks to @ThomasKwa for suggesting the use of mL instead of the quotient of two separate logarithms. This uses basic log laws for calculating the number of bounces, and then the sum of a geometric series, which I had to look up on Wikipedia. Explanation: l~ Get and interpret input. _ Copy B, will need this later. 3$    Get copy of H to top.
W#    Calculate H^-1 = 1/H as double.
2$Get copy of B to top. mL Log with base. m] Ceiling. This is the number of bounces N. @ Rotate one copy of B to top. 1$    Copy number of bounces to top.
#     Exponent B^N.
(     Subtract 1.
@     Get other copy of B to top.
(     Subtract 1.
/     Divide the two values.
@/    Rotate V to top and divide.
@*    Get H to top and multiply. This is T.
m]    Ceiling for time.
S\    Swap a space between the two resulting values.

• @ThomasKwa I hadn't seen that the time needs to be rounded. It was shown as floating point in the example calculation, but it's indeed rounded to int at the very end. Weird, but I'll add it. CJam does not have a unary minus, so changing the sign is 2 bytes. I was considering that, but it didn't look like it was going to be shorter. – Reto Koradi Sep 20 '15 at 4:46

# Python2, 84 82 bytes

from math import*
h,v,b=input()
n=ceil(-log(h,b))
print ceil(h*(b**n-1)/(b-1)/v),n


Closed forms, yay!

• log(h,1./b) -> -log(h,b)? – lirtosiast Sep 20 '15 at 3:38
• @ThomasKwa Of course :) – orlp Sep 20 '15 at 3:39

# TI-BASIC, 35

Prompt H,V,B
-int(logBASE(H,B
Disp -int(H/V(B^Ans-1)/(1-B
Ans


A port of orlp's Python answer.

## CoffeeScript, 62 bytes

f=(h,v,b,n=t=0)->(t+=h/v;h*=b;n++)while 1<=h;n+' '+Math.ceil t


# Pyth, 27 bytes

L_/b1y_c*Qt^KvwJy.lQK*vwtKJ


Direct port of my Python answer. Takes input in the following format:

h
b
v

• When I input 10 10 0.5 I get a syntax error, and 10\n10\n0.5 gives me -2 -1. – lirtosiast Sep 20 '15 at 4:00
• @ThomasKwa As said in my answer, the correct format would be 10\n0.5\n10. – orlp Sep 20 '15 at 4:01
• OP says the inputs must be passed in the order h v b (which I don't agree with, btw). – lirtosiast Sep 20 '15 at 4:02
• @ThomasKwa Ugh... I can't be arsed to fix this. Too bad. – orlp Sep 20 '15 at 4:02

## PHP, 87 bytes

Takes three command line arguments.

<?for($h=$argv[1],$n=$t=0;$h=>1;$n++){$t+=$h/$argv[2];$h*=$argv[3];}echo"$n ".ceil(\$t);