class Facility def initialize(val, price, num=0) @val = val @reinforce_price = price @price = price @num = num || 0 end def produce @num * @val end def reinforce(cookie) diff = 0 if cookie >= @reinforce_price diff = -@reinforce_price @reinforce_price *= 10 @val *= 2 end diff end end class Clicker def initialize @cookie = 0 @facilities = {} @history = [] @click = Facility.new(1, 15, 1) [ [:hand, 1, 150], [:lily, 10, 2000], [:factory, 120, 30000], [:casino, 2000, 600000], [:grimoire, 25000, 10000000] ].each do |name, sp, price| @facilities[name] = Facility.new(sp, price) end end def do_action(cmd) @history << cmd case cmd when 'click' @cookie += @click.produce when /\Abuy (.*?)\z/ name = $1.to_sym @cookie += @facilities[name].buy(@cookie) when /\Asell (.*?)\z/ name = $1.to_sym @cookie += @facilities[name].sell(@cookie) when /\Areinforce (.*?)\z/ name = $1.to_sym @cookie += @facilities[name].reinforce(@cookie) when 'enhclick' @cookie += @click.reinforce(@cookie) when 'nothing' # do nothing else raise "Unknown action: '#{cmd}'" end end def do_produce() @facilities.each do |name, f| @cookie += f.produce end end def do_special(type) if type == 'B' # Bonus @cookie += (@cookie+99)/100 elsif type == 'F'# Fever elsif type == 'S' # Sale elsif type == 'N' # Nothing # do nothing else raise end end def run(s) s.each_char.with_index do |ch, turn| if @cookie >= @click.instance_eval{@reinforce_price} do_action("enhclick") else do_action("click") end do_produce() do_special(ch) end @cookie end end n = gets.to_i s = gets.chomp cl = Clicker.new score = cl.run(s) $stderr.puts score cl.instance_eval{@history}.each do |cmd| puts cmd gets end