Skip to content

Instantly share code, notes, and snippets.

@kostasdizas
Last active December 1, 2017 00:23
Show Gist options
  • Save kostasdizas/b77385403d60a292c6fa48c710e33e3f to your computer and use it in GitHub Desktop.
Save kostasdizas/b77385403d60a292c6fa48c710e33e3f to your computer and use it in GitHub Desktop.
Weighted Lottery entry calculator

Weighted entry lottery

Say you are buying tickets for a lottery, but this lottery has been weighed in favour of those with less tickets. The rules are as follows:

  • 1 to 100 tickets = 1 entry per 1 ticket
  • 101 to 500 tickets = 1 entry per 2 tickets
  • 501 to 1000 tikets = 1 entry per 3 tickets
  • 1001 to 1500 tickets = 1 entry per 4 tickets

This formula will give you the number of entries for any number of tickets.

rules = [(1,100,1),(101,500,2), (501,1000,3), (1001,1500,4)]
tickets = 993.9
entries = round(sum([(b-a+1)/c if (tickets>b) else (tickets-a+1)/c for a,b,c in rules if tickets>a]))
print('You have {} entries'.format(entries))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment