Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from itertools import product
- import string
- import random
- from sys import argv
- cols = int(argv[1]) # number of columns
- chars = int(argv[2]) # average number of chars per column
- variation = int(argv[3]) # max +/- variation on # chars per column
- answer_rows = int(argv[4]) # number of answer-key rows
- complexity = int(argv[5]) # maximum complexity (length of any given group of characters in answer)
- printables = [c for c in string.printable if c not in string.whitespace]
- col_options = []
- for col in range(cols):
- random.shuffle(printables)
- nchars_this_column = chars + random.choice(range(-variation, variation+1))
- col_options.append(printables[0:nchars_this_column])
- # generate answer key, from which input will be created
- answer_key = []
- for r in range(answer_rows):
- col_groups = [] # each of the compressed groups, e.g. ['AB', 'XY', 'I']
- for col in range(cols):
- size = min(random.randrange(1,complexity), len(col_options[col]))
- random.shuffle(col_options[col])
- col_groups.append(''.join(col_options[col][:size]))
- answer_key.append(col_groups)
- inputs = []
- for a in answer_key:
- inputs.extend(product(*a))
- random.shuffle(inputs)
- with open('answer.txt', 'w') as f:
- for a in answer_key:
- f.write(' '.join(a) + '\n')
- with open('input.txt', 'w') as f:
- for i in inputs:
- f.write(' '.join(i) + '\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement