回答編集履歴
3
追記
test
CHANGED
@@ -129,3 +129,49 @@
|
|
129
129
|
.ToArray();
|
130
130
|
|
131
131
|
```
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
# 追記
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
多次元配列の別解
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
```C#
|
144
|
+
|
145
|
+
var cells = new int[,]
|
146
|
+
|
147
|
+
{
|
148
|
+
|
149
|
+
{ 0, 0, 0 },
|
150
|
+
|
151
|
+
{ 0, 0, 0 },
|
152
|
+
|
153
|
+
{ 1, 1, 0 },
|
154
|
+
|
155
|
+
{ 0, 0, 0 },
|
156
|
+
|
157
|
+
{ 1, 1, 1 },
|
158
|
+
|
159
|
+
};
|
160
|
+
|
161
|
+
var comparison = new int[] { 0, 0, 0 };
|
162
|
+
|
163
|
+
int[] indexarr = Enumerable
|
164
|
+
|
165
|
+
.Range(0, cells.GetLength(0))
|
166
|
+
|
167
|
+
.Where(index => Enumerable
|
168
|
+
|
169
|
+
.Range(0, cells.GetLength(1))
|
170
|
+
|
171
|
+
.Select(a => cells[index, a])
|
172
|
+
|
173
|
+
.SequenceEqual(comparison))
|
174
|
+
|
175
|
+
.ToArray();
|
176
|
+
|
177
|
+
```
|
2
追記
test
CHANGED
@@ -83,3 +83,49 @@
|
|
83
83
|
.ToArray();
|
84
84
|
|
85
85
|
```
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
# 追記
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
多次元配列の別解
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
```C#
|
98
|
+
|
99
|
+
var cells = new int[,]
|
100
|
+
|
101
|
+
{
|
102
|
+
|
103
|
+
{ 0, 0, 0 },
|
104
|
+
|
105
|
+
{ 0, 0, 0 },
|
106
|
+
|
107
|
+
{ 1, 1, 0 },
|
108
|
+
|
109
|
+
{ 0, 0, 0 },
|
110
|
+
|
111
|
+
{ 1, 1, 1 },
|
112
|
+
|
113
|
+
};
|
114
|
+
|
115
|
+
var comparison = new int[] { 0, 0, 0 };
|
116
|
+
|
117
|
+
int[] indexarr = cells
|
118
|
+
|
119
|
+
.Cast<int>()
|
120
|
+
|
121
|
+
.Select((value, index) => new { value, index })
|
122
|
+
|
123
|
+
.GroupBy(a => a.index / cells.GetLength(1), a => a.value)
|
124
|
+
|
125
|
+
.Where(a => a.SequenceEqual(comparison))
|
126
|
+
|
127
|
+
.Select(a => a.Key)
|
128
|
+
|
129
|
+
.ToArray();
|
130
|
+
|
131
|
+
```
|
1
追記
test
CHANGED
@@ -43,3 +43,43 @@
|
|
43
43
|
.ToArray();
|
44
44
|
|
45
45
|
```
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
# 追記
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
ジャグ配列を使った場合
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
```C#
|
58
|
+
|
59
|
+
var cells = new int[][]
|
60
|
+
|
61
|
+
{
|
62
|
+
|
63
|
+
new[] { 0, 0, 0 },
|
64
|
+
|
65
|
+
new[] { 0, 0, 0 },
|
66
|
+
|
67
|
+
new[] { 1, 1, 0 },
|
68
|
+
|
69
|
+
new[] { 0, 0, 0 },
|
70
|
+
|
71
|
+
new[] { 1, 1, 1 },
|
72
|
+
|
73
|
+
};
|
74
|
+
|
75
|
+
var comparison = new int[] { 0, 0, 0 };
|
76
|
+
|
77
|
+
int[] indexarr = cells
|
78
|
+
|
79
|
+
.Select((a, i) => a.SequenceEqual(comparison) ? i : -1)
|
80
|
+
|
81
|
+
.Where(a => a != -1)
|
82
|
+
|
83
|
+
.ToArray();
|
84
|
+
|
85
|
+
```
|