查看: 4381|回复: 5

[RMVX发布] 24点破解器 (2012-10-1新出V2.0.4,见6楼)

[复制链接]
梦石
0
星屑
50
在线时间
21 小时
注册时间
2011-8-22
回帖
8
发表于 2012-1-20 11:00:27 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 lotsofone 于 2012-10-1 00:08 编辑

    24点破解器,玩24点遇到难题交给它都能解决。本破解器可以求出由4个从1到13的随机数构成的24点游戏的所有解。
24点破解器截图.PNG
24点破解器.rar (130.27 KB, 下载次数: 788)
代码不仅有破24点的程序,还附带了一些Window类,用来设置4个24点的数值和显示解法。
若因修正bug改变代码,导致下载的文件里的脚本与下面的脚本不同,请以下面的脚本为准。
[pre lang="ruby" line="1"]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 = sets[0][2]
    end
    for i in 0...self.sets.size
      rect = self.sets[0]
      str = self.sets[1][self.item_set]
      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[0]
      str = self.sets[1][self.item_set]
      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 = self.item_set
    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 = self.item_set
    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, 100, 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]]
    strall = for_result_b_24(number_a.to_i, number_b.to_i, number_c.to_i, number_d.to_i)
    str_array = strall.split(/:/)
    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)
    end
    self.contents.draw_text(Rect.new(390, 250, 100, 24), "by "+author)
  end
end
def deal_rest(result)
  if (result[1].to_i < result[3].to_i) and (result[2] == "-") and (result[8] == "-")
    exchanges = result[1]
    result[1] = result[3]
    result[3] = exchanges
    exchanges = result[7]
    result[7] = result[9]
    result[9] = exchanges
  end
  if eval(result[1]+result[2]+result[3])>eval(result[7]+result[8]+result[9]) and result[5] == "*"
    translates = []
    for i in 0..10
      translates = result
    end
    result[1] = translates[7]
    result[2] = translates[8]
    result[3] = translates[9]
    result[7] = translates[1]
    result[8] = translates[2]
    result[9] = translates[3]
  end
  if result[1] > result[3] and result[2] == "+"
    exchanges = result[1]
    result[1] = result[3]
    result[3] = exchanges
  end
  if result[7] > result[9] and result[8] == "+"
    exchanges = result[7]
    result[7] = result[9]
    result[9] = exchanges
  end
end
def break_24_locked(a, b, c, d)#此方法为本程序的核心之一
  ret = []
  eval_array = ["(", "(", a.to_s, nil, b.to_s, ")", nil, c.to_s, ")", nil, d.to_s]
  method_array = ["+", "-", "*", "/"]
  for x in method_array
    if x == "/"
      next if a / b * b != a
    end
    eval_array[3] = x
    for y in method_array
      if y == "/"
        next if eval(a.to_s + x + b.to_s)/c*c != eval(a.to_s + x + b.to_s)
      end
      eval_array[6] = y
      for z in method_array
        if z == "/"
          next if eval("(" + a.to_s + x + b.to_s + ")" + y + c.to_s)/d*d != eval("(" + a.to_s + x + b.to_s + ")" + y + c.to_s)
        end
        eval_array[9] = z
        eval_string = eval_array[0]
        for i in 1..10
          eval_string += eval_array
        end
        if eval(eval_string) == $equal_value
          arr = []
          for i in 0..10
            arr = eval_array
          end
          ret << arr
        end
      end
    end
  end
  eval_array = ["(", a.to_s, nil, b.to_s, ")", nil, "(", c.to_s, nil, d.to_s, ")"]
  for x in 0..1
    for y in 2..3
      for z in 0..1
        eval_array[2] = method_array[x]
        eval_array[5] = method_array[y]
        eval_array[8] = method_array[z]
        if eval_array[5] == "/"
          chu_shu = eval(eval_array[7]+eval_array[8]+eval_array[9])
          bei_chu_shu = eval(eval_array[1]+eval_array[2]+eval_array[3])
          next if chu_shu == 0 or bei_chu_shu / chu_shu * chu_shu != bei_chu_shu
        end
        eval_string = eval_array[0]
        for i in 1..10
          eval_string += eval_array
        end
        if eval(eval_string) == $equal_value
          arr = []
          for i in 0..10
            arr = eval_array
          end
          ret << arr
        end
      end
    end
  end
  return ret  
