r/dailyprogrammer_ideas • u/_Krug • Jun 01 '21
[Intermediate] - Floor Designer
Flooring Design Question
Imagine for a moment that you work for a flooring company. You’ve been laying hardwood floors for a while and you find yourself in a rather peculiar situation. To your surprise, Eric, your coworker with the only saw has left and has taken the saw with him. You look at the scrap pile of hardwood that remains and you find the following pieces.
| Quantity | Length(cm) | Height(cm) |
|---|---|---|
| 10 | 90 | 10 |
| 10 | 45 | 10 |
| 20 | 22.5 | 10 |
| 20 | 8 | 10 |
You’re determined to lay the hardwood flooring in the last room of the customers home, and agree to finish the job. The room that you’re going to be flooring has the dimensions of 196cm x 100cm.
The customer heard that you were a great programmer, and requested a script that would do the following:
- Use no more materials than you found in the scrap pile (the customer is environmentally conscious)
- Output a visual of the completed room, which will include a grid of what size pieces are used in a particular row.
- Bonus points if each execution of the script produces different results (within possibility).
Example result: https://x0.at/AQ9.png
Notes: - Let’s assume greater-than-human precision is at play, and there are no imperfections in the room, wood, etc.
1
u/po8 Jun 03 '21 edited Jun 03 '21
Thanks again for sharing this. I've now solved it. A few comments:
With the board lengths as given, a maximally greedy tiling works fine — no search needed. My solution was
I wish I had written this in the first place. Either need to find more interesting board lengths or give a hint that search is not needed.
Happy to share my code if it is helpful.
1
u/po8 Jun 02 '21
Hooray, a problem! Thank you!
I'll try to get to solving it and leaving some comments shortly.
1
u/cbarrick Jun 20 '21
This is similar to the (multiple) knapsack problem and the bin packing problem.
For these types of problems, I think it is way more fun to have a complex set of things to pack so that a simple greedy algorithm won't work.
Maybe you can have three versions of increasing difficulty:
It's solutions to the third type that interests me the most.
Also, you should formally define the input and output formats as something that could be read from stdin and written to stdout.