7
1
In chemistry class, we were learning about titrations, and attempting one as a lab. We were using phenolphthalein as the indicator for the titration, so on top of grading the lab normally, my teacher held a little contest to see who had the lightest shade of pink, and thus the most accurate transition.
Your task is to write a program that acts like the teacher and judges the titrations.
Specs
As input, you take a list of RGB triples in any sane format representing the titration of each student. ex: ["D966FF", "ECB3FF", "AC00E6"]
. You will be guaranteed that if converted to HSL, the hue is 285
and the saturation is 100
.
The conversion for RGB to HSL lightness is the average of the max and min of the normalized RGB components (*100
for a percentage).
Now the teacher is a human being and therefore cannot measure the lightness of the solution perfectly, so before you do any of the things described below, randomly change the lightness value of each of the titrations by ±3
, uniformly distributed.
If a titration has a lightness value greater than 94
, it is too light to visibly see that all the acid has neutralized. Therefore, the first output is a list, sorted in descending order, of all the titrations whose RGB triples, when converted to HSL, yield a lightness value less than 94. This represents the results of the contest.
The other output is a list of all the people who have failed the lab. This includes the people with the lightness values greater than 94
, but also people whose lightness values are less than or equal to 65
because these people's titrations are too inaccurate.
This is code-golf, so shortest code in bytes win.
Test Cases
These test cases all assume that the error is always 0 for ease in checking if your program is correct. The results from your program should be different each time you run it.
["D966FF", "ECB3FF", "AC00E6"] -> ["ECB3FF", "D966FF", "AC00E6"], ["AC00E6"]
["EDB8FF", "D761FF", "9100C2", "FBEFFF"] -> ["EDB8FF", "D761FF", "9100C2"], ["FBEFFF", "9100C2"]
["F5D6FF"] -> ["F5D6FF"], []
@PeterTyler Actually, only one of them is wrong invalid, and that is the fourth element in the 2nd test case, which evaluates to
– R. Kap – 2016-05-22T00:08:03.203284º
instead of285º
when converted to HSL.@PeterTaylor It's fixed now. – R. Kap – 2016-05-22T04:06:42.027