Suppose you have a receipt with some numbers that have been smudged or didn't print. In particular, the total amount is missing the first and last digits. The purchase did not involve tax (or you're looking at the subtotal before tax), only one item was purchased, and the quantity of the item is known. Use this data to determine what the total amount was, assuming that the unit cost does not contain a fraction of a cent. The partially known total will be provided as a string with an X for the unknown first and last digits.
In some cases, there will be multiple possible answers. We're going to assume the best and return the lowest possible total. The second missing digit can range from 0 to 9, though the first missing digit is the leading number, and, therefore, cannot be zero.
there may be a few incorrect tests here (e.g. test 2 with 'X31.6X' and qty=111 should return '531.69' if I am interpreting correctly)
agree with alfonso
I had the same issue with that particular test case.
I've updated the test suite. It should work now. I selected the option to have all previous solutions rescored, but I've never actually seen that option work for other problems I've worked on, so just submit your solutions again. Also, refer to comments on http://www.mathworks.com/matlabcentral/cody/problems/42385-combined-ages-4-non-symmetric-with-multiples-n-3 regarding not being able to use the "Test reference solution" button currently. Is anyone else having that problem?
I believe rescoring doesn't work immediately, but all solutions seem to be rescored now. "Test reference solution" doesn't work for me neither. As far as I remember it's not the first time it doesn't work (on my account), but previous incidents had shorter duration (week or so).
http://www.mathworks.com/matlabcentral/cody/solutions/686845#comment_5568
That link doesn't work as written (at least, it didn't for me). It does function, though, if you truncate the url at #.
Funny behavior of possible over-reactive spam filter in Cody: changing this code to use instead of char(str2num('[49 36 49.... 36 50 57')) the actual char array '1$1...$29' will get you an "inappropriate content" flag... I admit no regexprep string should ever have that many dollar signs...
fails for partial_amt = 'X67.9X'; qty = 9; and many, many others
A bunch of your solutions now pass the test suite, so perhaps this comment is outdated?
In above case it returns 567.90, correct answer would be 167.94. This solution is minimizing last digit which works in most cases, but is based on wrong assumptions. It passes test, but doesn't solve the problem. Yes, my later submissions doesn't have this bug, but I'm unsatisfied when those wrong ones are going through the test alive :-)
You had me confused, since that specific combination isn't in the test suite, but I think I understand now. In your quest for perfection, you've been testing the solution against more test cases. That's the really difficult thing about making these problems—coming up with a robust test suite that's in-depth enough to only let completely correct solutions through.
Sorry Grant. Yes, I'm used to do more tests and I was suspicious about my algorithm.
436 Solvers
Permute diagonal and antidiagonal
179 Solvers
Detect a number and replace with two NaN's
157 Solvers
166 Solvers
Implement a bubble sort technique and output the number of swaps required
81 Solvers