I’d like to add a test case to Change with the following parameters:
"input": {
"coins": [1, 10, 11],
"target": 20
},
This is to catch out greedy approaches that try to use as many large coins as possible. The correct solution of course is 10 + 10, but greedily starting with 11 gives
a ten-coin solution with nine pennies.
I see that several years ago, someone checked in a change with the description “Add test for incorrect greedy algorithm”, but it only defends against a simple kind of greed, where you take the maximum possible number of coins at each step and get stuck as a result. If you moderate your greed, so that you take the maximum number that yields a solution, you will slip past this defense (ask me how I know!).
If others agree that this is a good idea, I can create a PR.
The existing test does pretty much the same thing as the one preceding it (no pennies, get stuck if blindly greedy), so yes, I’d say “reimplements” would be a good choice.
P.S. I see that schema validation failed with a complaint showing four duplicate uuids. However, none of them is the uuid of my new test. How should I resolve this?
The CI tests are all failing because exercises/eliuds-eggs/canonical-data.json and exercises/pop-count/canonical-data.json have the same UUIDs. This one is a bit unusual as it’s one of the few (only?) exercise renames.
It might be able to ignore those failures, but I’m not sure.
@iHiD / @ErikSchierboom should pop-count be removed? The duplication is going to make all PRs fail the CI tests here.