Skip to content

Commit 9467848

Browse files
authored
Merge pull request #223 from apasel422/fix
Return final credit assignments from fairly-allocate-credit algorithm
2 parents cc56baa + 70ec146 commit 9467848

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

api.bs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,10 +1701,14 @@ To perform <dfn>common matching logic</dfn>, given
17011701

17021702
<div algorithm>
17031703
To <dfn>fairly allocate credit</dfn>, given a [=list=] of doubles |credit| and an integer |value|:
1704-
1. Multiply each entry in |credit| by |value|.
17051704
1. Let |sumCredit| be the sum of |credit|'s [=list/items=].
1706-
1. Let |rawNormalizedCredit| be the result of element-wise dividing each [=list/item=] in |credit| by |sumCredit|.
1707-
1. Let |normalizedCredit| be |rawNormalizedCredit|, with each [=list/item=] rounded towards positive Infinity and converted to an integer.
1705+
1. Let |rawNormalizedCredit| be a new [=list=].
1706+
1. Let |normalizedCredit| be a new [=list=].
1707+
1. [=list/iterate|For each=] |item| of |credit|:
1708+
1. Let |rawNormalized| be |value| * |item| / |sumCredit|.
1709+
1. [=list/Append=] |rawNormalized| to |rawNormalizedCredit|.
1710+
1. Let |normalized| be |rawNormalized| rounded towards positive Infinity and converted to an integer.
1711+
1. [=list/Append=] |normalized| to |normalizedCredit|.
17081712
1. Let |shuffledFractionalIndices| be [=list/get the indices|the indices=] of |credit|, ordered randomly.
17091713
1. [=list/remove|Remove=] all indices |i| from |shuffledFractionalIndices| where |rawNormalizedCredit|[|i|] has no fractional part.
17101714
1. [=list/iterate|For each=] |index| of |shuffledFractionalIndices|:

0 commit comments

Comments
 (0)