• Optima Number Calculator in Python

    From John Metcalf@21:1/5 to All on Fri Dec 3 18:12:37 2021
    Here's a short optima number calculator in Python which should be pretty
    easy to translate to other languages. It uses the bomb-free space method.

    Other methods (closest previous hit, distance from midpoint and Fibonacci-
    like gaps) produce almost identical results with a few small differences.

    The code is also available on the optima page with a brief description of
    the other optima algorithms I'm aware of (please let me know if I've
    missed anything):

    https://corewar.co.uk/optima.htm


    # pyoptima v0.1 - Core War optima number calculator in Python
    # 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])

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)