Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.
2 added 72 characters in body
source | link

T-SQL, 305305 299 bytes

DECLARE @ char(999)=REPLACE(REPLACE(REPLACE(REPLACE('SELECT TOP 1i FROM(VALUES(''Very s$#9.0&S$#8s$#9&S$#8.4&Moderately#7.8&Slightly#7.3&Neutral'',6.5&Slightly@6.0&Moderately@5.5&S$@55&Slightly@6&Moderately@5.0&Very5&S$@5&Very s$@4.4&Extremely@3.4&Ultra@-1))x(i,j),t WHERE j<a','#',' alkaline'','),'@',' acidic'','),'&','),('''),'$','trongly')EXEC(@)

Input is via a pre-existing table t with DECIMAL(4,1) column a, per our Input/Output rules.

Because of the DECIMAL(4,1) data type, any "approximation rule" rounding takes place when the value is entered into the input table, so doesn't need to be explicitly managed by my code.

After the space-saving REPLACES are performed, this is a simple SQL query joining our input table with our list of values:

SELECT TOP 1 i
FROM(VALUES
    ('Very strongly alkaline',9.0),
    ('Strongly alkaline',8.4),
    ('Moderately alkaline',7.8),
    ('Slightly alkaline',7.3),
    ('Neutral',6.5),
    ('Slightly acidic',6.0),
    ('Moderately acidic',5.5),
    ('Strongly acidic',5.0),
    ('Very strongly acidic',4.4),
    ('Extremely acidic',3.4),
    ('Ultra acidic',-1)
) x(i,j), t
WHERE j<a

I reverse the order so TOP 1 picks the first one less than our input value.

Even this form (after removing line breaks and extra spaces) is pretty good, at 318 bytes. Adding the overhead of the DECLARE, REPLACES AND EXEC only becomes worth it with all the repeated phrases.

EDIT: Save 6 bytes by removing unnecessary ".0" on several values

T-SQL, 305 bytes

DECLARE @ char(999)=REPLACE(REPLACE(REPLACE(REPLACE('SELECT TOP 1i FROM(VALUES(''Very s$#9.0&S$#8.4&Moderately#7.8&Slightly#7.3&Neutral'',6.5&Slightly@6.0&Moderately@5.5&S$@5.0&Very s$@4.4&Extremely@3.4&Ultra@-1))x(i,j),t WHERE j<a','#',' alkaline'','),'@',' acidic'','),'&','),('''),'$','trongly')EXEC(@)

Input is via a pre-existing table t with DECIMAL(4,1) column a, per our Input/Output rules.

Because of the DECIMAL(4,1) data type, any "approximation rule" rounding takes place when the value is entered into the input table, so doesn't need to be explicitly managed by my code.

After the space-saving REPLACES are performed, this is a simple SQL query joining our input table with our list of values:

SELECT TOP 1 i
FROM(VALUES
    ('Very strongly alkaline',9.0),
    ('Strongly alkaline',8.4),
    ('Moderately alkaline',7.8),
    ('Slightly alkaline',7.3),
    ('Neutral',6.5),
    ('Slightly acidic',6.0),
    ('Moderately acidic',5.5),
    ('Strongly acidic',5.0),
    ('Very strongly acidic',4.4),
    ('Extremely acidic',3.4),
    ('Ultra acidic',-1)
) x(i,j), t
WHERE j<a

I reverse the order so TOP 1 picks the first one less than our input value.

Even this form (after removing line breaks and extra spaces) is pretty good, at 318 bytes. Adding the overhead of the DECLARE, REPLACES AND EXEC only becomes worth it with all the repeated phrases.

T-SQL, 305 299 bytes

DECLARE @ char(999)=REPLACE(REPLACE(REPLACE(REPLACE('SELECT TOP 1i FROM(VALUES(''Very s$#9&S$#8.4&Moderately#7.8&Slightly#7.3&Neutral'',6.5&Slightly@6&Moderately@5.5&S$@5&Very s$@4.4&Extremely@3.4&Ultra@-1))x(i,j),t WHERE j<a','#',' alkaline'','),'@',' acidic'','),'&','),('''),'$','trongly')EXEC(@)

Input is via a pre-existing table t with DECIMAL(4,1) column a, per our Input/Output rules.

Because of the DECIMAL(4,1) data type, any "approximation rule" rounding takes place when the value is entered into the input table, so doesn't need to be explicitly managed by my code.

After the space-saving REPLACES are performed, this is a simple SQL query joining our input table with our list of values:

SELECT TOP 1 i
FROM(VALUES
    ('Very strongly alkaline',9),
    ('Strongly alkaline',8.4),
    ('Moderately alkaline',7.8),
    ('Slightly alkaline',7.3),
    ('Neutral',6.5),
    ('Slightly acidic',6),
    ('Moderately acidic',5.5),
    ('Strongly acidic',5),
    ('Very strongly acidic',4.4),
    ('Extremely acidic',3.4),
    ('Ultra acidic',-1)
) x(i,j), t
WHERE j<a

I reverse the order so TOP 1 picks the first one less than our input value.

Even this form (after removing line breaks and extra spaces) is pretty good, at 318 bytes. Adding the overhead of the DECLARE, REPLACES AND EXEC only becomes worth it with all the repeated phrases.

EDIT: Save 6 bytes by removing unnecessary ".0" on several values

1
source | link

T-SQL, 305 bytes

DECLARE @ char(999)=REPLACE(REPLACE(REPLACE(REPLACE('SELECT TOP 1i FROM(VALUES(''Very s$#9.0&S$#8.4&Moderately#7.8&Slightly#7.3&Neutral'',6.5&Slightly@6.0&Moderately@5.5&S$@5.0&Very s$@4.4&Extremely@3.4&Ultra@-1))x(i,j),t WHERE j<a','#',' alkaline'','),'@',' acidic'','),'&','),('''),'$','trongly')EXEC(@)

Input is via a pre-existing table t with DECIMAL(4,1) column a, per our Input/Output rules.

Because of the DECIMAL(4,1) data type, any "approximation rule" rounding takes place when the value is entered into the input table, so doesn't need to be explicitly managed by my code.

After the space-saving REPLACES are performed, this is a simple SQL query joining our input table with our list of values:

SELECT TOP 1 i
FROM(VALUES
    ('Very strongly alkaline',9.0),
    ('Strongly alkaline',8.4),
    ('Moderately alkaline',7.8),
    ('Slightly alkaline',7.3),
    ('Neutral',6.5),
    ('Slightly acidic',6.0),
    ('Moderately acidic',5.5),
    ('Strongly acidic',5.0),
    ('Very strongly acidic',4.4),
    ('Extremely acidic',3.4),
    ('Ultra acidic',-1)
) x(i,j), t
WHERE j<a

I reverse the order so TOP 1 picks the first one less than our input value.

Even this form (after removing line breaks and extra spaces) is pretty good, at 318 bytes. Adding the overhead of the DECLARE, REPLACES AND EXEC only becomes worth it with all the repeated phrases.