#!/usr/bin/env ruby # rubyoptima v0.3 - Core War optima number calculator in Ruby by John Metcalf # using the bomb-free space method - 09/02/2025 # Usage: $ ruby optima3.rb coresize [modulo] coresize = ARGV[0]&.to_i || 8000 modulo = ARGV[1]&.to_i || 1 scores = (1..coresize / 2).select { |step| step.gcd(coresize) == modulo }.map do |step| score = coresize - 1 high = low = pos = step score += coresize - (high = [high, pos = (pos + step) % coresize].max) + (low = [low, pos].min) - 1 until pos.zero? [score, step] end puts 'step,score' scores.min(20).each { |i| puts i.reverse.join(',') }