评级系统限制在 10
Rating system limited at 10
我用这个系统用数字 1-20 分成 20 个组,然后对每个组进行评分以查看它的随机化程度,例如(1,1,1,1)=1 因为只有一种数字,而 (1,2,3,3)=3 因为有 3 个不同的数字。此代码适用于较小的数字并对它们进行排名。然而,当我达到 20 时,即使我的小组声明有超过 10 个不同的数字,评分系统也会达到 10 分?谁能看出为什么这是为了让评分系统达到 10 分的最大值?
import numpy
import random
members=20
n_groups =20
participants=list(range(1,members+1))*n_groups
#print participants
random.shuffle(participants)
with open('myfile1.txt','w') as tf:
for i in range(n_groups):
group = participants[i*members:(i+1)*members]
for participant in group:
tf.write(str(participant)+' ')
tf.write('\n')
with open('myfile1.txt','r') as tf:
g = [list(map(int, line.split())) for line in tf.readlines()]
print(g)
my_groups =g
def get_rating(group):
"""
(tuple of ints)->int
"""
group_str = ""
for each_num in group:
group_str += str(each_num)
return len(set(group_str))
for each_grp in my_groups:
print(get_rating(each_grp))
输出:
[[6, 11, 11, 7, 16, 3, 1, 11, 10, 16, 14, 15, 14, 20, 15, 12, 1, 12, 15, 1], [15, 5, 7, 6, 9, 11, 3, 1, 5, 17, 9, 19, 10, 1, 20, 18, 3, 2, 5, 18], [20, 11, 1, 18, 5, 5, 2, 4, 14, 10, 18, 1, 7, 17, 9, 11, 14, 16, 3, 12], [19, 13, 1, 16, 16, 14, 7, 6, 5, 11, 19, 1, 14, 20, 2, 12, 5, 19, 8, 4], [4, 5, 10, 18, 10, 16, 13, 12, 5, 19, 10, 16, 3, 2, 10, 4, 2, 17, 2, 8], [19, 9, 8, 5, 1, 3, 8, 11, 18, 20, 19, 15, 6, 15, 15, 2, 8, 7, 6, 18], [4, 2, 3, 8, 2, 18, 13, 14, 14, 3, 8, 12, 10, 17, 9, 19, 10, 20, 13, 2], [4, 9, 17, 20, 12, 2, 10, 6, 6, 19, 3, 17, 6, 2, 2, 8, 14, 3, 6, 6], [9, 16, 5, 3, 9, 16, 11, 4, 13, 13, 20, 20, 17, 19, 18, 12, 15, 13, 14, 16], [11, 16, 9, 18, 5, 3, 13, 19, 16, 12, 7, 7, 20, 10, 12, 13, 20, 17, 4, 10], [20, 5, 3, 11, 15, 4, 15, 11, 10, 13, 14, 2, 17, 14, 9, 9, 14, 6, 4, 13], [4, 7, 19, 15, 19, 13, 11, 1, 4, 15, 18, 10, 2, 10, 1, 8, 4, 8, 9, 7], [10, 10, 6, 1, 16, 1, 11, 18, 17, 9, 16, 12, 16, 11, 11, 1, 18, 19, 4, 13], [12, 13, 19, 7, 5, 8, 20, 15, 17, 14, 8, 8, 13, 8, 12, 4, 18, 2, 20, 7], [8, 5, 12, 2, 12, 5, 6, 12, 14, 9, 19, 1, 18, 17, 16, 10, 16, 5, 3, 4], [4, 3, 13, 7, 3, 4, 5, 6, 5, 5, 7, 4, 1, 12, 17, 1, 15, 6, 18, 9], [ 9, 15, 3, 17, 20, 14, 8, 12, 3, 14, 13, 8, 6, 1, 15, 9, 19, 12, 18, 3], [7, 7, 14, 3, 11, 14, 20, 17, 6, 11, 17, 2, 9, 9, 17, 14, 2, 16, 7, 11], [13, 8, 4, 15, 8, 16, 13, 19, 19, 18, 6, 15, 18, 17, 16, 20, 20, 7, 9, 10], [17, 15, 2, 7, 7, 7, 13, 20, 8, 6, 10, 17, 1, 12, 15, 20, 6, 18, 19, 11]]
8个
9
10
10
10
9
8个
9
10
10
9
9
9
9
10
9
10
8个
10
9
注意:每个括号的结束率数字越低越好,但似乎最大为 10,即使我手动计算一些有更多
其他系统:
导入 numpy
随机导入
成员=20
n_groups =20
参与者=列表(范围(1,成员+1))*n_groups
#print 参与者
random.shuffle(参与者)
with open('myfile1.txt','w') as tf:
for i in range(n_groups):
group = participants[i*members:(i+1)*members]
for participant in group:
tf.write(str(participant)+' ')
tf.write('\n')
with open('myfile1.txt','r') as tf:
g = [list(map(int, line.split())) for line in tf.readlines()]
print(g)
my_groups =g
def get_rating(group):
return len(set(group))
print(len(set(group)))
这个returns:
[[11, 9, 8, 3, 2, 13, 7, 17, 7, 2, 3, 2, 17, 8, 5, 4, 6, 12, 1, 16], [3, 4, 7, 5, 17, 16, 16, 20, 1, 5, 16, 5, 4, 11, 11, 4, 20, 15, 8, 12], [6, 3, 15, 14, 5, 17, 1, 10, 13, 10, 4, 20, 5, 15, 17, 6, 9, 17, 13, 6], [11, 5, 11, 20, 2, 2, 10, 6, 18, 13, 6, 16, 18, 16, 7, 2, 3, 8, 11, 15], [18, 15, 8, 1, 16, 16, 14, 3, 19, 14, 1, 17, 12, 6, 4, 3, 3, 12, 12, 20], [19, 16, 12, 2, 15, 8, 8, 18, 20, 6, 13, 1, 13, 19, 8, 16, 17, 8, 3, 20], [9, 5, 11, 18, 1, 16, 18, 10, 16, 17, 4, 2, 2, 5, 5, 7, 8, 5, 10, 3], [18, 4, 9, 11, 9, 9, 14, 1, 4, 19, 17, 10, 12, 18, 8, 13, 5, 14, 12, 17], [20, 13, 4, 7, 13, 10, 1, 2, 6, 11, 7, 9, 13, 10, 7, 14, 6, 8, 9, 17], [14, 13, 15, 14, 14, 20, 2, 19, 2, 13, 13, 6, 8, 10, 7, 12, 9, 8, 17, 19], [1, 12, 10, 20, 5, 15, 4, 3, 19, 16, 13, 1, 6, 10, 2, 6, 17, 1, 5, 19], [7, 7, 13, 8, 11, 9, 12, 13, 2, 16, 18, 19, 4, 12, 8, 15, 9, 13, 2, 17], [20, 18, 15, 11, 14, 8, 4, 3, 4, 16, 4, 14, 19, 19, 6, 11, 7, 2, 13, 14], [9, 14, 18, 7, 17, 15, 5, 9, 12, 18, 19, 1, 20, 12, 10, 3, 10, 6, 18, 10], [10, 10, 7, 7, 3, 11, 10, 20, 15, 16, 17, 5, 20, 12, 9, 20, 2, 7, 18, 1], [19, 5, 5, 19, 11, 3, 15, 1, 9, 19, 19, 1, 11, 7, 16, 3, 8, 12, 20, 11], [8, 2, 18, 15, 18, 14, 19, 8, 5, 10, 16, 20, 4, 14, 7, 6, 18, 17, 6, 3], [4, 9, 2, 6, 15, 16, 17, 14, 12, 19, 16, 2, 12, 3, 9, 17, 9, 7, 19, 11], [20, 5, 4, 19, 1, 4, 11, 15, 13, 15, 11, 14, 14, 11, 7, 9, 12, 9, 10, 3], [1, 14, 20, 6, 6, 15, 12, 1, 4, 15, 15, 1, 13, 18, 14、20、3、18、10、18]]
11 <-(只有一个费率,我要 20 个)
get_rating
功能未正确实现。例如,考虑 get_rating((1, 11))
的输出。您的函数将所有数字连接在一起以获得 '111'
和 returns 唯一字符数 (1
)。只有十个以 10 为基数的数字,所以这是您的最大值。
您只需简化代码即可避免此问题:
def get_rating(group):
return len(set(group))
无需将数字转换为字符串。
我用这个系统用数字 1-20 分成 20 个组,然后对每个组进行评分以查看它的随机化程度,例如(1,1,1,1)=1 因为只有一种数字,而 (1,2,3,3)=3 因为有 3 个不同的数字。此代码适用于较小的数字并对它们进行排名。然而,当我达到 20 时,即使我的小组声明有超过 10 个不同的数字,评分系统也会达到 10 分?谁能看出为什么这是为了让评分系统达到 10 分的最大值?
import numpy
import random
members=20
n_groups =20
participants=list(range(1,members+1))*n_groups
#print participants
random.shuffle(participants)
with open('myfile1.txt','w') as tf:
for i in range(n_groups):
group = participants[i*members:(i+1)*members]
for participant in group:
tf.write(str(participant)+' ')
tf.write('\n')
with open('myfile1.txt','r') as tf:
g = [list(map(int, line.split())) for line in tf.readlines()]
print(g)
my_groups =g
def get_rating(group):
"""
(tuple of ints)->int
"""
group_str = ""
for each_num in group:
group_str += str(each_num)
return len(set(group_str))
for each_grp in my_groups:
print(get_rating(each_grp))
输出: [[6, 11, 11, 7, 16, 3, 1, 11, 10, 16, 14, 15, 14, 20, 15, 12, 1, 12, 15, 1], [15, 5, 7, 6, 9, 11, 3, 1, 5, 17, 9, 19, 10, 1, 20, 18, 3, 2, 5, 18], [20, 11, 1, 18, 5, 5, 2, 4, 14, 10, 18, 1, 7, 17, 9, 11, 14, 16, 3, 12], [19, 13, 1, 16, 16, 14, 7, 6, 5, 11, 19, 1, 14, 20, 2, 12, 5, 19, 8, 4], [4, 5, 10, 18, 10, 16, 13, 12, 5, 19, 10, 16, 3, 2, 10, 4, 2, 17, 2, 8], [19, 9, 8, 5, 1, 3, 8, 11, 18, 20, 19, 15, 6, 15, 15, 2, 8, 7, 6, 18], [4, 2, 3, 8, 2, 18, 13, 14, 14, 3, 8, 12, 10, 17, 9, 19, 10, 20, 13, 2], [4, 9, 17, 20, 12, 2, 10, 6, 6, 19, 3, 17, 6, 2, 2, 8, 14, 3, 6, 6], [9, 16, 5, 3, 9, 16, 11, 4, 13, 13, 20, 20, 17, 19, 18, 12, 15, 13, 14, 16], [11, 16, 9, 18, 5, 3, 13, 19, 16, 12, 7, 7, 20, 10, 12, 13, 20, 17, 4, 10], [20, 5, 3, 11, 15, 4, 15, 11, 10, 13, 14, 2, 17, 14, 9, 9, 14, 6, 4, 13], [4, 7, 19, 15, 19, 13, 11, 1, 4, 15, 18, 10, 2, 10, 1, 8, 4, 8, 9, 7], [10, 10, 6, 1, 16, 1, 11, 18, 17, 9, 16, 12, 16, 11, 11, 1, 18, 19, 4, 13], [12, 13, 19, 7, 5, 8, 20, 15, 17, 14, 8, 8, 13, 8, 12, 4, 18, 2, 20, 7], [8, 5, 12, 2, 12, 5, 6, 12, 14, 9, 19, 1, 18, 17, 16, 10, 16, 5, 3, 4], [4, 3, 13, 7, 3, 4, 5, 6, 5, 5, 7, 4, 1, 12, 17, 1, 15, 6, 18, 9], [ 9, 15, 3, 17, 20, 14, 8, 12, 3, 14, 13, 8, 6, 1, 15, 9, 19, 12, 18, 3], [7, 7, 14, 3, 11, 14, 20, 17, 6, 11, 17, 2, 9, 9, 17, 14, 2, 16, 7, 11], [13, 8, 4, 15, 8, 16, 13, 19, 19, 18, 6, 15, 18, 17, 16, 20, 20, 7, 9, 10], [17, 15, 2, 7, 7, 7, 13, 20, 8, 6, 10, 17, 1, 12, 15, 20, 6, 18, 19, 11]] 8个 9 10 10 10 9 8个 9 10 10 9 9 9 9 10 9 10 8个 10 9
注意:每个括号的结束率数字越低越好,但似乎最大为 10,即使我手动计算一些有更多
其他系统: 导入 numpy 随机导入 成员=20 n_groups =20 参与者=列表(范围(1,成员+1))*n_groups #print 参与者 random.shuffle(参与者)
with open('myfile1.txt','w') as tf:
for i in range(n_groups):
group = participants[i*members:(i+1)*members]
for participant in group:
tf.write(str(participant)+' ')
tf.write('\n')
with open('myfile1.txt','r') as tf:
g = [list(map(int, line.split())) for line in tf.readlines()]
print(g)
my_groups =g
def get_rating(group):
return len(set(group))
print(len(set(group)))
这个returns: [[11, 9, 8, 3, 2, 13, 7, 17, 7, 2, 3, 2, 17, 8, 5, 4, 6, 12, 1, 16], [3, 4, 7, 5, 17, 16, 16, 20, 1, 5, 16, 5, 4, 11, 11, 4, 20, 15, 8, 12], [6, 3, 15, 14, 5, 17, 1, 10, 13, 10, 4, 20, 5, 15, 17, 6, 9, 17, 13, 6], [11, 5, 11, 20, 2, 2, 10, 6, 18, 13, 6, 16, 18, 16, 7, 2, 3, 8, 11, 15], [18, 15, 8, 1, 16, 16, 14, 3, 19, 14, 1, 17, 12, 6, 4, 3, 3, 12, 12, 20], [19, 16, 12, 2, 15, 8, 8, 18, 20, 6, 13, 1, 13, 19, 8, 16, 17, 8, 3, 20], [9, 5, 11, 18, 1, 16, 18, 10, 16, 17, 4, 2, 2, 5, 5, 7, 8, 5, 10, 3], [18, 4, 9, 11, 9, 9, 14, 1, 4, 19, 17, 10, 12, 18, 8, 13, 5, 14, 12, 17], [20, 13, 4, 7, 13, 10, 1, 2, 6, 11, 7, 9, 13, 10, 7, 14, 6, 8, 9, 17], [14, 13, 15, 14, 14, 20, 2, 19, 2, 13, 13, 6, 8, 10, 7, 12, 9, 8, 17, 19], [1, 12, 10, 20, 5, 15, 4, 3, 19, 16, 13, 1, 6, 10, 2, 6, 17, 1, 5, 19], [7, 7, 13, 8, 11, 9, 12, 13, 2, 16, 18, 19, 4, 12, 8, 15, 9, 13, 2, 17], [20, 18, 15, 11, 14, 8, 4, 3, 4, 16, 4, 14, 19, 19, 6, 11, 7, 2, 13, 14], [9, 14, 18, 7, 17, 15, 5, 9, 12, 18, 19, 1, 20, 12, 10, 3, 10, 6, 18, 10], [10, 10, 7, 7, 3, 11, 10, 20, 15, 16, 17, 5, 20, 12, 9, 20, 2, 7, 18, 1], [19, 5, 5, 19, 11, 3, 15, 1, 9, 19, 19, 1, 11, 7, 16, 3, 8, 12, 20, 11], [8, 2, 18, 15, 18, 14, 19, 8, 5, 10, 16, 20, 4, 14, 7, 6, 18, 17, 6, 3], [4, 9, 2, 6, 15, 16, 17, 14, 12, 19, 16, 2, 12, 3, 9, 17, 9, 7, 19, 11], [20, 5, 4, 19, 1, 4, 11, 15, 13, 15, 11, 14, 14, 11, 7, 9, 12, 9, 10, 3], [1, 14, 20, 6, 6, 15, 12, 1, 4, 15, 15, 1, 13, 18, 14、20、3、18、10、18]] 11 <-(只有一个费率,我要 20 个)
get_rating
功能未正确实现。例如,考虑 get_rating((1, 11))
的输出。您的函数将所有数字连接在一起以获得 '111'
和 returns 唯一字符数 (1
)。只有十个以 10 为基数的数字,所以这是您的最大值。
您只需简化代码即可避免此问题:
def get_rating(group):
return len(set(group))
无需将数字转换为字符串。