# pyoptima v0.1 - Core War optima number calculator in Python by John Metcalf # using the bomb-free space method # Usage: >>> from optima import optima # >>> optima(coresize, modulo) from math import gcd def optima(coresize, modulo = 1): scores = [] for step in range(modulo, 1 + coresize // 2, modulo): if gcd(coresize, step) == modulo: score = coresize - 1 high = low = pos = step while pos: pos = (pos + step) % coresize high, low = max(pos, high), min(pos, low) score += coresize - high + low - 1 scores.append((step, score)) scores.sort(key = lambda x: x[1]) print('(step, score)') for i in range(20): print(scores[i])