Areas from Origin X59299


Statement
 

pdf   zip   main.py

html

A point in the integer plane is defined by a pair of integers (x, y): first the x-axis coordinate, then the y-axis coordinate, as usual. Such a point defines an axis-parallel rectangle with respect to the origin of coordinates, namely (0, 0). The other two corners are, clearly, (0, y) and (x, 0). What is the area of this rectangle? Write a function area(x,y) that receives two integers x and y and returns the area of the rectangle specified in this manner.

An approximate drawing of the public test cases, with points p: (5,3) and q: (−1, −1) could be:

                  |
                  3 -- - -- - -- - -- - -- p
                  |                        |
                  2                        |
                  |                        |
                  1                        |
                  |                        |
- -3 - -2 - -1 -- 0 -- 1 -- 2 -- 3 -- 4 -- 5 --
             |    |
             q - -1
                  |
                 -2
                  |

Sample session
>>> area(5, 3)
15
>>> area(3, 5) + area(-1, -1)
16
Information
Author
José Luis Balcázar
Language
English
Official solutions
Python
User solutions
Python