Hit: 数と位置の両方が一致
Blow: 数は一致、位置は不一致
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Test
{
static void Main(string[] args)
{
int hit = 0;
int blow = 0;
int[] correctNumber = { 1, 2, 3, 4 };
int[] inputNumber = { 1, 3, 1, 4 };
List<int> listCheckNumber = new List<int>();
// Hitチェック
for (int index = 0; index < inputNumber.Length; index++)
{
if (correctNumber[index] == inputNumber[index])
{
hit++;
listCheckNumber.Add(inputNumber[index]);
}
}
// Blowチェック
for (int index = 0; index < inputNumber.Length; index++)
{
if (!(listCheckNumber.Contains(inputNumber[index]) ||
inputNumber[index] == correctNumber[index]))
{
blow++;
}
}
// test
Console.WriteLine("hit: " + hit);
Console.WriteLine("blow: " + blow);
}
}