| 
 
| 赞 | 0 |  
| VIP | 0 |  
| 好人卡 | 1 |  
| 积分 | 1 |  
| 经验 | 2446 |  
| 最后登录 | 2016-9-12 |  
| 在线时间 | 21 小时 |  
 Lv1.梦旅人 
	梦石0 星屑50 在线时间21 小时注册时间2011-8-22帖子13 | 
6楼
 
 
 楼主|
发表于 2012-3-11 20:23:56
|
只看该作者 
| 本帖最后由 lotsofone 于 2012-12-1 19:57 编辑 
 更新,24点破解器V2.0.4出来了,修正了V2.0的已经找到的bug。2.0相比1.0,新版支持分数计算,比如1.0不能解出1 5 5 5,V2.0能解出(5-1÷5)×5,3 3 8 8也是其中一个。在破解上,V1.0采用的方法是设定一个字符串"((a~b)~c)~d",并把加减乘除号代入"~"中,后来又添加了(a~b)~(c~d),但还是不能求出所有接;V2.0采用了一个更智能化的方法,把4个化3个,3个化2个,就求出了所有解法。唯一的缺点就是速度变得稍慢。1.0平均每个需要0.39337秒,2.0为每个0.64414秒。
 
   
  24点破解器 V2.0.5.rar
(969.3 KB, 下载次数: 57) 脚本如下,顺便感谢一下 orzfly 解答我的脚本问题。
 为能完整显示,脚本分成三段。
 如果有修正bug等改动脚本的操作使得文件包的脚本和下面的脚本不同,请以下面的脚本为准。最新更新时间2012-10-1。
 
 #==============================================================================# ■ Cache#------------------------------------------------------------------------------#  本模组载入所有图像,建立并保存Bitmap物件。为加快载入速度并节省内存,#  本模组将以建立的bitmap物件保存在内部哈希表中,使得程序在需求已存在#  的图像时能快速读取bitmap物件。#============================================================================== module Cache  #--------------------------------------------------------------------------  # * 获取动画图档  #     filename : 文件名  #     hue      : 色调  #--------------------------------------------------------------------------  def self.animation(filename, hue)    load_bitmap("Graphics/Animations/", filename, hue)  end  #--------------------------------------------------------------------------  # * 获取战斗图图档  #     filename : 文件名  #     hue      : 色调  #--------------------------------------------------------------------------  def self.battler(filename, hue)    load_bitmap("Graphics/Battlers/", filename, hue)  end  #--------------------------------------------------------------------------  # * 获取角色行走图图档  #     filename : 文件名  #--------------------------------------------------------------------------  def self.character(filename)    load_bitmap("Graphics/Characters/", filename)  end  #--------------------------------------------------------------------------  # * 获取头像图档  #     filename : 文件名  #--------------------------------------------------------------------------  def self.face(filename)    load_bitmap("Graphics/Faces/", filename)  end  #--------------------------------------------------------------------------  # * 获取远景图档  #     filename : 文件名  #--------------------------------------------------------------------------  def self.parallax(filename)    load_bitmap("Graphics/Parallaxes/", filename)  end  #--------------------------------------------------------------------------  # * 获取图片图档  #     filename : 文件名  #--------------------------------------------------------------------------  def self.picture(filename)    load_bitmap("Graphics/Pictures/", filename)  end  #--------------------------------------------------------------------------  # * 获取系统图档  #     filename : 文件名  #--------------------------------------------------------------------------  def self.system(filename)    load_bitmap("Graphics/System/", filename)  end  #--------------------------------------------------------------------------  # * 清除Cache  #--------------------------------------------------------------------------  def self.clear    @cache = {} if @cache == nil    @cache.clear    GC.start  end  #--------------------------------------------------------------------------  # * 载入图档  #--------------------------------------------------------------------------  def self.load_bitmap(folder_name, filename, hue = 0)    @cache = {} if @cache == nil    path = folder_name + filename    if not @cache.include?(path) or @cache[path].disposed?      if filename.empty?        @cache[path] = Bitmap.new(32, 32)      else        @cache[path] = Bitmap.new(path)      end    end    if hue == 0      return @cache[path]    else      key = [path, hue]      if not @cache.include?(key) or @cache[key].disposed?        @cache[key] = @cache[path].clone        @cache[key].hue_change(hue)      end      return @cache[key]    end  endend
#============================================================================== 
# ■ Cache 
#------------------------------------------------------------------------------ 
#  本模组载入所有图像,建立并保存Bitmap物件。为加快载入速度并节省内存, 
#  本模组将以建立的bitmap物件保存在内部哈希表中,使得程序在需求已存在 
#  的图像时能快速读取bitmap物件。 
#============================================================================== 
  
module Cache 
  #-------------------------------------------------------------------------- 
  # * 获取动画图档 
  #     filename : 文件名 
  #     hue      : 色调 
  #-------------------------------------------------------------------------- 
  def self.animation(filename, hue) 
    load_bitmap("Graphics/Animations/", filename, hue) 
  end 
  #-------------------------------------------------------------------------- 
  # * 获取战斗图图档 
  #     filename : 文件名 
  #     hue      : 色调 
  #-------------------------------------------------------------------------- 
  def self.battler(filename, hue) 
    load_bitmap("Graphics/Battlers/", filename, hue) 
  end 
  #-------------------------------------------------------------------------- 
  # * 获取角色行走图图档 
  #     filename : 文件名 
  #-------------------------------------------------------------------------- 
  def self.character(filename) 
    load_bitmap("Graphics/Characters/", filename) 
  end 
  #-------------------------------------------------------------------------- 
  # * 获取头像图档 
  #     filename : 文件名 
  #-------------------------------------------------------------------------- 
  def self.face(filename) 
    load_bitmap("Graphics/Faces/", filename) 
  end 
  #-------------------------------------------------------------------------- 
  # * 获取远景图档 
  #     filename : 文件名 
  #-------------------------------------------------------------------------- 
  def self.parallax(filename) 
    load_bitmap("Graphics/Parallaxes/", filename) 
  end 
  #-------------------------------------------------------------------------- 
  # * 获取图片图档 
  #     filename : 文件名 
  #-------------------------------------------------------------------------- 
  def self.picture(filename) 
    load_bitmap("Graphics/Pictures/", filename) 
  end 
  #-------------------------------------------------------------------------- 
  # * 获取系统图档 
  #     filename : 文件名 
  #-------------------------------------------------------------------------- 
  def self.system(filename) 
    load_bitmap("Graphics/System/", filename) 
  end 
  #-------------------------------------------------------------------------- 
  # * 清除Cache 
  #-------------------------------------------------------------------------- 
  def self.clear 
    @cache = {} if @cache == nil 
    @cache.clear 
    GC.start 
  end 
  #-------------------------------------------------------------------------- 
  # * 载入图档 
  #-------------------------------------------------------------------------- 
  def self.load_bitmap(folder_name, filename, hue = 0) 
    @cache = {} if @cache == nil 
    path = folder_name + filename 
    if not @cache.include?(path) or @cache[path].disposed? 
      if filename.empty? 
        @cache[path] = Bitmap.new(32, 32) 
      else 
        @cache[path] = Bitmap.new(path) 
      end 
    end 
    if hue == 0 
      return @cache[path] 
    else 
      key = [path, hue] 
      if not @cache.include?(key) or @cache[key].disposed? 
        @cache[key] = @cache[path].clone 
        @cache[key].hue_change(hue) 
      end 
      return @cache[key] 
    end 
  end 
