Saito
2013-06-28 18:40:46 +08:00
r = []
m = [0, 0, 0, 2295, 2295, 1530, 0, 0, 0, 0, 0, 1020, 1530, 1530, 1530, 1530, 2295, 2550, 1785, 0, 0, 0, 0, 0, 1020, 1530, 1530, 1530, 1530, 2295, 2550, 0, 0, 0, 0, 0, 1275, 1530, 1530, 1530, 1530, 1530, 0, 0, 0, 0, 0, 0]
lastest = current = 0
m.each_with_index do |n, i|
lastest = current
current = n
if current != 0
if lastest == 0
r << i
end
else
if lastest != 0
r << i - 1
end
end
end
puts r
puts r.each_slice(2) {|a| p a}
puts r.each_slice(2).map{|a| a[1] - a[0] + 1 }
结果:
3
5
11
18
24
30
36
41
[3, 5]
[11, 18]
[24, 30]
[36, 41]
nil
3
8
7
6
[Finished in 0.0s]