A social network reports the number of votes a post has in two ways: the number of net upvotes (total upvotes - total downvotes), and the % of votes that were upvotes, rounded to the nearest integer (.5 rounds up). The number of net upvotes is an integer (not necessarily positive), and the second is guaranteed to be an integer between 0 and +100 inclusive. The number of upvotes and the number of downvotes are both either zero or positive 32-bit integers (you can specify signed or unsigned). Assume that if there are zero total votes, the percentage upvoted is reported as zero.
Given these two integers (net upvotes and % upvoted), what is the shortest program you can write which determines the lowest number of total upvotes the post received, with all the constraints above satisfied?
Input constraints are guaranteed. If the input does not satisfy the constraints above, the program behavior is up to you. Bonus kudos if it doesn't enter an infinite loop or otherwise crash. Consider returning a negative number if you want more guidance.
- This is code-golf, so the shortest valid solution (measured in bytes) wins.
- If you have interesting solutions in multiple languages, post them separately.
- Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, or full programs. Your call.
- Default loopholes are forbidden.
- If possible, please add a link with a test for your code.
- Also, please add an explanation of how the code works.
- Keep in mind that if you are doing an integer division operation that truncates (e.g. 20/3=6) rather than rounds, that might not be fully correct.
- Additional test cases that explore the edge cases in the above constraints are welcome.
- While the expected return type is numeric, boolean "false" can be used in place of 0.
Example test cases:
The first column is just a reference number included to facilitate discussion.
ref net %up answer 1 0 0 => 0 2 -5 0 => 0 3 -4 17 => 1 4 -3 29 => 2 5 -2 38 => 3 6 -1 44 => 4 7 0 50 => 1 8 5 100 => 5 9 4 83 => 5 10 3 71 => 5 11 2 63 => 5 12 1 56 => 5 13 1234 100 => 1234 14 800 90 => 894 (tip: don't refer to this as the "last test case;" others may be added.)