end 
 #==============================================================================# ■ Window_Base#------------------------------------------------------------------------------#  游戏中全部窗口的超级类。#============================================================================== class Window_Base < Window  #--------------------------------------------------------------------------  # ● 常量  #--------------------------------------------------------------------------  WLH = 24                  # 窗口行高(Window Line Height)  #--------------------------------------------------------------------------  # ● 初始化对像  #     x      : 窗口 X 座标  #     y      : 窗口 Y 座标  #     width  : 窗口宽度  #     height : 窗口高度  #--------------------------------------------------------------------------  def initialize(x, y, width, height)    super()    self.windowskin = Cache.system("Window")    self.x = x    self.y = y    self.width = width    self.height = height    self.z = 100    self.back_opacity = 200    self.openness = 255    create_contents    @opening = false    @closing = false  end  #--------------------------------------------------------------------------  # ● 释放  #--------------------------------------------------------------------------  def dispose    self.contents.dispose    super  end  #--------------------------------------------------------------------------  # ● 生成窗口内容  #--------------------------------------------------------------------------  def create_contents    self.contents.dispose    self.contents = Bitmap.new(width - 32, height - 32)  end  #--------------------------------------------------------------------------  # ● 更新画面  #--------------------------------------------------------------------------  def update    super    if @opening      self.openness += 48      @opening = false if self.openness == 255    elsif @closing      self.openness -= 48      @closing = false if self.openness == 0    end  end  #--------------------------------------------------------------------------  # ● 打开窗口  #--------------------------------------------------------------------------  def open    @opening = true if self.openness < 255    @closing = false  end  #--------------------------------------------------------------------------  # ● 关闭窗口  #--------------------------------------------------------------------------  def close    @closing = true if self.openness > 0    @opening = false  end  #--------------------------------------------------------------------------  # ● 获取文字颜色  #     n : 文字颜色色号(0-31)  #--------------------------------------------------------------------------  def text_color(n)    x = 64 + (n % 8) * 8    y = 96 + (n / 8) * 8    return windowskin.get_pixel(x, y)  end  #--------------------------------------------------------------------------  # ● 获取一般文字颜色  #--------------------------------------------------------------------------  def normal_color    return text_color(0)  end  #--------------------------------------------------------------------------  # ● 获取系统文字颜色  #--------------------------------------------------------------------------  def system_color    return text_color(16)  end  #--------------------------------------------------------------------------  # ● 获取危机文字颜色  #--------------------------------------------------------------------------  def crisis_color    return text_color(17)  end  #--------------------------------------------------------------------------  # ● 获取战斗不能文字颜色  #--------------------------------------------------------------------------  def knockout_color    return text_color(18)  end  #--------------------------------------------------------------------------  # ● 获取变量条背景颜色  #--------------------------------------------------------------------------  def gauge_back_color    return text_color(19)  end  #--------------------------------------------------------------------------  # ● 获取体力值槽颜色1  #--------------------------------------------------------------------------  def hp_gauge_color1    return text_color(20)  end  #--------------------------------------------------------------------------  # ● 获取体力值槽颜色2  #--------------------------------------------------------------------------  def hp_gauge_color2    return text_color(21)  end  #--------------------------------------------------------------------------  # ● 获取魔力值槽颜色1  #--------------------------------------------------------------------------  def mp_gauge_color1    return text_color(22)  end  #--------------------------------------------------------------------------  # ● 获取魔力值槽颜色2  #--------------------------------------------------------------------------  def mp_gauge_color2    return text_color(23)  end  #--------------------------------------------------------------------------  # ● 获取装备画面能力值上升颜色  #--------------------------------------------------------------------------  def power_up_color    return text_color(24)  end  #--------------------------------------------------------------------------  # ● 获取装备画面能力值下降颜色  #--------------------------------------------------------------------------  def power_down_color    return text_color(25)  end  #--------------------------------------------------------------------------  # ● 会制图标  #     icon_index : 图标号  #     x     : 描画目标 X 坐标  #     y     : 描画目标 Y 坐标  #     enabled    : 有效化标志,为 false 时则图标半透明化。  #--------------------------------------------------------------------------  def draw_icon(icon_index, x, y, enabled = true)    bitmap = Cache.system("Iconset")    rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)    self.contents.blt(x, y, bitmap, rect, enabled ? 255 : 128)  end  #--------------------------------------------------------------------------  # ● 绘制头像  #     face_name  : 头像文件名  #     face_index : 头像号码  #     x     : 描画目标 X 坐标  #     y     : 描画目标 Y 坐标  #     size       : 显示大小  #--------------------------------------------------------------------------  def draw_face(face_name, face_index, x, y, size = 96)    bitmap = Cache.face(face_name)    rect = Rect.new(0, 0, 0, 0)    rect.x = face_index % 4 * 96 + (96 - size) / 2    rect.y = face_index / 4 * 96 + (96 - size) / 2    rect.width = size    rect.height = size    self.contents.blt(x, y, bitmap, rect)    bitmap.dispose  end  #--------------------------------------------------------------------------  # ● 绘制行走图  #     character_name  : 行走图文件名  #     character_index : 行走图号码  #     x     : 描画目标 X 坐标  #     y     : 描画目标 Y 坐标  #--------------------------------------------------------------------------  def draw_character(character_name, character_index, x, y)    return if character_name == nil    bitmap = Cache.character(character_name)    sign = character_name[/^[\!\$]./]    if sign != nil and sign.include?('$')      cw = bitmap.width / 3      ch = bitmap.height / 4    else      cw = bitmap.width / 12      ch = bitmap.height / 8    end    n = character_index    src_rect = Rect.new((n%4*3+1)*cw, (n/4*4)*ch, cw, ch)    self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)  end  #--------------------------------------------------------------------------  # ● 获取体力文字颜色  #     actor : 角色  #--------------------------------------------------------------------------  def hp_color(actor)    return knockout_color if actor.hp == 0    return crisis_color if actor.hp < actor.maxhp / 4    return normal_color  end  #--------------------------------------------------------------------------  # ● 获取魔力文字颜色  #     actor : 角色  #--------------------------------------------------------------------------  def mp_color(actor)    return crisis_color if actor.mp < actor.maxmp / 4    return normal_color  end  #--------------------------------------------------------------------------  # ● 绘制角色行走图  #     actor : 角色  #     x     : 描画目标 X 坐标  #     y     : 描画目标 Y 坐标  #--------------------------------------------------------------------------  def draw_actor_graphic(actor, x, y)    draw_character(actor.character_name, actor.character_index, x, y)  end  #--------------------------------------------------------------------------  # ● 绘制角色头像  #     actor : 角色  #     x     : 描画目标 X 坐标  #     y     : 描画目标 Y 坐标  #     size  : 绘制大小  #--------------------------------------------------------------------------  def draw_actor_face(actor, x, y, size = 96)    draw_face(actor.face_name, actor.face_index, x, y, size)  end  #--------------------------------------------------------------------------  # ● 绘制角色名称  #     actor : 角色  #     x     : 描画目标 X 坐标  #     y     : 描画目标 Y 坐标  #--------------------------------------------------------------------------  def draw_actor_name(actor, x, y)    self.contents.font.color = hp_color(actor)    self.contents.draw_text(x, y, 108, WLH, actor.name)  end  #--------------------------------------------------------------------------  # ● 绘制角色职业  #     actor : 角色  #     x     : 描画目标 X 坐标  #     y     : 描画目标 Y 坐标  #--------------------------------------------------------------------------  def draw_actor_class(actor, x, y)    self.contents.font.color = normal_color    self.contents.draw_text(x, y, 108, WLH, actor.class.name)  end  #--------------------------------------------------------------------------  # ● 绘制角色等级  #     actor : 角色  #     x     : 描画目标 X 坐标  #     y     : 描画目标 Y 坐标  #--------------------------------------------------------------------------  def draw_actor_level(actor, x, y)    self.contents.font.color = system_color    self.contents.draw_text(x, y, 32, WLH, Vocab::level_a)    self.contents.font.color = normal_color    self.contents.draw_text(x + 32, y, 24, WLH, actor.level, 2)  end  #--------------------------------------------------------------------------  # ● 绘制角色状态  #     actor : 角色  #     x     : 描画目标 X 坐标  #     y     : 描画目标 Y 坐标  #     width : 描画目标宽度  #--------------------------------------------------------------------------  def draw_actor_state(actor, x, y, width = 96)    count = 0    for state in actor.states      draw_icon(state.icon_index, x + 24 * count, y)      count += 1      break if (24 * count > width - 24)    end  end  #--------------------------------------------------------------------------  # ● 绘制角色体力  #     actor : 角色  #     x     : 描画目标 X 坐标  #     y     : 描画目标 Y 坐标  #     width : 描画目标宽度  #--------------------------------------------------------------------------  def draw_actor_hp(actor, x, y, width = 120)    draw_actor_hp_gauge(actor, x, y, width)    self.contents.font.color = system_color    self.contents.draw_text(x, y, 30, WLH, Vocab::hp_a)    self.contents.font.color = hp_color(actor)    last_font_size = self.contents.font.size    xr = x + width    if width < 120      self.contents.draw_text(xr - 44, y, 44, WLH, actor.hp, 2)    else      self.contents.draw_text(xr - 99, y, 44, WLH, actor.hp, 2)      self.contents.font.color = normal_color      self.contents.draw_text(xr - 55, y, 11, WLH, "/", 2)      self.contents.draw_text(xr - 44, y, 44, WLH, actor.maxhp, 2)    end  end  #--------------------------------------------------------------------------  # ● 绘制角色体力值槽  #     actor : 角色  #     x     : 描画目标 X 坐标  #     y     : 描画目标 Y 坐标  #     width : 描画目标宽度  #--------------------------------------------------------------------------  def draw_actor_hp_gauge(actor, x, y, width = 120)    gw = width * actor.hp / actor.maxhp    gc1 = hp_gauge_color1    gc2 = hp_gauge_color2    self.contents.fill_rect(x, y + WLH - 8, width, 6, gauge_back_color)    self.contents.gradient_fill_rect(x, y + WLH - 8, gw, 6, gc1, gc2)  end  #--------------------------------------------------------------------------  # ● 绘制角色魔力  #     actor : 角色  #     x     : 描画目标 X 坐标  #     y     : 描画目标 Y 坐标  #     width : 描画目标宽度  #--------------------------------------------------------------------------  def draw_actor_mp(actor, x, y, width = 120)    draw_actor_mp_gauge(actor, x, y, width)    self.contents.font.color = system_color    self.contents.draw_text(x, y, 30, WLH, Vocab::mp_a)    self.contents.font.color = mp_color(actor)    last_font_size = self.contents.font.size    xr = x + width    if width < 120      self.contents.draw_text(xr - 44, y, 44, WLH, actor.mp, 2)    else      self.contents.draw_text(xr - 99, y, 44, WLH, actor.mp, 2)      self.contents.font.color = normal_color      self.contents.draw_text(xr - 55, y, 11, WLH, "/", 2)      self.contents.draw_text(xr - 44, y, 44, WLH, actor.maxmp, 2)    end  end  #--------------------------------------------------------------------------  # ● 绘制角色魔力值槽  #     actor : 角色  #     x     : 描画目标 X 坐标  #     y     : 描画目标 Y 坐标  #     width : 描画目标宽度  #--------------------------------------------------------------------------  def draw_actor_mp_gauge(actor, x, y, width = 120)    gw = width * actor.mp / [actor.maxmp, 1].max    gc1 = mp_gauge_color1    gc2 = mp_gauge_color2    self.contents.fill_rect(x, y + WLH - 8, width, 6, gauge_back_color)    self.contents.gradient_fill_rect(x, y + WLH - 8, gw, 6, gc1, gc2)  end  #--------------------------------------------------------------------------  # ● 绘制角色能力值  #     actor : 角色  #     x     : 描画目标 X 坐标  #     y     : 描画目标 Y 坐标  #     type  : 能力值类型(0-3)  #--------------------------------------------------------------------------  def draw_actor_parameter(actor, x, y, type)    case type    when 0      parameter_name = Vocab::atk      parameter_value = actor.atk    when 1      parameter_name = Vocab::def      parameter_value = actor.def    when 2      parameter_name = Vocab::spi      parameter_value = actor.spi    when 3      parameter_name = Vocab::agi      parameter_value = actor.agi    end    self.contents.font.color = system_color    self.contents.draw_text(x, y, 120, WLH, parameter_name)    self.contents.font.color = normal_color    self.contents.draw_text(x + 120, y, 36, WLH, parameter_value, 2)  end  #--------------------------------------------------------------------------  # ● 绘制物品  #     item    : 物品(技能、武器、防具也合用)  #     x       : 描画目标 X 坐标  #     y       : 描画目标 Y 坐标  #     enabled : 有效化标志,为 false 时则物品半透明化。  #--------------------------------------------------------------------------  def draw_item_name(item, x, y, enabled = true)    if item != nil      draw_icon(item.icon_index, x, y, enabled)      self.contents.font.color = normal_color      self.contents.font.color.alpha = enabled ? 255 : 128      self.contents.draw_text(x + 24, y, 172, WLH, item.name)    end  end  #--------------------------------------------------------------------------  # ● 绘制金钱单位  #     value : 数目  #     x     : 描画目标 X 坐标  #     y     : 描画目标 Y 坐标  #     width : 描画目标宽度  #--------------------------------------------------------------------------  def draw_currency_value(value, x, y, width)    cx = contents.text_size(Vocab::gold).width    self.contents.font.color = normal_color    self.contents.draw_text(x, y, width-cx-2, WLH, value, 2)    self.contents.font.color = system_color    self.contents.draw_text(x, y, width, WLH, Vocab::gold, 2)  endendclass Window_Setable < Window_Base  attr_accessor :item_id, :item_set, :sets  def initialize(x, y, width, height, sets)    super(x, y, width, height)    self.sets = sets    self.item_id = 0    self.active = true    self.cursor_rect = sets[0][0]    self.item_set = []    for i in 0...sets.size      self.item_set[i] = sets[0][2]    end    for i in 0...self.sets.size      rect = self.sets[i][0]      str = self.sets[i][1][self.item_set[i]]      self.contents.draw_text(rect, str)    end  end  def update    super    if Input.trigger?(Input::RIGHT) or Input.repeat?(Input::RIGHT)      self.item_id += 1      if self.item_id >= self.sets.size        self.item_id -= self.sets.size      end      @moved_lr = true    end    if Input.trigger?(Input::LEFT) or Input.repeat?(Input::LEFT)      self.item_id -= 1      if self.item_id < 0        self.item_id += self.sets.size      end      @moved_lr = true    end    self.cursor_rect = sets[item_id][0]    if Input.trigger?(Input::UP) or Input.repeat?(Input::UP)      self.item_set[item_id] += 1      if self.item_set[item_id] >= self.sets[item_id][1].size        self.item_set[item_id] -= self.sets[item_id][1].size      end      @moved_ud = true    end    if Input.trigger?(Input::DOWN) or Input.repeat?(Input::DOWN)      self.item_set[item_id] -= 1      if self.item_set[item_id] < 0        self.item_set[item_id] += self.sets[item_id][1].size      end      @moved_ud = true    end    return true if !@moved_ud    self.contents.clear    for i in 0...self.sets.size      rect = self.sets[i][0]      str = self.sets[i][1][self.item_set[i]]      self.contents.draw_text(rect, str)    end    self.cursor_rect = sets[self.item_id][0]    @moved_lr = false    @moved_ud = false    def dispose      super      $windows.delete_at($windows.size-1)    end  endendclass Window_Input < Window_Setable  def initialize(x, y, width, height, sets)    super    @result_window = Window_Result.new(0, 96, 544, 416-96)    @compare_item_id = self.item_id    @compare_item_set = []    self.contents.draw_text(Rect.new(0, 0, 544-32, 32), "请设定4个数:(方向键操作)")    for i in 0...self.item_set.size      @compare_item_set[i] = self.item_set[i]    end  end  def update    super    return true if @compare_item_set == self.item_set    @result_window.update    @compare_item_set = []    for i in 0...self.item_set.size      @compare_item_set[i] = self.item_set[i]    end    self.contents.draw_text(Rect.new(0, 0, 544-32, 32), "请设定4个数:(方向键操作)")  endendclass Window_Result < Window_Base  def author    return "lotsofone"  end  def initialize(x, y, width, height)    super    self.contents.draw_text(Rect.new(390, 250, 140, 24), "by "+author)  end  def update    super    self.contents.clear    number_a = $windows[0].sets[0][1][$windows[0].item_set[0]]    number_b = $windows[0].sets[1][1][$windows[0].item_set[1]]    number_c = $windows[0].sets[2][1][$windows[0].item_set[2]]    number_d = $windows[0].sets[3][1][$windows[0].item_set[3]]    problem = Problem.new(number_a.to_i, number_b.to_i, number_c.to_i, number_d.to_i)    array = problem.get_way    x = 0    n = 0    str_array = [""]    for i in 0...array.size      str_array[n] << "     " if x%3 != 0      str_array[n] << array[i]      x += 1      if x%3 == 0        n += 1        str_array[n] = ""      end    end    self.contents.draw_text(Rect.new(0, 0, 544-32, 32), "解法:")    for i in 0...str_array.size      self.contents.draw_text(Rect.new(0, 32*i+32, 544-32, 32), str_array[i])    end    if array.size == 0      self.contents.draw_text(Rect.new(0, 32, 544-32, 32), "无解")    end    self.contents.draw_text(Rect.new(390, 250, 140, 24), "by "+author)  endend#------------------------------------------------------#------------------------------------------------------def deepcopy(input)  begin Marshal.load Marshal.dump input rescue input.map { |i| i.is_a?(Array) ? deepcopy(i) : (begin i.clone rescue i end) } endend
#============================================================================== 
# ■ Window_Base 
#------------------------------------------------------------------------------ 
#  游戏中全部窗口的超级类。 
#============================================================================== 
  
class Window_Base < Window 
  #-------------------------------------------------------------------------- 
  # ● 常量 
  #-------------------------------------------------------------------------- 
  WLH = 24                  # 窗口行高(Window Line Height) 
  #-------------------------------------------------------------------------- 
  # ● 初始化对像 
  #     x      : 窗口 X 座标 
  #     y      : 窗口 Y 座标 
  #     width  : 窗口宽度 
  #     height : 窗口高度 
  #-------------------------------------------------------------------------- 
  def initialize(x, y, width, height) 
    super() 
    self.windowskin = Cache.system("Window") 
    self.x = x 
    self.y = y 
    self.width = width 
    self.height = height 
    self.z = 100 
    self.back_opacity = 200 
    self.openness = 255 
    create_contents 
    @opening = false 
    @closing = false 
  end 
  #-------------------------------------------------------------------------- 
  # ● 释放 
  #-------------------------------------------------------------------------- 
  def dispose 
    self.contents.dispose 
    super 
  end 
  #-------------------------------------------------------------------------- 
  # ● 生成窗口内容 
  #-------------------------------------------------------------------------- 
  def create_contents 
    self.contents.dispose 
    self.contents = Bitmap.new(width - 32, height - 32) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 更新画面 
  #-------------------------------------------------------------------------- 
  def update 
    super 
    if @opening 
      self.openness += 48 
      @opening = false if self.openness == 255 
    elsif @closing 
      self.openness -= 48 
      @closing = false if self.openness == 0 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # ● 打开窗口 
  #-------------------------------------------------------------------------- 
  def open 
    @opening = true if self.openness < 255 
    @closing = false 
  end 
  #-------------------------------------------------------------------------- 
  # ● 关闭窗口 
  #-------------------------------------------------------------------------- 
  def close 
    @closing = true if self.openness > 0 
    @opening = false 
  end 
  #-------------------------------------------------------------------------- 
  # ● 获取文字颜色 
  #     n : 文字颜色色号(0-31) 
  #-------------------------------------------------------------------------- 
  def text_color(n) 
    x = 64 + (n % 8) * 8 
    y = 96 + (n / 8) * 8 
    return windowskin.get_pixel(x, y) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 获取一般文字颜色 
  #-------------------------------------------------------------------------- 
  def normal_color 
    return text_color(0) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 获取系统文字颜色 
  #-------------------------------------------------------------------------- 
  def system_color 
    return text_color(16) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 获取危机文字颜色 
  #-------------------------------------------------------------------------- 
  def crisis_color 
    return text_color(17) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 获取战斗不能文字颜色 
  #-------------------------------------------------------------------------- 
  def knockout_color 
    return text_color(18) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 获取变量条背景颜色 
  #-------------------------------------------------------------------------- 
  def gauge_back_color 
    return text_color(19) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 获取体力值槽颜色1 
  #-------------------------------------------------------------------------- 
  def hp_gauge_color1 
    return text_color(20) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 获取体力值槽颜色2 
  #-------------------------------------------------------------------------- 
  def hp_gauge_color2 
    return text_color(21) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 获取魔力值槽颜色1 
  #-------------------------------------------------------------------------- 
  def mp_gauge_color1 
    return text_color(22) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 获取魔力值槽颜色2 
  #-------------------------------------------------------------------------- 
  def mp_gauge_color2 
    return text_color(23) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 获取装备画面能力值上升颜色 
  #-------------------------------------------------------------------------- 
  def power_up_color 
    return text_color(24) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 获取装备画面能力值下降颜色 
  #-------------------------------------------------------------------------- 
  def power_down_color 
    return text_color(25) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 会制图标 
  #     icon_index : 图标号 
  #     x     : 描画目标 X 坐标 
  #     y     : 描画目标 Y 坐标 
  #     enabled    : 有效化标志,为 false 时则图标半透明化。 
  #-------------------------------------------------------------------------- 
  def draw_icon(icon_index, x, y, enabled = true) 
    bitmap = Cache.system("Iconset") 
    rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24) 
    self.contents.blt(x, y, bitmap, rect, enabled ? 255 : 128) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 绘制头像 
  #     face_name  : 头像文件名 
  #     face_index : 头像号码 
  #     x     : 描画目标 X 坐标 
  #     y     : 描画目标 Y 坐标 
  #     size       : 显示大小 
  #-------------------------------------------------------------------------- 
  def draw_face(face_name, face_index, x, y, size = 96) 
    bitmap = Cache.face(face_name) 
    rect = Rect.new(0, 0, 0, 0) 
    rect.x = face_index % 4 * 96 + (96 - size) / 2 
    rect.y = face_index / 4 * 96 + (96 - size) / 2 
    rect.width = size 
    rect.height = size 
    self.contents.blt(x, y, bitmap, rect) 
    bitmap.dispose 
  end 
  #-------------------------------------------------------------------------- 
  # ● 绘制行走图 
  #     character_name  : 行走图文件名 
  #     character_index : 行走图号码 
  #     x     : 描画目标 X 坐标 
  #     y     : 描画目标 Y 坐标 
  #-------------------------------------------------------------------------- 
  def draw_character(character_name, character_index, x, y) 
    return if character_name == nil 
    bitmap = Cache.character(character_name) 
    sign = character_name[/^[\!\$]./] 
    if sign != nil and sign.include?('$') 
      cw = bitmap.width / 3 
      ch = bitmap.height / 4 
    else 
      cw = bitmap.width / 12 
      ch = bitmap.height / 8 
    end 
    n = character_index 
    src_rect = Rect.new((n%4*3+1)*cw, (n/4*4)*ch, cw, ch) 
    self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 获取体力文字颜色 
  #     actor : 角色 
  #-------------------------------------------------------------------------- 
  def hp_color(actor) 
    return knockout_color if actor.hp == 0 
    return crisis_color if actor.hp < actor.maxhp / 4 
    return normal_color 
  end 
  #-------------------------------------------------------------------------- 
  # ● 获取魔力文字颜色 
  #     actor : 角色 
  #-------------------------------------------------------------------------- 
  def mp_color(actor) 
    return crisis_color if actor.mp < actor.maxmp / 4 
    return normal_color 
  end 
  #-------------------------------------------------------------------------- 
  # ● 绘制角色行走图 
  #     actor : 角色 
  #     x     : 描画目标 X 坐标 
  #     y     : 描画目标 Y 坐标 
  #-------------------------------------------------------------------------- 
  def draw_actor_graphic(actor, x, y) 
    draw_character(actor.character_name, actor.character_index, x, y) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 绘制角色头像 
  #     actor : 角色 
  #     x     : 描画目标 X 坐标 
  #     y     : 描画目标 Y 坐标 
  #     size  : 绘制大小 
  #-------------------------------------------------------------------------- 
  def draw_actor_face(actor, x, y, size = 96) 
    draw_face(actor.face_name, actor.face_index, x, y, size) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 绘制角色名称 
  #     actor : 角色 
  #     x     : 描画目标 X 坐标 
  #     y     : 描画目标 Y 坐标 
  #-------------------------------------------------------------------------- 
  def draw_actor_name(actor, x, y) 
    self.contents.font.color = hp_color(actor) 
    self.contents.draw_text(x, y, 108, WLH, actor.name) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 绘制角色职业 
  #     actor : 角色 
  #     x     : 描画目标 X 坐标 
  #     y     : 描画目标 Y 坐标 
  #-------------------------------------------------------------------------- 
  def draw_actor_class(actor, x, y) 
    self.contents.font.color = normal_color 
    self.contents.draw_text(x, y, 108, WLH, actor.class.name) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 绘制角色等级 
  #     actor : 角色 
  #     x     : 描画目标 X 坐标 
  #     y     : 描画目标 Y 坐标 
  #-------------------------------------------------------------------------- 
  def draw_actor_level(actor, x, y) 
    self.contents.font.color = system_color 
    self.contents.draw_text(x, y, 32, WLH, Vocab::level_a) 
    self.contents.font.color = normal_color 
    self.contents.draw_text(x + 32, y, 24, WLH, actor.level, 2) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 绘制角色状态 
  #     actor : 角色 
  #     x     : 描画目标 X 坐标 
  #     y     : 描画目标 Y 坐标 
  #     width : 描画目标宽度 
  #-------------------------------------------------------------------------- 
  def draw_actor_state(actor, x, y, width = 96) 
    count = 0 
    for state in actor.states 
      draw_icon(state.icon_index, x + 24 * count, y) 
      count += 1 
      break if (24 * count > width - 24) 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # ● 绘制角色体力 
  #     actor : 角色 
  #     x     : 描画目标 X 坐标 
  #     y     : 描画目标 Y 坐标 
  #     width : 描画目标宽度 
  #-------------------------------------------------------------------------- 
  def draw_actor_hp(actor, x, y, width = 120) 
    draw_actor_hp_gauge(actor, x, y, width) 
    self.contents.font.color = system_color 
    self.contents.draw_text(x, y, 30, WLH, Vocab::hp_a) 
    self.contents.font.color = hp_color(actor) 
    last_font_size = self.contents.font.size 
    xr = x + width 
    if width < 120 
      self.contents.draw_text(xr - 44, y, 44, WLH, actor.hp, 2) 
    else 
      self.contents.draw_text(xr - 99, y, 44, WLH, actor.hp, 2) 
      self.contents.font.color = normal_color 
      self.contents.draw_text(xr - 55, y, 11, WLH, "/", 2) 
      self.contents.draw_text(xr - 44, y, 44, WLH, actor.maxhp, 2) 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # ● 绘制角色体力值槽 
  #     actor : 角色 
  #     x     : 描画目标 X 坐标 
  #     y     : 描画目标 Y 坐标 
  #     width : 描画目标宽度 
  #-------------------------------------------------------------------------- 
  def draw_actor_hp_gauge(actor, x, y, width = 120) 
    gw = width * actor.hp / actor.maxhp 
    gc1 = hp_gauge_color1 
    gc2 = hp_gauge_color2 
    self.contents.fill_rect(x, y + WLH - 8, width, 6, gauge_back_color) 
    self.contents.gradient_fill_rect(x, y + WLH - 8, gw, 6, gc1, gc2) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 绘制角色魔力 
  #     actor : 角色 
  #     x     : 描画目标 X 坐标 
  #     y     : 描画目标 Y 坐标 
  #     width : 描画目标宽度 
  #-------------------------------------------------------------------------- 
  def draw_actor_mp(actor, x, y, width = 120) 
    draw_actor_mp_gauge(actor, x, y, width) 
    self.contents.font.color = system_color 
    self.contents.draw_text(x, y, 30, WLH, Vocab::mp_a) 
    self.contents.font.color = mp_color(actor) 
    last_font_size = self.contents.font.size 
    xr = x + width 
    if width < 120 
      self.contents.draw_text(xr - 44, y, 44, WLH, actor.mp, 2) 
    else 
      self.contents.draw_text(xr - 99, y, 44, WLH, actor.mp, 2) 
      self.contents.font.color = normal_color 
      self.contents.draw_text(xr - 55, y, 11, WLH, "/", 2) 
      self.contents.draw_text(xr - 44, y, 44, WLH, actor.maxmp, 2) 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # ● 绘制角色魔力值槽 
  #     actor : 角色 
  #     x     : 描画目标 X 坐标 
  #     y     : 描画目标 Y 坐标 
  #     width : 描画目标宽度 
  #-------------------------------------------------------------------------- 
  def draw_actor_mp_gauge(actor, x, y, width = 120) 
    gw = width * actor.mp / [actor.maxmp, 1].max 
    gc1 = mp_gauge_color1 
    gc2 = mp_gauge_color2 
    self.contents.fill_rect(x, y + WLH - 8, width, 6, gauge_back_color) 
    self.contents.gradient_fill_rect(x, y + WLH - 8, gw, 6, gc1, gc2) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 绘制角色能力值 
  #     actor : 角色 
  #     x     : 描画目标 X 坐标 
  #     y     : 描画目标 Y 坐标 
  #     type  : 能力值类型(0-3) 
  #-------------------------------------------------------------------------- 
  def draw_actor_parameter(actor, x, y, type) 
    case type 
    when 0 
      parameter_name = Vocab::atk 
      parameter_value = actor.atk 
    when 1 
      parameter_name = Vocab::def 
      parameter_value = actor.def 
    when 2 
      parameter_name = Vocab::spi 
      parameter_value = actor.spi 
    when 3 
      parameter_name = Vocab::agi 
      parameter_value = actor.agi 
    end 
    self.contents.font.color = system_color 
    self.contents.draw_text(x, y, 120, WLH, parameter_name) 
    self.contents.font.color = normal_color 
    self.contents.draw_text(x + 120, y, 36, WLH, parameter_value, 2) 
  end 
  #-------------------------------------------------------------------------- 
  # ● 绘制物品 
  #     item    : 物品(技能、武器、防具也合用) 
  #     x       : 描画目标 X 坐标 
  #     y       : 描画目标 Y 坐标 
  #     enabled : 有效化标志,为 false 时则物品半透明化。 
  #-------------------------------------------------------------------------- 
  def draw_item_name(item, x, y, enabled = true) 
    if item != nil 
      draw_icon(item.icon_index, x, y, enabled) 
      self.contents.font.color = normal_color 
      self.contents.font.color.alpha = enabled ? 255 : 128 
      self.contents.draw_text(x + 24, y, 172, WLH, item.name) 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # ● 绘制金钱单位 
  #     value : 数目 
  #     x     : 描画目标 X 坐标 
  #     y     : 描画目标 Y 坐标 
  #     width : 描画目标宽度 
  #-------------------------------------------------------------------------- 
  def draw_currency_value(value, x, y, width) 
    cx = contents.text_size(Vocab::gold).width 
    self.contents.font.color = normal_color 
    self.contents.draw_text(x, y, width-cx-2, WLH, value, 2) 
    self.contents.font.color = system_color 
    self.contents.draw_text(x, y, width, WLH, Vocab::gold, 2) 
  end 
