NP Code Competition

# Colors

Back to Problem Listing
You are given a list of tuples. Each tuple has 5 elements in it. The first four of these are numbers and the last one is a string that will be either "red", "yellow", or "blue".

Pretend that each tuple in this list is a rectangular piece of colored cellophane arranged on a white table where each rectangle is aligned with the cartesian axes. The first two numbers in each tuple are the x and y coordinates (respectively) of the top left corner of the rectangle. The 3rd and 4th numbers of each tuple are the width and height of the rectangle (respectively).

Write a function called rainbow_science that takes in 3 parameters: a list of these tuples (colored rectangles), an x-coordinate, and a y-coordinate. You must return a string that describes the perceived color at this point. So for example, if the given point is located where a red and blue rectangle overlap, you must return "purple". If the given point does not overlap any rectangles, then you should return "white".

All colors inputs and outputs will/ought to be lowercase.

Here are all the possible outcomes:
no overlaps --> "white"
red-overlaps only --> "red"
blue-overlaps only --> "blue"
yellow-overlaps only --> "yellow"
red and yellow overlaps --> "orange"
yellow and blue overlaps --> "green"
blue and red overlaps --> "purple"
all 3 colors overlap --> "brown"

## Sample

```>>> rainbow_science([(0, 0, 4, 5, "blue"), (3, 0, 4, 5, "yellow")], 1, 1)
"blue"
>>> rainbow_science([(0, 0, 4, 5, "blue"), (3, 0, 4, 5, "yellow")], 5, 1)
"yellow"
>>> rainbow_science([(0, 0, 4, 5, "blue"), (3, 0, 4, 5, "yellow")], 3.5, 1)
"green"
>>> rainbow_science([(0, 0, 4, 5, "blue"), (3, 0, 4, 5, "yellow")], 100, 1)
"white"
>>> rainbow_science([(0, 0, 4, 5, "blue"), (3, 0, 4, 5, "yellow"), (0, 0, 7, 5, "red")], 3.5, 1)
"brown"```
This contest has ended. No more answers will be accepted.