Duplicate the KOOS Jr. Scoring interval algorithm

6

0

Inspired from a real problem; we were looking at this table and said "Hey, now that's a good codegolf problem."

The KOOS Jr. scores converts from a raw number to a percentile score given this table:

Raw summed score  Interval score
(0-28)            (0 to 100 scale)
 0                100.000
 1                 91.975
 2                 84.600
 3                 79.914
 4                 76.332
 5                 73.342
 6                 70.704
 7                 68.284
 8                 65.994
 9                 63.776
10                 61.583
11                 59.381
12                 57.140
13                 54.840
14                 52.465
15                 50.012
16                 47.487
17                 44.905
18                 42.281
19                 39.625
20                 36.931
21                 34.174
22                 31.307
23                 28.251
24                 24.875
25                 20.941
26                 15.939
27                  8.291
28                  0.000

Provide a program, function, expression, or source file generator* that given the input raw number returns the interval score number. You may accept your input as a string or number and may produce your output as a string or number. Trailing zeros after the decimal point may be included or omitted. You may not however use scaled integers: 1 must really return 91.975 not 91975.

*source file generator must output a valid source file for some language you specify; just outputting the table is not allowed.

Joshua

Posted 2017-07-15T01:52:49.240

Reputation: 3 043

Note that for some languages, outputting to a file is not possible. I would recommend removing this restriction. – HyperNeutrino – 2017-07-15T01:56:21.403

@HyperNeutrino: 1) It's not a restriction - see the or clause; 2) if they output the source file to stdout that's what I expect anyway. – Joshua – 2017-07-15T01:57:34.087

Oh well I should go to sleep then. I must be blind. :P – HyperNeutrino – 2017-07-15T01:58:02.567

1" I used to be an adventurer like you. Then I took an arrow in the knee." Score: 0.000. – Arnauld – 2017-07-15T10:55:55.063

Answers

3

05AB1E, 59 bytes

•G‚Œιã¶&‡Vc–QΩ`ååI~(Ìö{3.ùSÿ{Ćι¯TærÆcï`₃āÀ}ªHÕ¶η•4ô.¥R3°/Iè

Try it online!

Explanation

•G‚Œιã¶&‡Vc–QΩååI~(Ìö{3.ùSÿ{Ćι¯TærÆcï₃āÀ}ªHÕ¶η• is a compressed version of the input constructed by:

  • multiplying each element in the input by 1000
  • reversing the resulting list
  • calculating deltas
  • joining to a single base-10 number
  • compressing to base-255

The rest of the code is then:

4ô          # split in pieces of 4
  .¥        # undelta
    R       # reverse
     3°/    # divide each by 1000
        Iè  # index into list with input

Emigna

Posted 2017-07-15T01:52:49.240

Reputation: 50 798

1Clever trick with the same-length-4 stuff! – Erik the Outgolfer – 2017-07-15T13:49:38.387

A wild Undelta appears! – Magic Octopus Urn – 2017-07-17T21:12:16.587

1

Python 2, 166 160 139 bytes

lambda n:sum(int('6533222222211111111111222356EWU1LC74210ZYWTRQPOPRV1BRMO6BGYASWNLUSWQ55ZW96XMM8A2I6VX'[i::28],36)for i in range(28-n))/1e3

Try it online!

Edit: golf 6 bytes from glaring redundancy of 2's...; also saved 21 bytes by switch to base 36 (thanks ovs!) and using 1e3 instead of 1000.

The string is an encoded list of the 28 4-digit deltas.

Chas Brown

Posted 2017-07-15T01:52:49.240

Reputation: 8 959

1

PHP, 152 bytes

<?=intval(substr("255s1yyv1ta01pnu1mwc1kla1ik01gos1ex61d7k1bin19th183816bc14hd12l810n30ynd0wmh0ukp0shv0qda0o5n0lsr0j6z0g5p0car06eb0",$argn*4,4),36)/1e3;

Try it online!

Jörg Hülsermann

Posted 2017-07-15T01:52:49.240

Reputation: 13 026

1

Python 3, 133 bytes

lambda k:sum(int('5ukygji75mxo64d3f5vstve68rdiq42l8nof8cs35qyb5bdtzihbhk086m8nel1nx3kqxvn',36)//8292**i%8292for i in range(28-k))/1e3

It uses packed differences, and sums them. To pack efficiently, rather than using binary, it's packed in a number that's effectively base 8292, and that number is embedded in the code as a base 36 literal.

recursive

Posted 2017-07-15T01:52:49.240

Reputation: 8 616

1

Stax, 59 bytes

â¬∟╧↓┘╟╤éJ{súÇaz░«╝╬°╢=♦Γ┘=▐▬[è2Ü←`‼frl¢£≤kpOy‼5¶^≡%#ßî↕V0Å

Run and debug it

recursive

Posted 2017-07-15T01:52:49.240

Reputation: 8 616

0

Mathematica, 196 bytes

(100-Accumulate[{0}~Join~IntegerDigits@9753332322223223323323344578])[[#+1]].{0,975,6,914,332,342,704,284,994,776,583,381,14,84,465,"012",487,905,281,625,931,174,307,251,875,941,939,291,0}[[#+1]]&

J42161217

Posted 2017-07-15T01:52:49.240

Reputation: 15 931

0

Python 3, 147 146 bytes

-1 byte thanks to @JörgHülsermann

lambda k:sum((int('9CU7OK2L6V5W6E8QYM3YL0TRGZIJ6Y14N43TRVCAXF6C58HP69ZC4536JNILBUC45C5S8G4DIT0J',36)&2**(14*-~i)-1)>>i*14for i in range(28-k))/1e3

Try it online!

ovs

Posted 2017-07-15T01:52:49.240

Reputation: 21 408

1e3 instead of 1000 – Jörg Hülsermann – 2017-07-15T14:33:15.823