回答編集履歴
1
追記
test
CHANGED
@@ -15,3 +15,55 @@
|
|
15
15
|
|
16
16
|
|
17
17
|
正直、初めて[Array#bsearch](https://docs.ruby-lang.org/ja/latest/method/Array/i/bsearch.html) / [Enumerable#chunk](https://docs.ruby lang.org/ja/latest/method/Enumerable/i/chunk.html)を使ったような気がします。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
**追記**
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
|
27
|
+
arr = [1,2,3,4,5,6,7,8,9,10]
|
28
|
+
|
29
|
+
offsets = [2, 4, 7]
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
p arr.each_with_index.slice_when{|_, (_, i)|
|
34
|
+
|
35
|
+
if offsets.first == i
|
36
|
+
|
37
|
+
offsets.shift
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
}.map{|a| a.map(&:first)}
|
42
|
+
|
43
|
+
```
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
オフセット→要素数への変換ができるのならば
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
|
53
|
+
arr = [1,2,3,4,5,6,7,8,9,10]
|
54
|
+
|
55
|
+
elements = [2, 2, 3]
|
56
|
+
|
57
|
+
result = []
|
58
|
+
|
59
|
+
result << arr.shift(elements.shift) until elements.empty?
|
60
|
+
|
61
|
+
result << arr
|
62
|
+
|
63
|
+
p result
|
64
|
+
|
65
|
+
```
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
が速いとは思います。
|