import numpy as np
def fit(inner_dims, outer_dims):
inner_dims.sort()
outer_dims.sort()
x1, y1, z1 = inner_dims
x2, y2, z2 = outer_dims
# Volume Test
inner_volume = x1 * y1 * z1
outer_volume = x2 * y2 * z2
if inner_volume > outer_volume:
return False
# Edge Test
diffs = np.greater_equal(outer_dims, inner_dims)
if np.all(diffs):
return True
# Rotation Test
inner_perms = [(x1, y1, z1), (x1, z1, y1), (z1, y1, x1)]
outer_perms = [(x2, y2, z2), (x2, z2, y2), (z2, y2, x2)]
for i, j in zip(inner_perms, outer_perms):
if rotation_test(i, j):
return True
# Diagonal Test
diag = np.sqrt(x2**2 + y2**2 + z2**2)
if x1 + y1 + z1 <= diag:
return True
return False
def rotation_test(inner_dims, outer_dims):
x1, y1, z1 = inner_dims
x2, y2, z2 = outer_dims
diag = np.sqrt(x2**2 + y2**2)
if x1 + y1 <= diag and z1 <= z2:
return True
else:
return False
def main():
n = 3
first = []
second = []
# iterating till the range
for i in range(0, n):
ele = int(input())
first.append(ele)
for i in range(0, n):
ele = int(input())
second.append(ele)
# first = [1,1,1]
# second = [2,2,2]
first.sort()
second.sort()
if first == second:
print("Boxes are of same size")
elif fit(first,second):
print("Box 1 fits in Box 2")
elif fit(second,first):
print("Box 2 fits in Box 2")
else:
print("Boxes are incomparable")
main()
please comment in case of doubt, please upvote the solution
Get Answers For Free
Most questions answered within 1 hours.