Any box can take 3 positions if you don't account for mirrored ones: laying on the top/bottom, the front/back or either side. Ruling out each of these positions directly should be faster than either sorting the proportions (the first solution I shortly considered) or perform lots of multiplication and finding the maximum size for each box.
typeBox={width:number,height:number,length:number};constfitsOriented=(outer:Box,inner:Box)=>outer.width>inner.width&&outer.height>inner.height&&outer.length>inner.length;// turn over the X axis: swap height and lengthconstturnX=(box:Box)=>({width:box.width,height:box.length,length:box.height});// turn over the Z axis: swap width and lengthconstturnZ=(box:Box)=>({width:box.length,height:box.height,length:box.width});constfits=(outer:Box,inner:Box)=>fitsOriented(outer,inner)||fitsOriented(outer,turnX(inner))||fitsOriented(outer,turnZ(inner));constsolution=boxes.find((box)=>fits(box,item));
Any box can take 3 positions if you don't account for mirrored ones: laying on the top/bottom, the front/back or either side. Ruling out each of these positions directly should be faster than either sorting the proportions (the first solution I shortly considered) or perform lots of multiplication and finding the maximum size for each box.
Yeah technically indeed, however you might occur objects who fit diagonal in either of the three ways introducing another level.
Not really an issue for this puzzle, but in terms of finding the "best" one I got stuck on that as well.