$active_open = "active"; // see header.php include "../files/user.php"; // also includes site.php include "../header.php"; include "authenticate.php"; if (! has_access()) { ?>
At this moment, you are not allowed access to the question.
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.
The new-target calculation is given by two similar formulas, depending on whether today's target was reached:
For example, if M is 45, T is 7500 and S is 7125, the second formula gives
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
80 7500 8231 7700 9015 6000 -1produces...
7500 7967 7956 8633 8527 Motivation 80, days 4, mean steps 7736, goal reached 50%. Final target 8527If 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 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
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.
You may submit multiple times. Only your most recent submission for each question will be marked.