Created
June 17, 2021 19:54
-
-
Save stefanopepe/12bf6909ddc3eeac411d9ac4ed4f734f to your computer and use it in GitHub Desktop.
NEAR Seat Calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
staked = [39083288,20742627,17605710,14958721,12372225,11736051,11700857,10766231,10192733,9247144,8829467,8820923,8607624,7496028,7440797,7072148,6658986,6646311,6613536,6200873,6044540,5535635,5514813,5441478,5390617,5058487,5042476,5037097,5007809,4993358,4953007,4891731,4723753,4478417,4406591,4275230,4261006,4193711,4119969,4112941,4053846,4008247,3854746,3807783,3783853,3772500,3724032,3697405,3666975,3664753,3650362,3595469,3589451,3580855,3562831,3515380,3449636,3432393,3430539,3338958,3155647,2124049] | |
def findSeatPrice(stakes, num_seats): | |
""" | |
Find seat price given set of stakes and number of seats required. | |
Seat price is highest integer number such that if you sum `floor(stakes[i] / seat_price)` it is at least `num_seats`. | |
""" | |
stakes = sorted(stakes) | |
total_stakes = sum(stakes) | |
assert total_stakes >= num_seats, "Total stakes should be above number of seats" | |
left, right = 1, total_stakes + 1 | |
while True: | |
if left == right - 1: | |
return left | |
mid = (left + right) // 2 | |
found = False; | |
currentSum = 0 | |
for stake in stakes: | |
currentSum += stake // mid | |
if currentSum >= num_seats: | |
left = mid | |
found = True; | |
break | |
if not found: | |
print(currentSum, mid) | |
right = mid | |
print(findSeatPrice(staked,100)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add the staking entries in the
staked
array, and change the integer100
to the number of seats available