• Post Reply Bookmark Topic Watch Topic
  • New Topic
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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Can the box fit into another box?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please help me with this task.
Very hard Task.

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: 8760
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Compare the two shorter sides, then the two medium sides, then the two longest sides.
 
Marshal
Posts: 74381
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
As Carey has hinted, it isn't quite as hard as that website suggested.
 
Marshal
Posts: 26912
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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: 8760
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 26912
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic