Skip to content

Instantly share code, notes, and snippets.

@jin-x
Last active June 6, 2021 09:55
Show Gist options
  • Save jin-x/bc3583791921dcbcf3d27c79ddfaf4e9 to your computer and use it in GitHub Desktop.
Save jin-x/bc3583791921dcbcf3d27c79ddfaf4e9 to your computer and use it in GitHub Desktop.
@jinxonik / UniLecs #86
# Get maximum side size of three squares inside rectangle with specified width and height
def sqr3_side_in_rect(x, y):
# assume:
# length (of rectangle) = maximum of x and y
# width (of rectangle) = minimum of x and y
#
# if width divided by 2 is more than
# minimum of (length divided by 3) and width
# we'll cut by this scheme:
# +-----+-----+--+
# |%%%%%|%%%%%| |
# |%%%%%|%%%%%| |
# +-----+-----+--+
# |%%%%%| |
# |%%%%%| |
# +-----+--------+
# else we'll cut by this scheme:
# +-----+-----+-----+
# |%%%%%|%%%%%|%%%%%|
# |%%%%%|%%%%%|%%%%%|
# +-----+-----+-----+
# | |
# +-----------------+
return max(min(x, y)/2, min(max(x, y)/3, min(x, y)))
for r in ((210,297),(250,100),(10,100),(5,5)):
w, h = r
print('Rect width = %f, height = %f, square side = %f' % (w, h, sqr3_side_in_rect(w, h)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment