14
3
Andrew is a chemist, interested in the acidity of solutions and in agriculture. After months of research (Google is not his friend), he came up with the following table* regarding the human-readable level of acidity in terms of the pH (potential of Hydrogen):
Denomination | pH range | -------------------------+----------------------------- Ultra acidic | below 3.5 -------------------------+------------------------------ Extremely acidic | between 3.5 and 4.4 -------------------------+------------------------------ Very strongly acidic | between 4.5 and 5.0 -------------------------+------------------------------ Strongly acidic | between 5.1 and 5.5 -------------------------+------------------------------ Moderately acidic | between 5.6 and 6.0 -------------------------+------------------------------ Slightly acidic | between 6.1 and 6.5 -------------------------+------------------------------ Neutral | between 6.6 and 7.3 -------------------------+------------------------------ Slightly alkaline | between 7.4 and 7.8 -------------------------+------------------------------ Moderately alkaline | between 7.9 and 8.4 -------------------------+------------------------------ Strongly alkaline | between 8.5 and 9.0 -------------------------+------------------------------ Very strongly alkaline | over 9.0
Given a non-negative decimal number representing the pH of a substance, output its Denomination. You can take input and provide output by any standard method. The data types you are allowed to take input with are:
- Float
- Double
- Your language's standard decimal number data type
- String
And you must output a String representing the denomination. Built-ins related to chemistry are forbidden (Sorry, Mathematica!).
Approximation Rule: If the pH you receive is between an upper bound of a denomination and the lower bound of the next one (e.g. between 7.8 and 7.9), it gets approximated to the closest value between the two: if the pH ≥ upperBound of the first + 0.5, then it should receive the second denomination, but if the pH < upperBound of the first + 0.5, then it should receive the first one (e.g 7.85 is approximated to 7.9, but 7.84999 is approximated to 7.8). See the test cases for clarifications.
Test Cases:
Input -> Output 6.40 -> Slightly acidic 8.399 -> Moderately alkaline 3.876 -> Extremely acidic 10.60 -> Very strongly alkaline 0.012 -> Ultra acidic 7.30 -> Neutral 7.85 -> Moderately alkaline (the approximation rule is applied) 7.849 -> Slightly alkaline (the approximation rule is applied) 6.55 -> Neutral (the approximation rule is applied)
This is code-golf, so the shortest valid submission (in bytes) wins!
*Andrew did not come up with that, it was Wikipedia!
Sandbox for those who can see deleted posts. – Mr. Xcoder – 2017-06-19T10:17:17.927
yeah this doesn't really work with actual acidity levels. anything more acidic than lemon juice is ultra acidic – Destructible Lemon – 2017-06-19T10:22:51.340
@DestructibleLemon If lemon juice is Ultra acidic, then Fluoroantimonic acid, that behaves like having −31.3 is a total atomic bomb :))
– Mr. Xcoder – 2017-06-19T10:26:01.967oh, I see where you went wrong. 3.5 ph is not ultra acidic, but it is ultra acidic if the soil you are growing plants in is 3.5 ph. what I mean is, this table refers to soil ph – Destructible Lemon – 2017-06-19T10:46:12.353
@DestructibleLemon That's what this challenge is about: soil pH :)... This is totally what I intended :§ – Mr. Xcoder – 2017-06-19T10:56:52.960
1Brownie points for an answer in Python or Swift :) – Mr. Xcoder – 2017-06-19T12:25:29.900
How isn't [tag:kolmogorov-complexity] suited for this? You must compress the denomination strings... – Mr. Xcoder – 2017-06-19T13:15:11.173
@Mr.Xcoder if the problem were to print the table, that would be a kolmogorov-complexity problem. But since the problem is to take a number as input and return a string, this is not a kolmogorov-complexity problem (I could be wrong about this, but that's the answer I got on one of my past posts) – musicman523 – 2017-06-19T13:24:09.317
@musicman523 Ok, I was really confused – Mr. Xcoder – 2017-06-19T13:24:47.337
Can you add
3.49
and9.01
as test cases as the outer limits are differents from the inner ones – ovs – 2017-06-19T16:42:49.870Is the input restricted to being a valid value of "your language's standard decimal number data type"? – user253751 – 2017-06-20T00:00:27.203
IMHO there should be a category, like "mapping", for this kind of challenge. It's basically "map elements in this specific set onto this other set". – Steve Bennett – 2017-06-20T01:02:21.450
@immibis Yes, you are guaranteed that the value is valid – Mr. Xcoder – 2017-06-20T07:15:07.503
@Mr.Xcoder So if I use Boolfuck again, where the standard data type is a bit, the input can only be 0 or 1 (decimal)? – user253751 – 2017-06-20T07:44:03.937
@immibis I really do not know what to say about this, but I will allow it. – Mr. Xcoder – 2017-06-20T07:45:19.040
I feel like it should be natural logarithm of hydronium.... – bleh – 2017-06-21T02:27:10.500