-
-
Notifications
You must be signed in to change notification settings - Fork 547
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
New Exercise book-store #465
Changes from 15 commits
fc2f3c2
cd400f1
eac9f63
4421deb
b7a263d
5b53197
f5ecac4
ab3c6f1
34e908a
3ea936a
b05216f
c3e2244
9f18d96
9a7e7fe
611ea3a
d58666e
3d70586
71d61f1
37b0fe8
2858c29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
{ | ||
"book-store": { | ||
"description": "Calculate lowest price for shopping basket only containing books from a single series", | ||
"cases": [ | ||
{ | ||
"description": "TestSingleBookPrice", | ||
"expected": 8.0 | ||
}, | ||
{ | ||
"description": "TestBasketContainsMyBooks", | ||
"mybasket": "3" | ||
"expected": "3" | ||
}, | ||
{ | ||
"description": "TestTotalBasketPriceSingleBook", | ||
"basket": "1", | ||
"expected": 8.0 | ||
}, | ||
{ | ||
"description": "TestTotalBasketPriceTwoofSameBook", | ||
"basket": "22", | ||
"expected": 16.0 | ||
}, | ||
{ | ||
"description": "TestTotalBasketPriceEmptyBasket", | ||
"basket": "", | ||
"expected": 0.0 | ||
}, | ||
{ | ||
"description": "TestBasketWith2DifferentBooks", | ||
"basket": "12", | ||
"expected": 15.2 | ||
}, | ||
{ | ||
"description": "TestBasketWith3DifferentBooks", | ||
"basket": "123", | ||
"expected": 21.60 | ||
}, | ||
{ | ||
"description": "TestBasketWith4DifferentBooks", | ||
"basket": "1234", | ||
"expected": 25.60 | ||
}, | ||
{ | ||
"description": "TestBasketWith5DifferentBooks", | ||
"basket": "12345", | ||
"expected": 30.00 | ||
}, | ||
{ | ||
"description": "basket 11223345", | ||
"basket": "11223345", | ||
"expected": 51.20 | ||
}, | ||
{ | ||
"description": "basket 112233445", | ||
"basket": "112233445", | ||
"expected": 55.60 | ||
}, | ||
{ | ||
"description": "basket 1122334455", | ||
"basket": "1122334455", | ||
"expected": 60.00 | ||
}, | ||
{ | ||
"description": "basket 11223344551", | ||
"basket": "11223344551", | ||
"expected": 68.00 | ||
}, | ||
{ | ||
"description": "basket 112233445512", | ||
"basket": "112233445512", | ||
"expected": 75.20 | ||
} | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
To try and encourage more sales of the 5 different books they sell in a popular series, a bookshop has decided to offer | ||
discounts of multiple-book purchases. | ||
|
||
One copy of any of the five books costs 8 EUR. | ||
|
||
If, however, you buy two different books, you get a 5% discount on those two books. | ||
|
||
If you buy 3 different books, you get a 10% discount. | ||
|
||
If you buy 4 different books, you get a 20% discount. | ||
|
||
If you go the whole hog, and buy all 5, you get a huge 25% discount. | ||
|
||
Note that if you buy, say, four books, of which 3 are different titles, you get a 10% discount on the 3 that | ||
form part of a set, but the fourth book still costs 8 EUR. | ||
|
||
Your mission is to write a piece of code to calculate the price of any conceivable shopping basket (containing only books from the same series), giving as big a discount as possible. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit confusing, it sounds like it wants me to calculate every possible price/combination. But further down it seems to indicate it just wants a method that given a list of books will calculate the cheapest total price for those books. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see your point, however I don't really see a better way to word this. At this point its is just copy/pasted from cyber-dojo. I suppose, as it is, it adds to the challenge of the problem. I know when I originally worked this problem I ended up disregarding this piece, but I think it is needed initially to help the reader understand the requirements. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if were were to change it, I would suggest just changing "any conceivable" to "a given", which should make it clear that the basket is the input. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What is the licensing on that text? We may need to rewrite the text (or at least heavily edit it), even though we're referring to cyber-dojo as the source. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kytrinyx I've been scouring the cyber-dojo site and I haven't found anything at this point that makes the statement one way or the other that the exercise is protected. In general the only licensing that I see is regarding the comercial use of the site as a whole. Some of the other exercises there site other sites as sources for complete instructions. Some of the exercises have NO instructions and only reference the source site. Should we ask for permission to use the text? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Anything that doesn't have a public license is copyrighted by default, and we can't use it. The cyber-dojo website is released under a couple of variants of the BSD license. Does it cite another source for the book sale exercise? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kytrinyx I am still looking. Here is a link to a license, looks like boiler plate. https://github.com/cyber-dojo/start-points-exercises/blob/master/LICENSE.md I am still looking around. I don't know if this license really grants permission for use of exercises or just relating to the site as a whole. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That license does grant use of the exercise, but only under the same license, which we don't have. The exercises here are under an MIT license. |
||
|
||
For example, how much does this basket of books cost? | ||
|
||
2 copies of the first book | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that at https://github.com/rpottsoh/x-common/blob/rpottsoh-patch-1/exercises/book-store/description.md the lines get mashed together. Bullet points? Or do we expect people to always be reading the raw md file in a text editor rather than rendering? (I always read raw, but I don't know about others) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The MD file gets rendered on the website at e.g. http://exercism.io/exercises/ruby/hello-world/readme So it seems important to get the formatting to look good rendered too, not just in plain text. |
||
2 copies of the second book | ||
2 copies of the third book | ||
1 copy of the fourth book | ||
1 copy of the fifth book | ||
|
||
One way of group these 8 books is: | ||
1 group of 5 --> 25% discount (1st,2nd,3rd,4th,5th) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These also get mashed together. Not sure of the best way to deal with it - use backticks? |
||
+1 group of 3 --> 10% discount (1st,2nd,3rd) | ||
This would give a total of | ||
5 books at a 25% discount | ||
+3 books at a 10% discount | ||
Giving | ||
5 x (8 - 2.00) == 5 x 6.00 == 30.00 | ||
+3 x (8 - 0.80) == 3 x 7.20 == 21.60 | ||
For a total of 51.60 | ||
|
||
However, a different way to group these 8 books is: | ||
1 group of 4 books --> 20% discount (1st,2nd,3rd,4th) | ||
+1 group of 4 books --> 20% discount (1st,2nd,3rd,5th) | ||
This would give a total of | ||
4 books at a 20% discount | ||
+4 books at a 20% discount | ||
Giving | ||
4 x (8-1.60) == 4 x 6.40 == 25.60 | ||
+4 x (8-1.60) == 4 x 6.40 == 25.60 | ||
For a total of 51.20 | ||
|
||
And 51.20 is the price with the biggest discount. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
blurb: "To try and encourage more sales of different books from a popular 5 book series, a bookshop has decided to offer discounts of multiple-book purchases." | ||
source: "Inspired by the harry potter kata from Cyber-Dojo." | ||
source_url: "http://cyber-dojo.org" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing comma here