end 
class Window_Setable < Window_Base 
  attr_accessor :item_id, :item_set, :sets 
  def initialize(x, y, width, height, sets) 
    super(x, y, width, height) 
    self.sets = sets 
    self.item_id = 0 
    self.active = true 
    self.cursor_rect = sets[0][0] 
    self.item_set = [] 
    for i in 0...sets.size 
      self.item_set[i] = sets[0][2] 
    end 
    for i in 0...self.sets.size 
      rect = self.sets[i][0] 
      str = self.sets[i][1][self.item_set[i]] 
      self.contents.draw_text(rect, str) 
    end 
  end 
  def update 
    super 
    if Input.trigger?(Input::RIGHT) or Input.repeat?(Input::RIGHT) 
      self.item_id += 1 
      if self.item_id >= self.sets.size 
        self.item_id -= self.sets.size 
      end 
      @moved_lr = true 
    end 
    if Input.trigger?(Input::LEFT) or Input.repeat?(Input::LEFT) 
      self.item_id -= 1 
      if self.item_id < 0 
        self.item_id += self.sets.size 
      end 
      @moved_lr = true 
    end 
    self.cursor_rect = sets[item_id][0] 
    if Input.trigger?(Input::UP) or Input.repeat?(Input::UP) 
      self.item_set[item_id] += 1 
      if self.item_set[item_id] >= self.sets[item_id][1].size 
        self.item_set[item_id] -= self.sets[item_id][1].size 
      end 
      @moved_ud = true 
    end 
    if Input.trigger?(Input::DOWN) or Input.repeat?(Input::DOWN) 
      self.item_set[item_id] -= 1 
      if self.item_set[item_id] < 0 
        self.item_set[item_id] += self.sets[item_id][1].size 
      end 
      @moved_ud = true 
    end 
    return true if !@moved_ud 
    self.contents.clear 
    for i in 0...self.sets.size 
      rect = self.sets[i][0] 
      str = self.sets[i][1][self.item_set[i]] 
      self.contents.draw_text(rect, str) 
    end 
    self.cursor_rect = sets[self.item_id][0] 
    @moved_lr = false 
    @moved_ud = false 
    def dispose 
      super 
      $windows.delete_at($windows.size-1) 
    end 
  end 
