MHB Optimizing Block Distribution for Children's Boxes: A Computational Approach

  • Thread starter Thread starter Thread7
  • Start date Start date
  • Tags Tags
    Blocks Children
AI Thread Summary
The discussion focuses on creating an algorithm to distribute blocks among three children without exceeding the height limits of their boxes. The initial approach suggested looping through all combinations, which could be inefficient. A more efficient method proposed is backtracking, which systematically checks combinations and avoids unnecessary calculations by reverting when a block does not fit. This approach is expected to reduce computing resources while allowing for flexibility with different block assortments and box sizes. The user plans to implement backtracking to optimize the block distribution process.
Thread7
Messages
2
Reaction score
0
I'm sorry if this isn't the correct forum. I wasn't sure where to put it. I have a problem that I need to make a computer algorithm to solve. I thought someone here might be able to give me some ideas.
The basic problem is this:
There are 3 children each with their own box.

-George's box is 20 inches tall.
-Thomas' box is 8 inches tall.
-Abe's box is 7 inches tall.


In the room there is an assortment of blocks. The blocks have different heights. We must find a way for the children to be given various blocks so that the sum of the block heights they each are given is not higher than each children's box.

The blocks in the room and their heights are as follows:
- There is one block that is 2 inches tall.
- There is one block that is 3 inches tall.
- There are 6 blocks that are 5 inches tall.


How do you write an algorithm to perfectly distribute the blocks so each child's box does not overflow?

The answer to this is pretty easy.
- George: 4 of the 5 inch blocks. Total is 20 inches.
- Thomas: 1 of the 5 inch blocks and the 3 inch block. Total is 8 inches.
- Abe: 1 of the 5 inch blocks and the 2 inch block. Total is 7 inches.


But if I had written a computer program to distribute the blocks in the order in which I listed them, it would not have worked. George would get both the 2 inch and 3 inch block, then 3 of the 5 inch blocks. There would be 3 of the 5 inch blocks left over and both Thomas and Abe can only accept one of them. Leaving one left over that no one can accept.

The only way I can think is to write a program that loops through every combination until something works. Is there a way that takes less computing resources?

Furthermore, after I solve this, I am going to need to make the program work with any assortment of blocks, sizes, and children. So I am really looking for an approach to solving this and not simply a way to solve this one example.

Thanks in advance!
 
Mathematics news on Phys.org
Thread7 said:
I'm sorry if this isn't the correct forum. I wasn't sure where to put it. I have a problem that I need to make a computer algorithm to solve. I thought someone here might be able to give me some ideas.
The basic problem is this:
There are 3 children each with their own box.

-George's box is 20 inches tall.
-Thomas' box is 8 inches tall.
-Abe's box is 7 inches tall.


In the room there is an assortment of blocks. The blocks have different heights. We must find a way for the children to be given various blocks so that the sum of the block heights they each are given is not higher than each children's box.

The blocks in the room and their heights are as follows:
- There is one block that is 2 inches tall.
- There is one block that is 3 inches tall.
- There are 6 blocks that are 5 inches tall.


How do you write an algorithm to perfectly distribute the blocks so each child's box does not overflow?

The answer to this is pretty easy.
- George: 4 of the 5 inch blocks. Total is 20 inches.
- Thomas: 1 of the 5 inch blocks and the 3 inch block. Total is 8 inches.
- Abe: 1 of the 5 inch blocks and the 2 inch block. Total is 7 inches.


But if I had written a computer program to distribute the blocks in the order in which I listed them, it would not have worked. George would get both the 2 inch and 3 inch block, then 3 of the 5 inch blocks. There would be 3 of the 5 inch blocks left over and both Thomas and Abe can only accept one of them. Leaving one left over that no one can accept.

The only way I can think is to write a program that loops through every combination until something works. Is there a way that takes less computing resources?

Furthermore, after I solve this, I am going to need to make the program work with any assortment of blocks, sizes, and children. So I am really looking for an approach to solving this and not simply a way to solve this one example.

Thanks in advance!

Welcome to MHB, Thread7! :)

Basically you have to indeed loop through every combination until something works.
However, you can optimize the procedure quite a bit.

The method is called backtracking.
See for instance wiki: https://en.wikipedia.org/wiki/Backtracking

The principle is that we systematically verify each combination block by block.
Once we find a block that no longer fits, we do not try to continue with the other blocks, which is what your proposed algorithm would do.
Instead we "backtrack".
We take the last block that did not fit back, and try another block.
Then we take the last 2 blocks back that did not fit, and so on.
 
Ok, this helps. I was hoping it wouldn't be that resource intensive. I'll proceed down the backtracking route and if anyone has other comments please chime in.
 
Seemingly by some mathematical coincidence, a hexagon of sides 2,2,7,7, 11, and 11 can be inscribed in a circle of radius 7. The other day I saw a math problem on line, which they said came from a Polish Olympiad, where you compute the length x of the 3rd side which is the same as the radius, so that the sides of length 2,x, and 11 are inscribed on the arc of a semi-circle. The law of cosines applied twice gives the answer for x of exactly 7, but the arithmetic is so complex that the...
Is it possible to arrange six pencils such that each one touches the other five? If so, how? This is an adaption of a Martin Gardner puzzle only I changed it from cigarettes to pencils and left out the clues because PF folks don’t need clues. From the book “My Best Mathematical and Logic Puzzles”. Dover, 1994.
Back
Top