end
def deal(array)
  for i in 0...array.size
    if array[1] == "("
      deal_most(array)
    else
      deal_rest(array)
    end
    for n in 0...array.size
      if array[n]=="*"
        array[n]="×"
      elsif array[n]=="/"
        array[n]="÷"
      end
    end
  end
  i = 0
  while i < array.size
    for n in 0...array.size
      next if n == i
      if array == array[n]
        array.delete_at(i)
        i -= 1
        break
      end
    end
    i += 1
  end
  for i in 0...array.size
    tra = array
    array = tra[0]
    for n in 1..10
      break if ! tra[n]
      array += tra[n]
    end   
  end
end
def break_24(a, b, c, d)#此方法为本程序的核心之一
  ret = []
  n = [a, b, c, d]
  for w in 0..3
    for x in 0..3
      next if x == w
      for y in 0..3
        next if y==x or y==w
        for z in 0..3
          next if z==x or z==y or z==w
          ret.concat(break_24_locked(n[w], n[x], n[y], n[z]))
        end
      end
    end
  end
  deal(ret)
  return ret
end
def deal_most(result)  
  if result[3] == "/"
    if result[6] == "*"
      tr = result[4]
      result[4] = result[7]
      result[7] = tr
      result[3] = "*"
      result[6] = "/"
    end
  end
  if result[3] == "-"
    if result[6] == "+"
      tr = result[4]
      result[4] = result[7]
      result[7] = tr
      result[3] = "+"
      result[6] = "-"
    end
  end
  if result[6] == "/"
    if result[9] == "*"
      tr = result[7]
      result[7] = result[10]
      result[10] = tr
      result[6] = "*"
      result[9] = "/"
    end
  end
  if result[6] == "-"
    if result[9] == "+"
      tr = result[7]
      result[7] = result[10]
      result[10] = tr
      result[6] = "+"
      result[9] = "-"
    end
  end
  if result[3] == "/"
    if result[6] == "*"
      tr = result[4]
      result[4] = result[7]
      result[7] = tr
      result[3] = "*"
      result[6] = "/"
    end
  end
  if result[3] == "-"
    if result[6] == "+"
      tr = result[4]
      result[4] = result[7]
      result[7] = tr
      result[3] = "+"
      result[6] = "-"
    end
  end
  if result[3] == "*" or result[3] == "+"
    if result[2].to_i > result[4].to_i
      trans = result[2]
      result[2] = result[4]
      result[4] = trans
    end
  end
  if result[3] == "+"
    if result[6] == "+"
      if result[9] == "+"
        ta = [result[2],result[4],result[7],result[10]]
        if ta[0]<=ta[1] and ta[0]<=ta[2] and ta[0]<=ta[3]
          result[2] = ta[0]
          ta.delete_at(0)
        elsif ta[1]<=ta[0] and ta[1]<=ta[2] and ta[1]<=ta[3]
          result[2] = ta[1]
          ta.delete_at(1)
        elsif ta[2]<=ta[0] and ta[2]<=ta[1] and ta[2]<=ta[3]
          result[2] = ta[2]
          ta.delete_at(2)
        elsif ta[3]<=ta[0] and ta[3]<=ta[1] and ta[3]<=ta[2]
          result[2] = ta[3]
          ta.delete_at(3)
        end
        if ta[0]<=ta[1] and ta[0]<=ta[2]
          result[4]=ta[0]
          ta.delete_at(0)
        elsif ta[1]<=ta[0] and ta[1]<=ta[2]
          result[4]=ta[1]
          ta.delete_at(1)
        elsif ta[2]<=ta[0] and ta[2]<=ta[1]
          result[4]=ta[2]
          ta.delete_at(2)
        end
        if ta[0]<=ta[1]
          result[7] = ta[0]
          result[10] = ta[1]
        else
          result[7] = ta[1]
          result[10] = ta[0]
        end
      else
        ta = [result[2],result[4],result[7]]
        if ta[0]<=ta[1] and ta[0]<=ta[2]
          result[2]=ta[0]
          ta.delete_at(0)
        elsif ta[1]<=ta[0] and ta[1]<=ta[2]
          result[2]=ta[1]
          ta.delete_at(1)
        elsif ta[2]<=ta[0] and ta[2]<=ta[1]
          result[2]=ta[2]
          ta.delete_at(2)
        end
        if ta[0]<=ta[1]
          result[4] = ta[0]
          result[7] = ta[1]
        else
          result[7] = ta[0]
          result[4] = ta[1]
        end
      end
    end
  end
  if (result[6] == "*" and result[9] == "*") or (result[6] == "+" and result[9] == "+") or (result[6] == "-" and result[9] == "-") or (result[6] == "/" and result[9] == "/")
    if result[7]>result[10]
      tnm = result[7]
      result[7] = result[10]
      result[10] = tnm
    end
  end
  if result[3] == "*"
    if result[6] == "*"
      if result[9] == "*"
        ta = [result[2],result[4],result[7],result[10]]
        if ta[0]<=ta[1] and ta[0]<=ta[2] and ta[0]<=ta[3]
          result[2] = ta[0]
          ta.delete_at(0)
        elsif ta[1]<=ta[0] and ta[1]<=ta[2] and ta[1]<=ta[3]
          result[2] = ta[1]
          ta.delete_at(1)
        elsif ta[2]<=ta[0] and ta[2]<=ta[1] and ta[2]<=ta[3]
          result[2] = ta[2]
          ta.delete_at(2)
        elsif ta[3]<=ta[0] and ta[3]<=ta[1] and ta[3]<=ta[2]
          result[2] = ta[3]
          ta.delete_at(3)
        end
        if ta[0]<=ta[1] and ta[0]<=ta[2]
          result[4]=ta[0]
          ta.delete_at(0)
        elsif ta[1]<=ta[0] and ta[1]<=ta[2]
          result[4]=ta[1]
          ta.delete_at(1)
        elsif ta[2]<=ta[0] and ta[2]<=ta[1]
          result[4]=ta[2]
          ta.delete_at(2)
        end
        if ta[0]<=ta[1]
          result[7] = ta[0]
          result[10] = ta[1]
        else
          result[7] = ta[1]
          result[10] = ta[0]
        end
      else
        ta = [result[2],result[4],result[7]]
        if ta[0]<=ta[1] and ta[0]<=ta[2]
          result[2]=ta[0]
          ta.delete_at(0)
        elsif ta[1]<=ta[0] and ta[1]<=ta[2]
          result[2]=ta[1]
          ta.delete_at(1)
        elsif ta[2]<=ta[0] and ta[2]<=ta[1]
          result[2]=ta[2]
          ta.delete_at(2)
        end
        if ta[0]<=ta[1]
          result[4] = ta[0]
          result[7] = ta[1]
        else
          result[7] = ta[0]
          result[4] = ta[1]
        end
      end
    end
  end
  if result[3] == "*" or result[3] == "/"
    if result[6] == "*" or result[6] == "/"
      result.delete("(")
      result.delete(")")
    else
      if result[9] == "*" or result[9] == "/"
        result.delete_at(5)
        result.delete_at(0)
      else         
        result.delete("(")
        result.delete(")")
      end
    end
  else
    if result[6] == "*" or result[6] == "/"
      result.delete_at(8)
      result.delete_at(0)
    else
      if result[9] == "*" or result[9] == "/"
        result.delete_at(5)
        result.delete_at(0)
      else
        result.delete("(")
        result.delete(")")
      end
    end
  end
end
def for_result_b_24(a, b, c, d)
  ra = break_24(a, b, c, d)
  ret = ra[0]
  number = 3
  times = 0
  if ra.size>=1
    for i in 1...ra.size
      times += 1
      ret << "     " if times % number != 0
      ret << ":"  if times % number == 0
      ret << ra
    end
  end
  if ret == nil
    ret = "无解"
  end
  ret
end
$equal_value=24
Graphics.freeze
array = []
for i in 0..12
  array = (i+1).to_s
end
sets = []
set_now = 0
for i in 0..3
  sets = [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[/pre]
ps:我是把除Window_Base和Cache以外的脚本全删光,然后添加的这些脚本。
最近更新时间:2012-1-20 13:04 修正了12*12/2/3和12/2*12/3这种相同的解不能合并的bug。

猛然发现自己漏解:它解不出 a+-(b×÷c)+-d = 24等的解。编这东西很容易漏掉某些情况,所有情况包括:
(a~b)~c~d√
(a~b~c)~d√
a~(b~c)~d×
a~b~(c~d)×
a~(b~c~d)×
(a~b)~(c~d)√
(标×表示本程序没有收录)
懒得改了,以后再更新。

评分

参与人数 3星屑 +1502 收起 理由
fux2 + 1332 精品文章
orzfly + 38 塞糖
Sonic1997 + 132

查看全部评分

海原大樹

梦石
0
星屑
205
在线时间
966 小时
注册时间
2011-12-17
回帖
680
发表于 2012-1-20 11:36:00 | 显示全部楼层
标题就直接带了个【破x】,不怕被误会咩{:nm_6:}(总之好强大{:nm_3:})

点击有惊喜什么的...
回复

使用道具 举报

音速君

梦石
0
星屑
161
在线时间
1623 小时
注册时间
2011-6-9
回帖
3342

开拓者贵宾

发表于 2012-1-20 12:32:37 | 显示全部楼层
本帖最后由 Sonic1997 于 2012-1-19 21:12 编辑

建议弄多一点数字吧反正又不会出错{:nm_6:}
RE:↓还真不知道

点评

乃显然不知道24点的玩法  发表于 2012-1-20 13:10
Deartime
RMVA从零学起
【RMVA从零学起】【基础27课】数据库-系统
#2013年11月24日更新
偷懒了好久呢. .
于是最终还是决定暂时不写进阶教程了
先把这些基础的东西仔细说一下.w.
回复

使用道具 举报

梦石
0
星屑
60
在线时间
565 小时
注册时间
2010-10-30
回帖
159
发表于 2012-1-20 13:56:59 | 显示全部楼层
下来看看,貌似很强大。。
(ARPG)赵云突围: http://rpg.blue/thread-303844-1-1.html
(剧情向战斗)命运赌局: http://rpg.blue/thread-257144-1-1.html
(ARPG)三英战吕布: http://rpg.blue/thread-220451-1-1.html
(R剧)秋风五丈原: http://rpg.blue/thread-211306-1-1.html
回复

使用道具 举报

老黄鸡

梦石
4
星屑
45772
在线时间
7953 小时
注册时间
2009-7-6
回帖
13338

MZ评测员RM创作大赛01组委会开拓者贵宾

发表于 2012-1-20 17:55:48 | 显示全部楼层
在下还记得LZ以前发布的ARPG系统很给力呢XD
RGDirect - DirectX驱动的RGSS,点我了解.
(排满,暂停)RM全系列成套系统定制请联系QQ1213237796
不接受对其他插件维护的委托
回复

使用道具 举报

梦石
0
星屑
50
在线时间
21 小时
注册时间
2011-8-22
回帖
8
 楼主| 发表于 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秒。
3388.PNG
24点破解器 V2.0.5.rar (969.3 KB, 下载次数: 57)
脚本如下,顺便感谢一下 orzfly 解答我的脚本问题。
为能完整显示,脚本分成三段。
如果有修正bug等改动脚本的操作使得文件包的脚本和下面的脚本不同,请以下面的脚本为准。最新更新时间2012-10-1。
[pre lang="ruby" line="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
  end
end
[/pre]
[pre lang="ruby" line="1"]#==============================================================================
# ■ 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 = sets[0][2]
    end
    for i in 0...self.sets.size
      rect = self.sets[0]
      str = self.sets[1][self.item_set]
      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[0]
      str = self.sets[1][self.item_set]
      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 = self.item_set
    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 = self.item_set
    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
      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)
    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[/pre]
[pre lang="ruby" line="1"]
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
        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 == "*" or array == "/"
      return 2
    elsif array == "+" or array == "-"
      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
    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
    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 = deal(way)
    end
    i = 0
    while i < way.size
      ds = i+1
      while ds < way.size
        if way == 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
    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
                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 == "("
                        deep += 1
                      elsif gets == ")"
                        deep -= 1
                      end
                      if deep == 0
                        if gets == "*"
                          gets = "/"
                        elsif gets == "/"
                          gets = "*"
                        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 == "+"
                          gets = "-"
                        elsif gets == "-"
                          gets = "+"
                        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
                      end
                      str << ")"
                      array[left..right] = str
                    end
                  else
                    str = "("
                    for i in 0...gets.size
                      str << gets
                    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 << array[0]
          array.delete_at(0)
        end
        break if array.size <= 0
        if returns != ""
          i += 1
          returns << ""
        end
        returns << 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 << array[0]
          array.delete_at(0)
        end
        break if array.size <= 0
        if returns != ""
          i += 1
          returns << ""
        end
        returns << 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
    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 == "+" or array == "-"
        t+=1
        times_array[t] = [array]
        t+=1
        times_array[t] = []
      else
        times_array[t] << array
      end
    end
    for i in 0...times_array.size
      times_array = put_in_order_array_1_1(times_array)
    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
      returns << "*"
      returns << timers
    end
    for i in 0...dividers.size
      next unless dividers
      returns << "/"
      returns << dividers
    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
      returns << "+"
      returns << addtions
    end
    for i in 0...minus.size
      next unless minus
      returns << "-"
      returns << minus
    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)
      n = i+1
      loop do
        break unless numbers.include?(array[n])
        array << 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 < x
      array_small << array
    else
      array_else << array #被分成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+1).to_s
end
sets = []
set_now = 0
for i in 0..3
  sets = [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[/pre]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部