Hi have this code that makes 4 groups until numbers 1-4, then rates them on how good they are:
import numpy
import math
import random
for i in range(3):
# everything is in, see the indentation
members=4
n_groups =4
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):
return len(set(group))
for each_grp in my_groups:
print((get_rating(each_grp)))
print(sum(len(set(x)) for x in my_groups))
This is the output:
[[1, 3, 4, 1], [3, 4, 2, 3], [2, 2, 1, 4], [4, 3, 1, 2]]
3
3
3
4
13
[[3, 4, 2, 1], [1, 1, 2, 4], [2, 3, 3, 2], [3, 4, 4, 1]]
4
3
2
3
12
[[3, 2, 3, 1], [4, 2, 3, 3], [2, 4, 1, 2], [4, 4, 1, 1]]
3
3
3
2
11
The square brackets are the 4 groups, the 4 numbers below rate each group so (1,1,1,1) is very good as has the least changes, whereas (1,2,3,3) is less good as it has 3 different numbers. The final number just sums all the 4 numbers up.
I was wondering if there was a way to display the lowest score with the group combination with all the groups, in this case 11 after i run the trial, this would make it easier if i do more trials like 2000
Aucun commentaire:
Enregistrer un commentaire