From b8a312b366dd7fde13bb12793f7126fccf6cf91a Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Wed, 22 May 2024 09:11:45 +0200 Subject: [PATCH] Sync the `knapsack` exercise's docs with the latest data. (#122) --- .../practice/knapsack/.docs/instructions.md | 21 +++++++------------ .../practice/knapsack/.docs/introduction.md | 8 +++++++ 2 files changed, 15 insertions(+), 14 deletions(-) create mode 100644 exercises/practice/knapsack/.docs/introduction.md diff --git a/exercises/practice/knapsack/.docs/instructions.md b/exercises/practice/knapsack/.docs/instructions.md index 1dbbca9..3411db9 100644 --- a/exercises/practice/knapsack/.docs/instructions.md +++ b/exercises/practice/knapsack/.docs/instructions.md @@ -1,22 +1,15 @@ # Instructions -In this exercise, let's try to solve a classic problem. - -Bob is a thief. -After months of careful planning, he finally manages to crack the security systems of a high-class apartment. - -In front of him are many items, each with a value (v) and weight (w). -Bob, of course, wants to maximize the total value he can get; he would gladly take all of the items if he could. -However, to his horror, he realizes that the knapsack he carries with him can only hold so much weight (W). - -Given a knapsack with a specific carrying capacity (W), help Bob determine the maximum value he can get from the items in the house. -Note that Bob can take only one of each item. +Your task is to determine which items to take so that the total value of his selection is maximized, taking into account the knapsack's carrying capacity. +Items will be represented as a list of items. +Each item will have a weight and value. All values given will be strictly positive. -Items will be represented as a list of pairs, `wi` and `vi`, where the first element `wi` is the weight of the *i*th item and `vi` is the value for that item. +Bob can take only one of each item. For example: +```text Items: [ { "weight": 5, "value": 10 }, { "weight": 4, "value": 40 }, @@ -24,9 +17,9 @@ Items: [ { "weight": 4, "value": 50 } ] -Knapsack Limit: 10 +Knapsack Maximum Weight: 10 +``` For the above, the first item has weight 5 and value 10, the second item has weight 4 and value 40, and so on. - In this example, Bob should take the second and fourth item to maximize his value, which, in this case, is 90. He cannot get more than 90 as his knapsack has a weight limit of 10. diff --git a/exercises/practice/knapsack/.docs/introduction.md b/exercises/practice/knapsack/.docs/introduction.md new file mode 100644 index 0000000..9b2bed8 --- /dev/null +++ b/exercises/practice/knapsack/.docs/introduction.md @@ -0,0 +1,8 @@ +# Introduction + +Bob is a thief. +After months of careful planning, he finally manages to crack the security systems of a fancy store. + +In front of him are many items, each with a value and weight. +Bob would gladly take all of the items, but his knapsack can only hold so much weight. +Bob has to carefully consider which items to take so that the total value of his selection is maximized.