I opened a pull request (PR) here regarding a bug related to the C++ track that was promptly closed by the github-actions bot. It turns out that, because the bug is related to a test case, then I will need to open a discussion here first before the PR can be reviewed.
I have pasted the body of the PR below, since it explains the basic premise. I would appreciate it if someone could give me some feedback, and possibly re-open the PR if it looks OK.
The following test case contains an incorrect want value.
Currently, the test case has the following parameters:
\texttt{balance} = 2345.67
\texttt{target_balance} = 12345.6789
\texttt{want} = 85
However, the value of want is incorrect. Since \texttt{balance} = 2345.67, then, as given in the instructions, the interest rate is \% 1.621. If we assume that \texttt{want} = 85 as given above, then the final balance after \texttt{want} years is
Similarly, the final balance after \texttt{want} - 1 years is approximately \$ 9054.78. If the want value was correct, then the target balance would have been between the final balance after want - 1 years and the final balance after want years. However, this is not the case.
This PR fixes the want value by setting it to 104 years. We can see that this is indeed correct since
From first glance, that seems correct. Apart from the test case, that would also touch the exemplar solution in the .meta directory. There are a ton of other tracks that just take those test cases and reuse them, so your point might be valid for other tracks.
(Full disclosure: I implemented that exercise in the first place and wrote the test cases, e.g. modified them from the source code of some other track. Probably go)
Thank you for sharing the exemplar solution, Christian, and thanks for re-opening my PR. I have a follow-up question for you: given that the PR is now re-opened, are there any changes that you would suggest I add to make it merge-able?
By the way, the exemplar solution is actually quite different from my solution, which was
#include <cmath>
// years_until_desired_balance calculates the minimum number of years required
// to reach the desired balance.
int years_until_desired_balance(double balance, double target_balance) {
// TODO: Implement the years_until_desired_balance function
return int(ceil(log(target_balance / balance) / log(1 + interest_rate(balance) / 100)));
}
Of course, my solution isn’t really appropriate for learning about for loops, because it uses none, and it includes cmath, which may not be appropriate, but I wanted to mention it anyway (FYI, I obtained this solution by re-arranging the following equation to solve for x and then applying ceil() followed by int():
Are you able to transform your solution into the concepts, that are meant to be taught?
Yes. After seeing exemplar solution here, it became clear that the exercise was asking me to make use of the previous functions that I had written.
However, it would have been helpful if there was a note in the instructions explaining that I should be making use of the previous functions I had written, as I hadn’t immediately realized this.