4 ms·
Another approach to the 'highest averages' method, using a k9 dict: v: 10400 3400 6200 s: 15 quotients: ,/v%\.5+!s labels: s/!s*#v
by chrispsn 7y ago
Another approach to the 'highest averages' method, using a k9 dict:
v: 10400 3400 6200
s: 15
quotients: ,/v%\.5+!s
labels: s/!s*#v / list of 15x 0, 1, 2. arbitrary; could instead be party names
top: s#>labels!quotients / k dicts can have duplicate keys; can sort items by key(^) or val(<>)
seats: `freq@!top / count appearances of dict's keys
The ability to transform a dict's values while keeping the labels (keys) unchanged - sort, arithmetic, etc - is really powerful.
This answer is longer when minified, but it's faster in 2020.03.27:
\t:100000 +/s>(#v)^<>,/v%/.5+!s ⇒ 1494
\t:100000 `freq@!s#>(s/!s*#v)!,/v%\.5+!s ⇒ 691
- chrispsn 7y agoCorrection: I think the above can be a bit faster and shorter if we skip the dict, and just index into the keys. Compare: \t:100000 `freq@!s#>(s/!s*#v)!,/v%\.5+!s 941 \t:100000 `freq(s/!s*#v)s#>,/v%\.5+!s 901