October 2018
Intermediate to advanced
252 pages
6h 49m
English
questions = [] expected = [] seen = set() print('Generating data...') while len(questions) < TRAINING_SIZE: f = lambda: int(''.join(np.random.choice(list('0123456789')) for i in range(np.random.randint(1, DIGITS + 1)))) a, b = f(), f() # Skip any subtraction questions we've already seen # Also skip any such that x-Y == Y-x (hence the sorting). key = tuple(sorted((a, b))) if key in seen: continue seen.add(key) # Pad the data with spaces such that it is always MAXLEN. q = '{}-{}'.format(a, b) query = q + ' ' * (MAXLEN - len(q)) ans = str(a - b) # Answers can be of maximum ...