• Optima Number Calculator in Ruby

    From John Metcalf@21:1/5 to All on Sat Jul 15 19:32:56 2023
    Here's a Ruby implementation of a bomb-free space optima number
    calculator. It's also available (with versions in C and Python) on the
    Optima number page:

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

    # rubyoptima v0.1 - Core War optima number calculator in Ruby by John
    Metcalf
    # using the bomb-free space method
    # Usage: $ irb -r ./optima.rb
    # >> optima(coresize, modulo)

    def optima(coresize, modulo = 1)
    scores = []
    (modulo..coresize / 2).step(modulo) do |step|
    if coresize.gcd(step) == modulo
    score = coresize - 1
    high = low = pos = step
    until pos.zero?
    pos = (pos + step) % coresize
    high = [pos, high].max
    low = [pos, low].min
    score += coresize - high + low - 1
    end
    scores << [score, step]
    end
    end
    puts 'step,score'
    scores.sort.take(20).each { |i| puts i.reverse.join(',') }
    nil
    end

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