end 
class Window_Input < Window_Setable 
  def initialize(x, y, width, height, sets) 
    super 
    @result_window = Window_Result.new(0, 96, 544, 416-96) 
    @compare_item_id = self.item_id 
    @compare_item_set = [] 
    self.contents.draw_text(Rect.new(0, 0, 544-32, 32), "请设定4个数:(方向键操作)") 
    for i in 0...self.item_set.size 
      @compare_item_set[i] = self.item_set[i] 
    end 
  end 
  def update 
    super 
    return true if @compare_item_set == self.item_set 
    @result_window.update 
    @compare_item_set = [] 
    for i in 0...self.item_set.size 
      @compare_item_set[i] = self.item_set[i] 
    end 
    self.contents.draw_text(Rect.new(0, 0, 544-32, 32), "请设定4个数:(方向键操作)") 
  end 
end 
class Window_Result < Window_Base 
  def author 
    return "lotsofone" 
  end 
  def initialize(x, y, width, height) 
    super 
    self.contents.draw_text(Rect.new(390, 250, 140, 24), "by "+author) 
  end 
  def update 
    super 
    self.contents.clear 
    number_a = $windows[0].sets[0][1][$windows[0].item_set[0]] 
    number_b = $windows[0].sets[1][1][$windows[0].item_set[1]] 
    number_c = $windows[0].sets[2][1][$windows[0].item_set[2]] 
    number_d = $windows[0].sets[3][1][$windows[0].item_set[3]] 
    problem = Problem.new(number_a.to_i, number_b.to_i, number_c.to_i, number_d.to_i) 
    array = problem.get_way 
    x = 0 
    n = 0 
    str_array = [""] 
    for i in 0...array.size 
      str_array[n] << "     " if x%3 != 0 
      str_array[n] << array[i] 
      x += 1 
      if x%3 == 0 
        n += 1 
        str_array[n] = "" 
      end 
    end 
    self.contents.draw_text(Rect.new(0, 0, 544-32, 32), "解法:") 
    for i in 0...str_array.size 
      self.contents.draw_text(Rect.new(0, 32*i+32, 544-32, 32), str_array[i]) 
    end 
    if array.size == 0 
      self.contents.draw_text(Rect.new(0, 32, 544-32, 32), "无解") 
    end 
    self.contents.draw_text(Rect.new(390, 250, 140, 24), "by "+author) 
  end 
