-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
book-store: Add test checking that solutions can mix groups of 4 and 5 #2141
Conversation
A couple of things:
|
@sswingle this is a very good catch ... I didn't try too hard to come up with a target for which the two approaches disagreed. This one really is worth adding to the canonical data file that @cmccandless mentioned, so please open an issue or PR there. Unfortunately there's a temporary hold on merges for that repo, but it'll be good to have it documented for when that lifts. |
@cmccandless @yawpitch thanks for taking the time to look at this and point me in the right direction. I'll make a PR for the canonical data change. Looks like the other reason the CI build failed was that the example solution for book store only correctly works for input that's sorted (i.e. my test should be [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5]). When the hold on merges on the other repo lifts, what happens when I merge the PR there? Does this PR need to go through at the same time so that builds work? What about other language tracks? |
This PR will need to merge shortly after the update to canonical-data, yes. Other language tracks will likely adopt the new canonical version as well in their own time (not every track has failing CI when tests are out-of-date). The example solution here will also need to be updated to pass the new test. My advice there would actually be to sort the input inside the example solution, not in the test, as this makes the solution more robust. |
I've created a PR over on problem-specifications (exercism/problem-specifications#1620) On this one I've edited the example solution to sort inputs. This should pass tests and be read to merge when the problem-specs one merges. |
To be accurate this PR is not in a state where it could be merged when exercism/problem-specifications#1620 is merged; because the tests are automatically generated from the canonical data the template would need updating, not the Also there's a subtle issue with the suggested change to the
|
No, it shouldn't. It should create a copy, and sort that. |
I'm not changing the formatting of any tests, so the template doesn't need to be changed - my changes to
Ah, of course not... |
I've now updated to add the second test I added in the problem-specifications PR (for shuffled book data). It was generated from the template, so should reflect that PR exactly. |
You're correct, misread and thought you were directly editing the test file. The usual process is that we pull changes to the problem-specifications, run the test builder, then do a PR that just reflects a sync with the upstream repo. |
Yeah that makes sense. Thanks for the help! I guess now we just wait on the other repo. |
This issue has been automatically marked as |
* [book-store] Add additional tests Adds tests that requires use of booth groups of 4 and 5 volumes. Closes #2141, which had gone stale. * [book-store] Update from latest template. * Crank the handle on Travis
Many of the "brute force" solutions I see do something like run a greedy solver multiple times with different maximum group sizes. This allows them to solve test cases that check for finding 2 groups of 4 instead of a group of 5 and a group of 3.
However, this wouldn't solve cases where you need to use both groups of 5 and groups of 4. For example, consider
books = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3]
. The cheapest price possible is achieved by splitting it into 1 group of 5 and 2 groups of 4, with cost =800*(1*5*0.75 + 2*4*0.8) = 8120
. Solutions like those described above will typically split it into 2 groups of 5 and 1 group of 3, with a cost of800*(2*5*0.75 + 1*3*0.9) = 8160
. An example is the compact brute force solution @yawpitch shows here: https://exercism.io/tracks/python/exercises/book-store/solutions/c58f3dcf78314e95820c717a30f787c9 (your recursive solution returns the correct value of 8120, of course).This PR adds the test case described above.