我找到了一个代码片段,可以在自动化比赛支架生成器中给我想要的东西:一个数组。
但是有一个问题。我不会读也不会写Python,但我精通(足够)Java。 我不知道这是否违反了堆栈溢出的礼仪,但我请求有人协助将此代码转换为Java方法。
因此,数组以两个为一组增加,每两个代表一场比赛。
但是有一个问题。我不会读也不会写Python,但我精通(足够)Java。 我不知道这是否违反了堆栈溢出的礼仪,但我请求有人协助将此代码转换为Java方法。
def CBseed( n ):
#returns list of n in standard tournament seed order
#Note that n need not be a power of 2 - 'byes' are returned as zero
ol = [1]
for i in range( int(ceil( log(n) / log(2) ) )):
l = 2*len(ol) + 1
ol = [e if e <= n else 0 for s in [[el, l-el] for el in ol] for e in s]
return ol
这将返回一个漂亮的结果
2 [1, 2] #seed 1 plays seed 2
3 [1, 0, 2, 3] #seed 1 gets a 'by' game and seed 2 plays seed 3
4 [1, 4, 2, 3] #ETC.
5 [1, 0, 4, 5, 2, 0, 3, 0]
6 [1, 0, 4, 5, 2, 0, 3, 6]
7 [1, 0, 4, 5, 2, 7, 3, 6]
8 [1, 8, 4, 5, 2, 7, 3, 6]
#and so on and so forth till this
31 [1, 0, 16, 17, 8, 25, 9, 24, 4, 29, 13, 20, 5, 28, 12, 21, 2, 31, 15, 18, 7, 26, 10, 23, 3, 30, 14, 19, 6, 27, 11, 22]
32 [1, 32, 16, 17, 8, 25, 9, 24, 4, 29, 13, 20, 5, 28, 12, 21, 2, 31, 15, 18, 7, 26, 10, 23, 3, 30, 14, 19, 6, 27, 11, 22]
因此,数组以两个为一组增加,每两个代表一场比赛。
[e if e <= n else 0 for s in [[el, l-el] for el in ol] for e in s]
,可能会感到有些混乱。 - arshajii[e if e <= n else 0 for el in ol for e in (el, l-el)]
吗?而且我不确定那个for
循环是否必要。 - user2357112