6
\$\begingroup\$

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.

sergiol
3,8441 gold badge16 silver badges36 bronze badges
asked Jul 15, 2017 at 1:52
\$\endgroup\$
4
  • \$\begingroup\$ Note that for some languages, outputting to a file is not possible. I would recommend removing this restriction. \$\endgroup\$ Commented Jul 15, 2017 at 1:56
  • \$\begingroup\$ @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. \$\endgroup\$ Commented Jul 15, 2017 at 1:57
  • \$\begingroup\$ Oh well I should go to sleep then. I must be blind. :P \$\endgroup\$ Commented Jul 15, 2017 at 1:58
  • 1
    \$\begingroup\$ " I used to be an adventurer like you. Then I took an arrow in the knee." Score: 0.000. \$\endgroup\$ Commented Jul 15, 2017 at 10:55

7 Answers 7

3
\$\begingroup\$

05AB1E, 59 bytes

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

Try it online!

Explanation

•G‚Œιã¶&‡Vc–QΩååI~(Ìö{3.ùSÿ{Ćι ̄TærÆcï3āÀ}aHÕ¶η• 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
answered Jul 15, 2017 at 8:29
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Clever trick with the same-length-4 stuff! \$\endgroup\$ Commented Jul 15, 2017 at 13:49
  • \$\begingroup\$ A wild Undelta appears! \$\endgroup\$ Commented Jul 17, 2017 at 21:12
1
\$\begingroup\$

PHP, 152 bytes

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

Try it online!

answered Jul 15, 2017 at 14:33
\$\endgroup\$
1
\$\begingroup\$

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.

answered Jul 15, 2017 at 8:11
\$\endgroup\$
0
1
\$\begingroup\$

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.

answered Jul 17, 2017 at 17:28
\$\endgroup\$
1
\$\begingroup\$

Stax, 59 bytes

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

Run and debug it

answered Apr 6, 2018 at 22:09
\$\endgroup\$
0
\$\begingroup\$

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]]&
answered Jul 15, 2017 at 6:44
\$\endgroup\$
0
\$\begingroup\$

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!

answered Jul 15, 2017 at 11:13
\$\endgroup\$
1
  • \$\begingroup\$ 1e3 instead of 1000 \$\endgroup\$ Commented Jul 15, 2017 at 14:33

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.