end 
#------------------------------------------------------ 
#------------------------------------------------------ 
def deepcopy(input) 
  begin Marshal.load Marshal.dump input rescue input.map { |i| i.is_a?(Array) ? deepcopy(i) : (begin i.clone rescue i end) } end 
end 
 class Problem  private  def equal_value    return 24 #必须大于0  end  def break_24_2(a, b)#以字符串输入    returns = []    s1 = a+"+"+b    s2 = a+"-"+b    s3 = a+"*"+b    s4 = a+"/"+b    s5 = b+"-"+a    s6 = b+"/"+a    returns.push(s1) if (eval(s1) - equal_value).abs < 0.00001    returns.push(s2) if (eval(s2) - equal_value).abs < 0.00001    returns.push(s3) if (eval(s3) - equal_value).abs < 0.00001    returns.push(s4) if (eval(s4) - equal_value).abs < 0.00001    returns.push(s5) if (eval(s5) - equal_value).abs < 0.00001    returns.push(s6) if (eval(s6) - equal_value).abs < 0.00001    return returns  end  def break_24_3(a, b, c)#以字符串输入    string_array = [a, b, c]    returns = []    for x in 0..2      for y in (x+1)..2        for s in 0..2          next if s == x or s == y          string = string_array[s]        end        e_string1 = string_array[x]        e_string2 = string_array[y]        e1 = "("+e_string1+"+"+e_string2+")"        e2 = "("+e_string1+"-"+e_string2+")"        e3 = "("+e_string1+"*"+e_string2+")"        e4 = "("+e_string1+"/"+e_string2+")"        e5 = "("+e_string2+"-"+e_string1+")"        e6 = "("+e_string2+"/"+e_string1+")"        returns.concat(break_24_2(string, e1))        returns.concat(break_24_2(string, e2))        returns.concat(break_24_2(string, e3))        returns.concat(break_24_2(string, e4))        returns.concat(break_24_2(string, e5))        returns.concat(break_24_2(string, e6))      end    end    return returns  end  def break_24(a, b, c, d)#以整数输入    number_array = [a, b, c, d]    returns = []    for x in 0..3      for y in (x+1)..3        for n1 in 0..3          if n1 != x and n1 != y            number1 = number_array[n1].to_f.to_s            for n2 in 0..3              if n2 != x and n2 != y and n2 != n1                number2 = number_array[n2].to_f.to_s                break              end            end            break          end        end        e_number1 = number_array[x].to_f.to_s        e_number2 = number_array[y].to_f.to_s        e1 = "("+e_number1+"+"+e_number2+")"        e2 = "("+e_number1+"-"+e_number2+")"        e3 = "("+e_number1+"*"+e_number2+")"        e4 = "("+e_number1+"/"+e_number2+")"        e5 = "("+e_number2+"-"+e_number1+")"        e6 = "("+e_number2+"/"+e_number1+")"        returns += break_24_3(number1, number2, e1)        returns += break_24_3(number1, number2, e2)        returns += break_24_3(number1, number2, e3)        returns += break_24_3(number1, number2, e4)        returns += break_24_3(number1, number2, e5)        returns += break_24_3(number1, number2, e6)      end    end    return returns  end  def make_sure_operators_type(array, i)    if array[i] == "*" or array[i] == "/"      return 2    elsif array[i] == "+" or array[i] == "-"      return 1    else      return 0     end  end  def put_in_order_3(array, x, y, z)    deals = []    for i in 0...array.size      deals << array[i]    end    s0 = deals[x[0]]+deals[x[1]]    s1 = deals[y[0]]+deals[y[1]]    s2 = deals[z[0]]+deals[z[1]]    string_array = quick_soft([s0, s1, s2])    deals[x[0]] = string_array[0][0, 1]    deals[x[1]] = string_array[0][1, string_array[0].size-1]    deals[y[0]] = string_array[1][0, 1]    deals[y[1]] = string_array[1][1, string_array[1].size-1]    deals[z[0]] = string_array[2][0, 1]    deals[z[1]] = string_array[2][1, string_array[2].size-1]    return deals  end  def put_in_order_2(array, x, y)    deals = []    for i in 0...array.size      deals << array[i]    end    s0 = deals[x[0]]+deals[x[1]]    s1 = deals[y[0]]+deals[y[1]]    string_array = quick_soft([s0, s1])    deals[x[0]] = string_array[0][0, 1]    deals[x[1]] = string_array[0][1, string_array[0].size-1]    deals[y[0]] = string_array[1][0, 1]    deals[y[1]] = string_array[1][1, string_array[1].size-1]    return deals  end  def deal(way)    way = Math.clear_bracket(way)    way = Math.put_in_order(way)    for i in 0...way.size      case way[i,1]      when "*"        way[i,1] = "×"      when "/"        way[i,1] = "÷"      end    end    return way  end  public  def initialize(a, b, c, d)#abcd都必须大于0    way = break_24(a, b, c, d)    for i in 0...way.size      way[i] = deal(way[i])    end    i = 0    while i < way.size      ds = i+1      while ds < way.size        if way[i] == way[ds]          way.delete_at(ds)          ds -= 1        end        ds += 1      end      i += 1    end    @way = deepcopy(way)  end  def get_way    return @way  endendmodule Math  def self.clear_bracket_a(array_input)#去括号化简    array = []    for i in 0...array_input.size      array << array_input[i]    end    if array.include?("(") #带有括号      left = 0      while left < array.size        if array[left] == "("          right = left + 1          nop = 1          dop = 1          while right < array.size            if array[right] == "("              nop += 1              dop += 1            end            if array[right] == ")"              dop -= 1              if dop == 0#意思是两个括号在同一个层次                re_calls = []                for i in (left+1)...right                  re_calls << array[i]                end                gets = clear_bracket_a(re_calls)                if gets.size == 1                  if array[left-1] == "*"                    array[left..right] = gets                  elsif array[left-1] == "/"                    deep = 0                    for i in 0...gets.size                      if gets[i] == "("                        deep += 1                      elsif gets[i] == ")"                        deep -= 1                      end                      if deep == 0                        if gets[i] == "*"                          gets[i] = "/"                        elsif gets[i] == "/"                          gets[i] = "*"                        end                      end                    end                  end                else                  if array[right+1] != "*" and array[right+1] != "/"                    if array[left-1] == "+"                      array[left..right] = gets                    elsif array[left-1] == "-"                      for i in 0...gets.size                        if gets[i] == "+"                          gets[i] = "-"                        elsif gets[i] == "-"                          gets[i] = "+"                        end                      end                      array[left..right] = gets                    elsif left == 0 #此分支于2012-3-18添加,修正了                      array[left..right] = gets                    else                      str = "("                      for i in 0...gets.size                        str << gets[i]                      end                      str << ")"                      array[left..right] = str                    end                  else                    str = "("                    for i in 0...gets.size                      str << gets[i]                    end                    str << ")"                    array[left..right] = str                  end                end#~                 array.faltten!                break              end            end            right += 1          end        end        left += 1      end#合并成单项式+-单项式……的形式。      returns = []      i = 0      returns << ""      loop do        loop do          break if array[0] == "+" or array[0] == "-" or array.size <= 0          returns[i] << array[0]          array.delete_at(0)        end        break if array.size <= 0        if returns[i] != ""          i += 1          returns << ""        end        returns[i] << array[0]        array.delete_at(0)        i += 1        returns << ""      end      return returns    else#没有括号了,就合并成单项式+-单项式+-单项式……的形式      returns = []      i = 0      returns << ""      loop do        loop do          break if array[0] == "+" or array[0] == "-" or array.size <= 0          returns[i] << array[0]          array.delete_at(0)        end        break if array.size <= 0        if returns[i] != ""          i += 1          returns << ""        end        returns[i] << array[0]        array.delete_at(0)        i += 1        returns << ""      end      return returns    end  end  def self.clear_bracket(string_input)    array = split_math(string_input)    array = clear_bracket_a(array)    returns = ""    for i in 0...array.size      returns << array[i]    end    return returns  end  def self.put_in_order_array_1(array_input)#无括号的部分#~     array = array_input.clone    array=deepcopy(array_input)    times_array = Array.new    t = 0    times_array[t] = []    for i in 0...array.size      if array[i] == "+" or array[i] == "-"        t+=1        times_array[t] = [array[i]]        t+=1        times_array[t] = []      else        times_array[t] << array[i]      end    end    for i in 0...times_array.size      times_array[i] = put_in_order_array_1_1(times_array[i])    end    returns = put_in_order_array_1_2(times_array)    return returns  end  def self.put_in_order_array_1_1(input0)#以array输入   */计算排序(无括号)    input = input0.clone    if input.class != Array      return input    end    timers = [input[0]]    dividers = []    for i in 1..(input.size-1)/2      if input[i*2-1] == "*"        timers << input[i*2]      elsif input[i*2-1] == "/"        dividers << input[i*2]      end    end    dividers = quick_soft(dividers)    timers = quick_soft(timers)    returns = timers[0]     for i in 1...timers.size      next unless timers[i]      returns << "*"      returns << timers[i]    end    for i in 0...dividers.size      next unless dividers[i]      returns << "/"      returns << dividers[i]    end    return returns  end  def self.put_in_order_array_1_2(input)#以array输入   +-计算排序(无括号)    addtions = [input[0]]    minus = []    for i in 1..(input.size-1)/2      if input[i*2-1] == "+"        addtions << input[i*2]      elsif input[i*2-1] == "-"        minus << input[i*2]      end    end    minus = quick_soft(minus)    addtions = quick_soft(addtions)    returns = addtions[0]    for i in 1...addtions.size      next unless addtions[i]      returns << "+"      returns << addtions[i]    end    for i in 0...minus.size      next unless minus[i]      returns << "-"      returns << minus[i]    end    return returns  end    def self.put_in_order_array(array_input)    array = deepcopy(array_input)    if array.include?("(")      left = 0      while left < array.size        if array[left] == "("          right = left+1          d = 1          while right < array.size            if array[right] == "("              d += 1            end            if array[right] == ")"              d -= 1              if d == 0                tr = put_in_order_array(array[left+1..right-1])                if tr                  array[left..right] = "(" + tr + ")"                else                  array[left..right] = nil                  array.delete_at(left)                end                break              end            end            right += 1          end        end        left += 1      end    end    string = put_in_order_array_1(array)    return string  end   def self.put_in_order(string)    array = split_math(string)    return put_in_order_array(array)  endenddef split_math(string)  array = string.split(//)  i = 0  numbers = %w(0 1 2 3 4 5 6 7 8 9)  while i < array.size    if numbers.include?(array[i])      n = i+1      loop do        break unless numbers.include?(array[n])        array[i] << array[n]        array.delete_at(n)      end    end    i += 1  end  return arrayenddef quick_soft(array)#快速排序法  x = array[0]  array_small = []  array_else = []  for i in 1...array.size    if array[i] < x      array_small << array[i]    else      array_else << array[i] #被分成array_small 、 x 和 array_else    end  end  if array_small.size == 0    returns1 = []  elsif array_small.size == 1    returns1 = [array_small[0]]  else    returns1 = quick_soft(array_small)  end  if array_else.size == 0    returns3 = []  elsif array_else.size == 1    returns3 = [array_else[0]]  else    returns3 = quick_soft(array_else)  end  returns2 = [x]  return returns1 + returns2 + returns3end#------------------------------------------------------#------------------------------------------------------Font.default_name = ["SimHei", "黑体", "DFKai-SB", "標楷體", "Verdana", "Arial Unicode MS"]$equal_value=24Graphics.freezearray = []for i in 0..12  array[i] = (i+1).to_sendsets = []set_now = 0for i in 0..3  sets[i] = [Rect.new(0+(i*272/3), 32, 32, 32), array, set_now]end$windows = [Window_Input.new(0, 0, 336, 96, sets)]Graphics.transition(30)loop do  Graphics.update  Input.update  $windows[$windows.size-1].update if $windows[0]end
