Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago