-
Notifications
You must be signed in to change notification settings - Fork 0
/
pair_gen.py
34 lines (27 loc) · 918 Bytes
/
pair_gen.py
1
2
3
4
5
6
7
8
9
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
from random import randint
def randpairs(probs):
"""
Takes a list of problems and returns a list of random (non-duplicate) pairs
"""
maxidx = len(probs) - 1
randidxs = []
for i in range(len(probs)):
randidx = randint(1, maxidx)
if randidx <= i:
randidx -= 1
randidxs.append((i, randidx))
return [(probs[pair[0]], probs[pair[1]]) for pair in randidxs]
ROUNDS = 3
with open("problems.txt") as f:
probs = [problem.strip() for problem in f]
with open("problem_types.txt") as f:
prob_types = [prob_type.strip() for prob_type in f]
pairs = []
for i in range(ROUNDS):
newpairs = randpairs(probs)
for pair in newpairs:
pairs.append(pair)
with open("problem_pairs.txt", 'w') as f:
for pair in pairs:
f.write(prob_types[randint(0, len(prob_types) - 1)] +
'\n A: ' + pair[0] + '\n B: ' + pair[1] + '\n\n')