Saucy, Ruby = def saucy(total_degrees, degrees_left, total_people, people_left) current_winner_path = './data/saucy_current_winner' previous_cake_path = './data/saucy_previous_cake' first_move = (total_people == people_left) current_winner = first_move ? 0 : File.read(current_winner_path).to_i previous_cake = first_move ? total_degrees : File.read(previous_cake_path).to_i last_slice = previous_cake - degrees_left current_winner = [current_winner, last_slice].max File.open(previous_cake_path, 'w') { |f| f.puts(degrees_left) } File.open(current_winner_path, 'w'){ |f| f.puts(current_winner) } if first_move degrees_left else average_left = degrees_left.fdiv(people_left).ceil beats_past_players = current_winner + 1 beats_future_players = degrees_left/2 - (people_left-2)*13 [average_left, beats_past_players, beats_future_players].max end end p saucy(*ARGV.map(&:to_i)) Saucy is willing to accept slightly less than half of the remaining cake, so long as it's more than anyone else has gotten or is likely to get (based on secret sauce).