Help with starting a gardening program.

Hello! First, I really appreciate any help you can give. I am tasked with creating a program to fit plants into a gardening bed. Here is the exact task below. I am having trouble starting the program because I am just not getting back into programming. If you could give me a general outline as to how I will design this program I would greatly appreciate it.

Mel Bartholomew promotes square foot gardening. The idea that you have a garden that uses only
4 foot by 4 foot beds. And then you put plants in each bed according to how big the plant is.
An onion for instance would be a 1 x 1, but a dwarve peach would be a 4 x 4. Write a program
that allows the user to enter the plants they want in all garden beds and then output a report
that says what plants should be in which beds.
Againtry is a resident troll. Don't let him get to you.

What you're describing sounds like a "knapsack problem" (in particular, a geometric knapsack problem of some kind).

In effect you've got a number of 4ft by 4ft squares, in which you can put plants. Each plant demands a certain amount of space. However, because of the constraints of each plant, just knowing that plants need less area than the bed contains is no guarantee that you can arrange those plants in that bed.

For example, if you had a 4x3 plant, and a 2x2 plant, even though the two plants together need 16 units of space, and a 4x4 bed IS 16 units of space, there is no way to fit them both in.

Now that you know the term for this class of problem - "knapsack problem" - you should be able to find various discussions of it. There are some classic algorithms that often do a reasonable job of this - for example, the "greedy" algorithm, which simply attempts to place the plants into the beds in any available space, starting with the biggest. You could do worse than start by writing your code to simply do that and see where you get.
And repeater is an ego-driven ponce who goes to writing his cult code drivel without understanding what the client's needs are.

He can't read or even follow a link to the genuine article which expands on the original short brief, even gives you more data on plants to 'play' with.

He is a shallow fool who shoots the messenger. He is an incompetent who just wants to air terms like greedy algorithms and knapsack problems, which are so unrelated to getting a start, it is beyond comical.

Repeater, like a few others is doing you a great disservice.
You could do worse than start by writing your code to simply do that and see where you get.
True, but not much worse and certainly not getting a handle on the problem before leaping and jumping out of control conclusions. Repeater's off the starting blocks at full speed. Only trouble Repeater is going the wrong way in the wrong game.
Got it. I appreciate the help and as soon as I get a chance I'll look into the knapsack problem. My class was having trouble overall so the professor gave us an example code that helps a lot. I hope I can figure it out! Thanks for the help!
Topic archived. No new replies allowed.