English 中文(简体)
《鲁比法典》中关于休息的问题[闭门]
原标题:Problems with loops in Ruby Code [closed]
  • 时间:2012-05-01 10:37:58
  •  标签:
  • ruby
  • arrays
Closed. This question needs to be more focused. It is not currently accepting answers.

我有一阵列。

现在,我想将阵列第17位的价值与阵列第1位的位置的价值区分开来,然后是第18位。 成果应当建立一个新的阵列。

然后,我想弄清新阵列的所有价值,如果两个或两个以上连续的数值大于1.2,我还要补充一下,把新阵列的最后一个价值与所有连续价值分开。 如果一个数值为1.2,下一个数值为0.8,则不应改变阵列的数值。

我的守则是:

a = [1,2,3,4,5,9,5,13,14,17,19,23,19,34,46,12,13,45,46,67,78,79]

b = Array.new
c = Array.new

a.each_cons(18) { |c| b.push(c[17]/c[0] }

Do you have an idea how to implement the condition?

最佳回答

我认为这样做,尽管我有选择地从你的问题中解释过一些事情。 具体来说,在“所有连续价值之行”中,“增长”指的是每一条基点的碎块? Ditto for “all persistent Value”

catch (:done) do
  for i in 2..b.length do
    b.each_cons(i) do |d| 
      for j in 2..d.length do 
        d.each_cons(j) do |g|
          if g.all? { |g| g > 1.2 }
            c = b.map { |f| f + (d[0].to_f/d[i-1].to_f) }
            break
          end
          if !c.empty? then throw :done end
        end
      end
    end
  end
end

puts c
问题回答

暂无回答




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签