- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
from random import random
from math import log
def championship(champions = 16):
space = ' '
count_of_laps = int(log(champions,2))
koef = [i for i in range(count_of_laps)]
nummer = 1
num_of_champions = []
for i in range(champions):
num_of_champions.append(nummer)
nummer += 2
value_of_champions = [("%.4f" % (random())) for i in range(champions)]
lap0 = []
for i in range(champions):
lap0.append([num_of_champions[i], value_of_champions[i], space*koef[0]])
koef.append(koef[-1]+1)
count_lap = 1
laps = []
for i in range(count_of_laps):
fighter1 = 0
fighter2 = 1
exec(f'lap{count_lap} = []')
while fighter2 <= eval(f'len(lap{count_lap - 1})'):
num_winner = (eval(f'lap{count_lap - 1}[{fighter1}][0]') + eval(f'lap{count_lap - 1}[{fighter2}][0]'))//2
value_winner = max(eval(f'lap{count_lap - 1}[{fighter1}][1]'), eval(f'lap{count_lap - 1}[{fighter2}][1]'))
probel = space*koef[i+1]
winner = [num_winner, value_winner, probel]
exec(f'lap{count_lap}.append({winner})')
fighter1 += 2
fighter2 += 2
count_lap += 1
laps = []
for i in range(count_of_laps+1):
exec(f'laps += lap{i}')
laps.sort()
for i in range(nummer-2):
print(laps[i][2] + str(laps[i][1]))
if __name__ == "__main__":
while True:
value = int(input('Write power of two: '))
print()
if (value & (value - 1)) == 0:
championship(value)
print()
else:
print('not power of two')
Прога воспроизводит турнир между цифрами от 0 до 1. Самое большое побеждает
Комментарии (0) RSS
Добавить комментарий