2.6 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 6a26df95efa55a2524399745 | Challenge 364: Between Two Buckets | 29 | challenge-364 |
--description--
Given two buckets of paint, each with an RGB color and a fullness level, return the mixed RGB color as an array of three integers.
- Each bucket is an object (JavaScript) or dictionary (Python) with a
colorproperty (an array of three integers[r, g, b]) and afullnessproperty (0–100). - The mixed color is a weighted average of each channel in the two colors based on fullness level, with each channel rounded to the nearest integer.
--hints--
mix_paint({"color": [250, 250, 250], "fullness": 50}, {"color": [0, 0, 0], "fullness": 50}) should return [125, 125, 125].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(mix_paint({"color": [250, 250, 250], "fullness": 50}, {"color": [0, 0, 0], "fullness": 50}), [125, 125, 125])`)
}})
mix_paint({"color": [250, 250, 250], "fullness": 80}, {"color": [0, 0, 0], "fullness": 20}) should return [200, 200, 200].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(mix_paint({"color": [250, 250, 250], "fullness": 80}, {"color": [0, 0, 0], "fullness": 20}), [200, 200, 200])`)
}})
mix_paint({"color": [100, 150, 200], "fullness": 30}, {"color": [100, 150, 200], "fullness": 70}) should return [100, 150, 200].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(mix_paint({"color": [100, 150, 200], "fullness": 30}, {"color": [100, 150, 200], "fullness": 70}), [100, 150, 200])`)
}})
mix_paint({"color": [143, 143, 101], "fullness": 45}, {"color": [100, 204, 204], "fullness": 90}) should return [114, 184, 170].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(mix_paint({"color": [143, 143, 101], "fullness": 45}, {"color": [100, 204, 204], "fullness": 90}), [114, 184, 170])`)
}})
mix_paint({"color": [15, 134, 249], "fullness": 29}, {"color": [97, 178, 55], "fullness": 54}) should return [68, 163, 123].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(mix_paint({"color": [15, 134, 249], "fullness": 29}, {"color": [97, 178, 55], "fullness": 54}), [68, 163, 123])`)
}})
--seed--
--seed-contents--
def mix_paint(bucket1, bucket2):
return bucket1
--solutions--
def mix_paint(bucket1, bucket2):
total = bucket1['fullness'] + bucket2['fullness']
return [
round((c1 * bucket1['fullness'] + c2 * bucket2['fullness']) / total)
for c1, c2 in zip(bucket1['color'], bucket2['color'])
]