Question
Write a Python function count_rectangles that takes as arguments positive integers m and n and returns the number of distinct, non-degenerate rectangles in an integer
Write a Python function count_rectangles that takes as arguments positive integers m and n and returns the number of distinct, non-degenerate rectangles in an integer grid with vertical lines at x=0,1,,m and horizontal lines at y=0,1,,n
.
Example 1: Consider the case when m=1
and n=1. In this case the grid is only the unit square with lower-left vertex at (0,0) and upper-right vertex at (1,1). Thus, your function should return 1
.
Example 2: Consider the case when m=2
and n=1 shown below. In this case there are 3 non-degenerate rectangles. The two small squares of side length 1, and the larger rectangle of side lengths 1 and 2. Thus, your function should return 3.
Write a Python function count rectangles that takes as arguments positive integers m and n and returns the number of distinct, non-degenerate rectangles in an integer grid with vertical lines at x = 0, 1, , m and horizontal lines at y = 0, 1, , n. Example 1: Consider the case when m 1 and n 1. In this case the grid is only the unit square with lower-left vertex at (0, 0) and upper-right vertex at (1,1). Thus, your function should return 1 Example 2: Consider the case when m 2 and n1 shown below. In this case there are 3 non-degenerate rectangles. The two small squares of side length 1, and the larger rectangle of side lengths 1 and 2. Thus, your function should return 3. (0,0) Notes: There are 3 visible test cases and 2 hidden test cases. The inputs m and n will satisfy 1 S m,n s 50. For example: Test print(count_rectangles (1,1)) 1 print(count_rectangles (2,1)) 3 Result
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started