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.
-
\$\begingroup\$ Note that for some languages, outputting to a file is not possible. I would recommend removing this restriction. \$\endgroup\$hyperneutrino– hyperneutrino ♦2017年07月15日 01:56:21 +00:00Commented 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\$Joshua– Joshua2017年07月15日 01:57:34 +00:00Commented Jul 15, 2017 at 1:57
-
\$\begingroup\$ Oh well I should go to sleep then. I must be blind. :P \$\endgroup\$hyperneutrino– hyperneutrino ♦2017年07月15日 01:58:02 +00:00Commented 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\$Arnauld– Arnauld2017年07月15日 10:55:55 +00:00Commented Jul 15, 2017 at 10:55
7 Answers 7
05AB1E, 59 bytes
•G‚Œιã¶&‡Vc–QΩ`ååI~(Ìö{3.ùSÿ{Ćι ̄TærÆcï`3āÀ}aHÕ¶η•4ô.\R3°/Iè
Explanation
•G‚Œιã¶&‡Vc–QΩ
is a compressed version of the input constructed by:ååI~(Ìö{3.ùSÿ{Ćι ̄TærÆcï
3āÀ}aHÕ¶η•
- 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
-
1\$\begingroup\$ Clever trick with the same-length-4 stuff! \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2017年07月15日 13:49:38 +00:00Commented Jul 15, 2017 at 13:49
-
\$\begingroup\$ A wild
Undelta
appears! \$\endgroup\$Magic Octopus Urn– Magic Octopus Urn2017年07月17日 21:12:16 +00:00Commented Jul 17, 2017 at 21:12
PHP, 152 bytes
<?=intval(substr("255s1yyv1ta01pnu1mwc1kla1ik01gos1ex61d7k1bin19th183816bc14hd12l810n30ynd0wmh0ukp0shv0qda0o5n0lsr0j6z0g5p0car06eb0",$argn*4,4),36)/1e3;
Python 2, (削除) 166 (削除ここまで) (削除) 160 (削除ここまで) 139 bytes
lambda n:sum(int('6533222222211111111111222356EWU1LC74210ZYWTRQPOPRV1BRMO6BGYASWNLUSWQ55ZW96XMM8A2I6VX'[i::28],36)for i in range(28-n))/1e3
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.
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.
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]]&
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
-
\$\begingroup\$
1e3
instead of1000
\$\endgroup\$Jörg Hülsermann– Jörg Hülsermann2017年07月15日 14:33:15 +00:00Commented Jul 15, 2017 at 14:33