Created
June 21, 2025 18:18
-
-
Save AdamOnza/8103758365a54ade75dac94d87b33fbf to your computer and use it in GitHub Desktop.
Fight numbers. Simulate a game where players rise up and fall down based on "fights", eventually, there is just 1 player per tier. This function finds the number of fights to reach that state.
This file contains hidden or 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
from random import choice, randint, random,shuffle | |
def fightnum(x): | |
tier = [[] for i in range(x)] | |
tier[x//2] = list(range(x)) | |
for fn in range(2_000_000): | |
t = [i for i in range(x) if len(tier[i])>=2] | |
if len(t) == 0: | |
return fn | |
i = choice(t) | |
c = choice(tier[i]) | |
tier[i].remove(c) | |
d = c | |
c = choice(tier[i]) | |
tier[i].remove(c) | |
m = [max(0,i-1),min(x-1,i+1)] | |
shuffle(m) | |
i,j = m | |
tier[i] += [c] | |
tier[j] += [d] | |
raise Exception("Fight number beyond range of fn for loop.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment