各位帮忙看看下面存在哪些算法错误
we uses a statistical approach for prize distribution. It allows a virtually infinite number of prizes to be distributed in prize tiers.
Prizes are distributed through weekly draws:
Each pick is compared to the winning number. How is this done exactly? By breaking each number down into an array of smaller numbers.
Each pick is 256 bits long. Let's interpret the first 32 bits as 8 numbers. This means we have 8 4-bit numbers.
If the pick is 12345678....
, then the first 8 numbers are 1, 2, 3, 4, 5, 6, 7, 8.
We call the number of bits for each number the bit range, and the number of numbers the cardinality. In the above example the bit range is 4 and the cardinality is 8.
Continuing the above example, let's assume the winning number is 123fe678...
. With bit range of 4 and cardinality 8 the first 8 numbers will be 1, 2, 3, f, e, 6, 7, 8.
Let's stack them up side-by-side.
index 0 | index 1 | index 2 | index 3 | index 4 | index 5 | index 6 | index 7 |
---|---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
1 | 2 | 3 | f | e | 6 | 7 | 8 |
The "degree" of the match is the cardinality less the first N matching numbers.
In the above example the first three numbers match:
index 0 | index 1 | index 2 | index 3 | index 4 | index 5 | index 6 | index 7 |
---|---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
1 | 2 | 3 | f | e | 6 | 7 | 8 |
This means that the degree of match is 8 - 3, or five.
The degree of the match is used to determine what tier of prize they won. Tier 0 is the grand prize, Tier 1 is second place, etc.
Given the bit range and the cardinality for a prize distribution, we can calculate the total number of combinations:
number of combinations = (2^bit range)^cardinality
For example, given the above cardinality of 8 and bit range of 4 we'd have:
number of combinations = (2^4)^8 = 4,294,967,296 possible combinations.
There is only 1 combination that matches all 8 winning numbers, so its odds are 1 / 4,294,967,296.
We call the number of combinations the total picks.
Each prize pool is alloted a portion of the total picks proportional to its contribution to the prize network liquidity for the week. If a prize pool contributed 50% of the prize liquidity for the week, then it would be alloted 4,294,967,296 / 2 = 2147483648 picks.
Each user for each prize pool is alloted a portion of the prize pool's picks based on their liquidity provided for the previous week. If a user provided 20% of the liquidity for the above prize pool during the previous week, then they would get 0.2 * 2147483648 = 429496729 picks.
We can compute a user's historic liquidity contribution using their Time-Weighted Average Balance.
If a user has 2000 picks for a draw, that means they are allowed to submit Pick 0 up until Pick 1999. Each's pick is pseudo-randomly generated using the user's address and the pick index.
A user can determine the value of a winning pick based on the degree of the match, the prize distribution, and the total prize. The prize distribution has an array of fractions that determines the portion of the prize allocated to each degree.
For example:
Degree | Percentage |
---|---|
0 | 40% |
1 | 20% |
2 | 40% |
For each degree, we must also calculate the number of combinations that will match that degree so that we can fairly split the portion among the winners.
For degree 0, which is to match all numbers, there will only be 1 combination. So in the above example a degree 0 pick will be awarded 40% of the total prize.
For degree 1, it's a little more complicated. If the bit range is 4, then each number can be one of 2^4, or 16. This means that the number of combinations that are exactly degree 1 are 15: the number of combinations that fall within degree 1 less the number that match degree 0.
This gives us the general formula:
Number of prizes for a degree = (2^bit range)^degree - (2^bit range)^(degree-1) - (2^bit range)^(degree-2) - ...
The prize for each degree must be split among these, so we have:
prize for a degree = total prize * degree percentage / number of prizes for a degree
Each Draw includes: