我正在尝试实现先验算法,但在编写生成候选项集的方法时遇到了麻烦。这是这个函数的截图。

主要问题是第2-5行。我不知道怎么弄到f1和f2。f1和f2是在最后一项上不同的数组,并且f1的最后一项小于f2的最后一项。
有谁知道怎么用Ruby写这段代码吗?
发布于 2013-06-25 21:05:19
f1 = [1,2,3]
f2 = [1,2,4]
z = [f1,f2].transpose
if(((z[0...(z.size-1)].collect {|el| el[0] == el[1]}.uniq == [true])) & (z[z.size-1][0] < z[z.size-1][1])) do
# f1 = f2 , except the last element, where the last f1 element is smaller than the last f2 element
endhttps://stackoverflow.com/questions/12206389
复制相似问题