回答編集履歴
1
あ
answer
CHANGED
@@ -1,1 +1,43 @@
|
|
1
|
-
インターフェイスをジェネリクスにして IQuestion<T> にする
|
1
|
+
~~インターフェイスをジェネリクスにして IQuestion<T> にする~~
|
2
|
+
回答が全てintではなかったですね。すみません。
|
3
|
+
|
4
|
+
```csharp
|
5
|
+
public class CalcQuestion : IQuestion<int, int>
|
6
|
+
{
|
7
|
+
private readonly int First;
|
8
|
+
private readonly int Second;
|
9
|
+
public CalcQuestion(int x, int y)
|
10
|
+
{
|
11
|
+
First = x;
|
12
|
+
Second = y;
|
13
|
+
}
|
14
|
+
|
15
|
+
public string Inquire() => $"{First} x {Second} = ?";
|
16
|
+
|
17
|
+
public bool IsCorrect(int answer) => answer == First * Second;
|
18
|
+
|
19
|
+
public int GetCorrectAnswer() => First * Second;
|
20
|
+
}
|
21
|
+
public class CombinationQuestion : IQuestion<(int, int), IEnumerable<(int, int)>>
|
22
|
+
{
|
23
|
+
private readonly int Prod;
|
24
|
+
private readonly IEnumerable<(int, int)> Pairs;
|
25
|
+
public CombinationQuestion(int x)
|
26
|
+
{
|
27
|
+
Prod = x;
|
28
|
+
Pairs = Enumerable.Range(1, x).Select(i => x % i == 0 ? (i, x / i) : (0, 0)).Where(t => t.Item1 != 0);
|
29
|
+
}
|
30
|
+
|
31
|
+
public string Inquire() => $"? x ? = {Prod}";
|
32
|
+
public bool IsCorrect((int, int) answer) => Pairs.Contains(answer);
|
33
|
+
|
34
|
+
public IEnumerable<(int, int)> GetCorrectAnswer() => Pairs;
|
35
|
+
}
|
36
|
+
|
37
|
+
public interface IQuestion<in T, out U>
|
38
|
+
{
|
39
|
+
string Inquire();
|
40
|
+
bool IsCorrect(T answer);
|
41
|
+
U GetCorrectAnswer();
|
42
|
+
}
|
43
|
+
```
|