This week's book giveaway is in the Testing forum.We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!See this thread for details.
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Tim Cooke
• Devaka Cooray
• Ron McLeod
• Jeanne Boyarsky
Sheriffs:
• Liutauras Vilda
• paul wheaton
• Junilu Lacar
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Piet Souris
• Carey Brown
• Tim Holloway
Bartenders:
• Martijn Verburg
• Frits Walraven
• Himai Minh

# Can the box fit into another box?

Greenhorn
Posts: 1
• Number of slices to send:
Optional 'thank-you' note:

So I want to get how does it work, not just code without comments

There are two boxes on the table. The first box has a size of X1 x Y1 x Z1, and the second box has a size of X2 x Y2 x Z2. You need to determine which box can be put inside another box. You can rotate both boxes as you want.

Input contains two lines.
The first line contains numbers X1, Y1, Z1, the second line contains numbers X2, Y2, Z2. All numbers are integers and greater than 0.

If the sizes of the boxes are equal, output "Box 1 = Box 2".

If the first box can be put inside the second box, output "Box 1 < Box 2".

If the second box can be put inside the first box, output "Box 1 > Box 2".

If none of the boxes can be put inside the other box, output "Incomparable".

Saloon Keeper
Posts: 9734
80
• Number of slices to send:
Optional 'thank-you' note:
Compare the two shorter sides, then the two medium sides, then the two longest sides.

Marshal
Posts: 76860
366
• Number of slices to send:
Optional 'thank-you' note:
Welcome to the Ranch
As Carey has hinted, it isn't quite as hard as that website suggested.

Sheriff
Posts: 27451
88
• Number of slices to send:
Optional 'thank-you' note:
But Carey's suggestion assumes a limited version of "rotate". For example a 14x1x1 box can fit inside an 11x11x1 box if you rotate it correctly. Given that version of "rotate", this is not at all easy.

Carey Brown
Saloon Keeper
Posts: 9734
80
• Number of slices to send:
Optional 'thank-you' note:
Interesting observation. I see you're thinking outside the box.

I would be surprised if that was what the framers of the question had in mind but the link to the problem has timed out and is no longer available to verify. If your theory is correct, then yes, that would be a pretty sticky problem to solve and would be beyond my geometry skills.

Paul Clapham
Sheriff
Posts: 27451
88
• Number of slices to send:
Optional 'thank-you' note:
I have the feeling that the full three-dimensional version of my theory is an unsolved mathematical problem -- at least I sort of recall reading that figuring out whether a given rectangular block can be moved around a corner in a given rectangular corridor is unsolved, which is probably more complicated. So I think that your simpler theory is the one meant to be solved.

Bartender
Posts: 732
10
• Number of slices to send:
Optional 'thank-you' note:
In general, it is easier to solve if you rotate both boxed so that they lie flat in the x-y plane, where it is easier to calculate the volume of each. Then see if the one with the smaller volume will fit in the larger box.

 Evildoers! Eat my justice! And this tiny ad's justice too! the value of filler advertising in 2021 https://coderanch.com/t/730886/filler-advertising