At this moment, you are not allowed access to the question.

Available Marks: 7

Smart watches now provide heart rate, walking speed, energy consumption, step counters and sometimes even the time. Everyone knows they should try to walk a certain minimum number of steps each day, and watches will often set a new target daily based on the number of steps taken over the last few days and the current target. Fitness Friend, ProgComp's proposed software that will only get to market if you can implement it for us, goes one step (sorry) further.

Some people are discouraged if they keep failing to reach their target: they have low motivation. Others try to outdo themselves every day and want an always-increasing target: they're highly motivated. Fitness Friend introduces a self-nominated motivation factor M, an integer between 0 and 100. The way it works is shown in the diagram below.

Today's step target is a particular number represented by the red horizontal line. When you exceed the target (S > T, green dot), then if you have low motivation the new target (red dot) is only a bit more than the old one to make it more attainable, but if you have high motivation it moves closer to S. Conversely if you don't reach the target (S < T, blue dot), in the low motivation case the target moves a long way down, much less so for the high-motivation case.

The new-target calculation is given by two similar formulas, depending on whether today's target was reached:

where S is today's step count, T is today's target, T is tomorrow's target, rounded down to the next integer, and M is the Fitness Friend Motivation Factor. k is just M converted to the range 0 to 1.

For example, if M is 45, T is 7500 and S is 7125, the second formula gives

k = 0.45, (1–k)2 = 0.55*0.55 = 0.3025,
T ′ = 7500 + 0.3025 * (7125 – 7500) = 7500 + 0.3025 * (–375) = 7500 – 113.4375 = 7386.5625
which you round down to 7386.

Your task

Write a program that calculates the daily targets given motivation and daily step counts, collecting simple statistics to report at the end. The first line of input has the Motivation Factor and starting target, separated by a space. The rest of the input has the daily steps, one per line. A negative value ends the list (and isn't counted as step data of course).

Your program should list all the targets on one line, then on a new line show

All quantities are expressed as integers, rounded down.

Example

80 7500
8231
7700
9015
6000
-1
produces...
7500 7967 7956 8633 8527
Motivation 80, days 4, mean steps 7736, goal reached 50%. Final target 8527
If the same step data is used but the motivation is changed from 80 to 30, the targets are more modest and the goal is reached more easily:
7500 7565 7577 7706 6870
Motivation 30, days 4, mean steps 7736, goal reached 75%. Final target 6870

Test data

Test your program using the following data.

60 8200
8350
10245
9254
7957
7880
7885
8194
8114
10176
9625
8492
9550
9483
10498
10511
9033
9215
10655
9791
8210
10664
8251
9800
8310
9614
7682
9327
7785
10527
9881
-1

Bonus Points

Simple programs can sometimes be used as tools to analyse aspects of the problem area. In this case there's an interesting relationship between motivation and the final target, which is monotonic increasing (this just means the greater the motivation, the higher the final target). By changing the motivation in the data file and rerunning the program, you could identify points on the relationship curve, or estimate the motivation required to set a specified target for this data set.

Use the program, without changing it at all, to find out what motivation is required to achieve a final target of 9888 for the steps in the test file (888 is an auspicious number in some cultures). Be smart about this, like the watch: try 50, halfway between 0 and 100. if the result is too high try 25 (halfway between 0 and 50), otherwise try 75. Keep going this way, choosing the midpoint between the deduced smallest and largest possible motivation, according to each result. This technique is called binary search, and is an important programming principle. While you're not programming it here, you are applying it to avoid having to try all possibilities. It will give you the answer in no more than 7 tries (log2 100). For bonus points, show each motivation value you tried, the last one being the answer. You get one for the correct answer but two for the binary search technique (if done approximately correctly). Note: bonus points are not included in the qualifying score for the finals, sorry.

Assessment

Step 0

Refresh the browser window  if the page has been idle for some time.

Step 1

Paste the output of your program for the long test case into the box below.

Step 2

Paste the source code for your program into the box below.

Step 3

When you are sure all the data has been entered correctly on the form press the submit button below.

You may submit multiple times. Only your most recent submission for each question will be marked.


Image source: myelmm.com