class Problem 
  private 
  def equal_value 
    return 24 #必须大于0 
  end 
  def break_24_2(a, b)#以字符串输入 
    returns = [] 
    s1 = a+"+"+b 
    s2 = a+"-"+b 
    s3 = a+"*"+b 
    s4 = a+"/"+b 
    s5 = b+"-"+a 
    s6 = b+"/"+a 
    returns.push(s1) if (eval(s1) - equal_value).abs < 0.00001 
    returns.push(s2) if (eval(s2) - equal_value).abs < 0.00001 
    returns.push(s3) if (eval(s3) - equal_value).abs < 0.00001 
    returns.push(s4) if (eval(s4) - equal_value).abs < 0.00001 
    returns.push(s5) if (eval(s5) - equal_value).abs < 0.00001 
    returns.push(s6) if (eval(s6) - equal_value).abs < 0.00001 
    return returns 
  end 
  def break_24_3(a, b, c)#以字符串输入 
    string_array = [a, b, c] 
    returns = [] 
    for x in 0..2 
      for y in (x+1)..2 
        for s in 0..2 
          next if s == x or s == y 
          string = string_array[s] 
        end 
        e_string1 = string_array[x] 
        e_string2 = string_array[y] 
        e1 = "("+e_string1+"+"+e_string2+")" 
        e2 = "("+e_string1+"-"+e_string2+")" 
        e3 = "("+e_string1+"*"+e_string2+")" 
        e4 = "("+e_string1+"/"+e_string2+")" 
        e5 = "("+e_string2+"-"+e_string1+")" 
        e6 = "("+e_string2+"/"+e_string1+")" 
        returns.concat(break_24_2(string, e1)) 
        returns.concat(break_24_2(string, e2)) 
        returns.concat(break_24_2(string, e3)) 
        returns.concat(break_24_2(string, e4)) 
        returns.concat(break_24_2(string, e5)) 
        returns.concat(break_24_2(string, e6)) 
      end 
    end 
    return returns 
  end 
  def break_24(a, b, c, d)#以整数输入 
    number_array = [a, b, c, d] 
    returns = [] 
    for x in 0..3 
      for y in (x+1)..3 
        for n1 in 0..3 
          if n1 != x and n1 != y 
            number1 = number_array[n1].to_f.to_s 
            for n2 in 0..3 
              if n2 != x and n2 != y and n2 != n1 
                number2 = number_array[n2].to_f.to_s 
                break 
              end 
            end 
            break 
          end 
        end 
        e_number1 = number_array[x].to_f.to_s 
        e_number2 = number_array[y].to_f.to_s 
        e1 = "("+e_number1+"+"+e_number2+")" 
        e2 = "("+e_number1+"-"+e_number2+")" 
        e3 = "("+e_number1+"*"+e_number2+")" 
        e4 = "("+e_number1+"/"+e_number2+")" 
        e5 = "("+e_number2+"-"+e_number1+")" 
        e6 = "("+e_number2+"/"+e_number1+")" 
        returns += break_24_3(number1, number2, e1) 
        returns += break_24_3(number1, number2, e2) 
        returns += break_24_3(number1, number2, e3) 
        returns += break_24_3(number1, number2, e4) 
        returns += break_24_3(number1, number2, e5) 
        returns += break_24_3(number1, number2, e6) 
      end 
    end 
    return returns 
  end 
  def make_sure_operators_type(array, i) 
    if array[i] == "*" or array[i] == "/" 
      return 2 
    elsif array[i] == "+" or array[i] == "-" 
      return 1 
    else 
      return 0  
    end 
  end 
  def put_in_order_3(array, x, y, z) 
    deals = [] 
    for i in 0...array.size 
      deals << array[i] 
    end 
    s0 = deals[x[0]]+deals[x[1]] 
    s1 = deals[y[0]]+deals[y[1]] 
    s2 = deals[z[0]]+deals[z[1]] 
    string_array = quick_soft([s0, s1, s2]) 
    deals[x[0]] = string_array[0][0, 1] 
    deals[x[1]] = string_array[0][1, string_array[0].size-1] 
    deals[y[0]] = string_array[1][0, 1] 
    deals[y[1]] = string_array[1][1, string_array[1].size-1] 
    deals[z[0]] = string_array[2][0, 1] 
    deals[z[1]] = string_array[2][1, string_array[2].size-1] 
    return deals 
  end 
  def put_in_order_2(array, x, y) 
    deals = [] 
    for i in 0...array.size 
      deals << array[i] 
    end 
    s0 = deals[x[0]]+deals[x[1]] 
    s1 = deals[y[0]]+deals[y[1]] 
    string_array = quick_soft([s0, s1]) 
    deals[x[0]] = string_array[0][0, 1] 
    deals[x[1]] = string_array[0][1, string_array[0].size-1] 
    deals[y[0]] = string_array[1][0, 1] 
    deals[y[1]] = string_array[1][1, string_array[1].size-1] 
    return deals 
  end 
  def deal(way) 
    way = Math.clear_bracket(way) 
    way = Math.put_in_order(way) 
    for i in 0...way.size 
      case way[i,1] 
      when "*" 
        way[i,1] = "×" 
      when "/" 
        way[i,1] = "÷" 
      end 
    end 
    return way 
  end 
  public 
  def initialize(a, b, c, d)#abcd都必须大于0 
    way = break_24(a, b, c, d) 
    for i in 0...way.size 
      way[i] = deal(way[i]) 
    end 
    i = 0 
    while i < way.size 
      ds = i+1 
      while ds < way.size 
        if way[i] == way[ds] 
          way.delete_at(ds) 
          ds -= 1 
        end 
        ds += 1 
      end 
      i += 1 
    end 
    @way = deepcopy(way) 
  end 
  def get_way 
    return @way 
  end 
