You are given to paint a floor area of size A. There will be 12 paint buckets from 4 primary colors with each having 3 shades (i.e. total 12 buckets). The bucket size, or more specifically, the amount of area you can paint from each shade is given in the following arrays. The different shades of the same primary color are shown in the same row.
- [12, 23, 14]
- [10, 30, 15]
- [16, 22, 35]
- [14, 24, 20]
Problem & Constraints
You need to select 4 shades to paint the floor area such that;
- Entire floor area should be painted; also no overlaps of shades are allowed
- "One and only one" shade from each primary color has been selected for the final painting
- Amount of wastage is minimized (i.e. assume once we open and use a bucket, any remainings will be discarded)
Implement a python program to answer the following problems;
Q1. The color shades (or buckets) satisfying the above constraints (if A = 100)
Q2. The amount of wastage in the above scenario
Q3. What will be the solution for Q1 and Q2 if A = 90?
Note: You may use the below notation to reference each shade in the above map.
R - row index
C - column index
(r,c) - shade in (r+1)th row and (c+1)th column
e.g. (0,0) -> 12, (0,1) -> 23, (1,2) -> 15, etc.
With this, the answer for Q1 can be given in the format [(0,1), (1,2), (2,0), (3,2)]
If user enter 100 system should display color code areas with their coordinates which sum are most close to 100
Example
Enter your Area = 100
100 ~ 101(sum of areas 12+30+35+24, There for 101 is the closet number to 100)
Shades = [12 30 35 24]
Cordinates of shades = (0,0)(1,1)(2,2)(3,1)
This is my answering code
import numpy as np
import itertools
colors = np.array([[12, 23, 14], [10, 30, 15], [16, 22, 35], [14, 24, 20]])
max_tot = 0
#get total of all integers which are in array
for i in range(len(colors)):
max_tot = max_tot + max(colors[i])
#Enter Area
area = int(input("Enter your Area = "))
if(area > max_tot):
print("Area is too long. Don't have enough paints for painting")
elif(area <= 0):
print("Wrong area")
else:
#get shades which are given lowest minimum wastage
for element in itertools.product(*colors):
if(sum(element) >= area):
x = sum(element)
if(x <= max_tot):
max_tot = x
el = np.array(element)
print()
print("sum of shades =", max_tot)
print("minimum wastage =" , max_tot - area)
print("Shades =", el)
print("Cordinates of shades = " ,end ='')
#get coordinates using manual method
for i in range(4):
g,h = np.where(colors == el[i])
print("(" ,g[0],",", h[0], ")", sep=' ', end='', flush=True)
Output -:
Enter your Area = 100
sum of shades = 101
minimum wastage = 1
Shades = [12 30 35 24]
Cordinates of shades = ( 0 , 0 )( 1 , 1 )( 2 , 2 )( 3 , 1 )
You can see I have got coordinates of 12 30 35 24
is manual type. That is not a good programming method.
How can I get that coordinates directly(using better way)?
Note that I have done all question. I want a better answer for Q3
from How to get cordinates of selected numbers which are from array
No comments:
Post a Comment