end 
module Math 
  def self.clear_bracket_a(array_input)#去括号化简 
    array = [] 
    for i in 0...array_input.size 
      array << array_input[i] 
    end 
    if array.include?("(") #带有括号 
      left = 0 
      while left < array.size 
        if array[left] == "(" 
          right = left + 1 
          nop = 1 
          dop = 1 
          while right < array.size 
            if array[right] == "(" 
              nop += 1 
              dop += 1 
            end 
            if array[right] == ")" 
              dop -= 1 
              if dop == 0#意思是两个括号在同一个层次 
                re_calls = [] 
                for i in (left+1)...right 
                  re_calls << array[i] 
                end 
                gets = clear_bracket_a(re_calls) 
                if gets.size == 1 
                  if array[left-1] == "*" 
                    array[left..right] = gets 
                  elsif array[left-1] == "/" 
                    deep = 0 
                    for i in 0...gets.size 
                      if gets[i] == "(" 
                        deep += 1 
                      elsif gets[i] == ")" 
                        deep -= 1 
                      end 
                      if deep == 0 
                        if gets[i] == "*" 
                          gets[i] = "/" 
                        elsif gets[i] == "/" 
                          gets[i] = "*" 
                        end 
                      end 
                    end 
                  end 
                else 
                  if array[right+1] != "*" and array[right+1] != "/" 
                    if array[left-1] == "+" 
                      array[left..right] = gets 
                    elsif array[left-1] == "-" 
                      for i in 0...gets.size 
                        if gets[i] == "+" 
                          gets[i] = "-" 
                        elsif gets[i] == "-" 
                          gets[i] = "+" 
                        end 
                      end 
                      array[left..right] = gets 
                    elsif left == 0 #此分支于2012-3-18添加,修正了 
                      array[left..right] = gets 
                    else 
                      str = "(" 
                      for i in 0...gets.size 
                        str << gets[i] 
                      end 
                      str << ")" 
                      array[left..right] = str 
                    end 
                  else 
                    str = "(" 
                    for i in 0...gets.size 
                      str << gets[i] 
                    end 
                    str << ")" 
                    array[left..right] = str 
                  end 
                end 
#~                 array.faltten! 
                break 
              end 
            end 
            right += 1 
          end 
        end 
        left += 1 
      end#合并成单项式+-单项式……的形式。 
      returns = [] 
      i = 0 
      returns << "" 
      loop do 
        loop do 
          break if array[0] == "+" or array[0] == "-" or array.size <= 0 
          returns[i] << array[0] 
          array.delete_at(0) 
        end 
        break if array.size <= 0 
        if returns[i] != "" 
          i += 1 
          returns << "" 
        end 
        returns[i] << array[0] 
        array.delete_at(0) 
        i += 1 
        returns << "" 
      end 
      return returns 
    else#没有括号了,就合并成单项式+-单项式+-单项式……的形式 
      returns = [] 
      i = 0 
      returns << "" 
      loop do 
        loop do 
          break if array[0] == "+" or array[0] == "-" or array.size <= 0 
          returns[i] << array[0] 
          array.delete_at(0) 
        end 
        break if array.size <= 0 
        if returns[i] != "" 
          i += 1 
          returns << "" 
        end 
        returns[i] << array[0] 
        array.delete_at(0) 
        i += 1 
        returns << "" 
      end 
      return returns 
    end 
  end 
  def self.clear_bracket(string_input) 
    array = split_math(string_input) 
    array = clear_bracket_a(array) 
    returns = "" 
    for i in 0...array.size 
      returns << array[i] 
    end 
    return returns 
  end 
  def self.put_in_order_array_1(array_input)#无括号的部分 
#~     array = array_input.clone 
    array=deepcopy(array_input) 
    times_array = Array.new 
    t = 0 
    times_array[t] = [] 
    for i in 0...array.size 
      if array[i] == "+" or array[i] == "-" 
        t+=1 
        times_array[t] = [array[i]] 
        t+=1 
        times_array[t] = [] 
      else 
        times_array[t] << array[i] 
      end 
    end 
    for i in 0...times_array.size 
      times_array[i] = put_in_order_array_1_1(times_array[i]) 
    end 
    returns = put_in_order_array_1_2(times_array) 
    return returns 
  end 
  def self.put_in_order_array_1_1(input0)#以array输入   */计算排序(无括号) 
    input = input0.clone 
    if input.class != Array 
      return input 
    end 
    timers = [input[0]] 
    dividers = [] 
    for i in 1..(input.size-1)/2 
      if input[i*2-1] == "*" 
        timers << input[i*2] 
      elsif input[i*2-1] == "/" 
        dividers << input[i*2] 
      end 
    end 
    dividers = quick_soft(dividers) 
    timers = quick_soft(timers) 
    returns = timers[0] 
  
    for i in 1...timers.size 
      next unless timers[i] 
      returns << "*" 
      returns << timers[i] 
    end 
    for i in 0...dividers.size 
      next unless dividers[i] 
      returns << "/" 
      returns << dividers[i] 
    end 
    return returns 
  end 
  def self.put_in_order_array_1_2(input)#以array输入   +-计算排序(无括号) 
    addtions = [input[0]] 
    minus = [] 
    for i in 1..(input.size-1)/2 
      if input[i*2-1] == "+" 
        addtions << input[i*2] 
      elsif input[i*2-1] == "-" 
        minus << input[i*2] 
      end 
    end 
    minus = quick_soft(minus) 
    addtions = quick_soft(addtions) 
    returns = addtions[0] 
    for i in 1...addtions.size 
      next unless addtions[i] 
      returns << "+" 
      returns << addtions[i] 
    end 
    for i in 0...minus.size 
      next unless minus[i] 
      returns << "-" 
      returns << minus[i] 
    end 
    return returns 
  end 
  
  
  def self.put_in_order_array(array_input) 
    array = deepcopy(array_input) 
    if array.include?("(") 
      left = 0 
      while left < array.size 
        if array[left] == "(" 
          right = left+1 
          d = 1 
          while right < array.size 
            if array[right] == "(" 
              d += 1 
            end 
            if array[right] == ")" 
              d -= 1 
              if d == 0 
                tr = put_in_order_array(array[left+1..right-1]) 
                if tr 
                  array[left..right] = "(" + tr + ")" 
                else 
                  array[left..right] = nil 
                  array.delete_at(left) 
                end 
                break 
              end 
            end 
            right += 1 
          end 
        end 
        left += 1 
      end 
    end 
    string = put_in_order_array_1(array) 
    return string 
  end 
  
  def self.put_in_order(string) 
    array = split_math(string) 
    return put_in_order_array(array) 
  end 
end 
def split_math(string) 
  array = string.split(//) 
  i = 0 
  numbers = %w(0 1 2 3 4 5 6 7 8 9) 
  while i < array.size 
    if numbers.include?(array[i]) 
      n = i+1 
      loop do 
        break unless numbers.include?(array[n]) 
        array[i] << array[n] 
        array.delete_at(n) 
      end 
    end 
    i += 1 
  end 
  return array 
end 
def quick_soft(array)#快速排序法 
  x = array[0] 
  array_small = [] 
  array_else = [] 
  for i in 1...array.size 
    if array[i] < x 
      array_small << array[i] 
    else 
      array_else << array[i] #被分成array_small 、 x 和 array_else 
    end 
  end 
  if array_small.size == 0 
    returns1 = [] 
  elsif array_small.size == 1 
    returns1 = [array_small[0]] 
  else 
    returns1 = quick_soft(array_small) 
  end 
  if array_else.size == 0 
    returns3 = [] 
  elsif array_else.size == 1 
    returns3 = [array_else[0]] 
  else 
    returns3 = quick_soft(array_else) 
  end 
  returns2 = [x] 
  return returns1 + returns2 + returns3 
end 
#------------------------------------------------------ 
#------------------------------------------------------ 
Font.default_name = ["SimHei", "黑体", "DFKai-SB", "標楷體", "Verdana", "Arial Unicode MS"] 
$equal_value=24 
Graphics.freeze 
array = [] 
for i in 0..12 
  array[i] = (i+1).to_s 
end 
sets = [] 
set_now = 0 
for i in 0..3 
  sets[i] = [Rect.new(0+(i*272/3), 32, 32, 32), array, set_now] 
end 
$windows = [Window_Input.new(0, 0, 336, 96, sets)] 
Graphics.transition(30) 
loop do 
  Graphics.update 
  Input.update 
  $windows[$windows.size-1].update if $windows[0] 
end 
 | 
 |