using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
int[] KouhoNumArr = DeriveKouhoNumArr();
int UB = KouhoNumArr.GetUpperBound(0);
int AnswerCnt = 0;
for (int I = 0; I <= UB; I++) {
for (int J = 0; J <= UB; J++) {
if (I == J) continue;
int A = KouhoNumArr[I], B = KouhoNumArr[J];
int C = DeriveRevBinNum(B), D = DeriveRevBinNum(A);
var wkList = new List<int>();
wkList.AddRange(DeriveEachNumArr(A));
wkList.AddRange(DeriveEachNumArr(B));
wkList.AddRange(DeriveEachNumArr(C));
wkList.AddRange(DeriveEachNumArr(D));
//数字の重複があったらNG
if (wkList.Count > wkList.Distinct().Count()) continue;
//0から9の、10個の数字がなかったらNG
if (wkList.Count < 10) continue;
AnswerCnt++;
Console.WriteLine("解{0}を発見。{1,3}.{2,3}.{3,3}.{4,3}",
AnswerCnt, A, B, C, D);
}
}
}
//使用可能な10進数の配列を返す
static int[] DeriveKouhoNumArr()
{
var WillReturn = new List<int>();
for (int I = 0; I <= 255; I++) {
int[] EachNumArr1 = DeriveEachNumArr(I);
int RevBinNum = DeriveRevBinNum(I);
//反転した数が255より大きかったらNG
if (RevBinNum > 255) continue;
//数字の重複があったらNG
int[] EachNumArr2 = DeriveEachNumArr(RevBinNum);
int[] wkArr = EachNumArr1.Concat(EachNumArr2).ToArray();
if (wkArr.Length > wkArr.Distinct().Count()) continue;
WillReturn.Add(I);
}
return WillReturn.ToArray();
}
//数値の各数字の配列を返す
static int[] DeriveEachNumArr(int pTarget)
{
var WillReturn = new List<int>();
int CopiedVal = pTarget;
do {
int ModVal = CopiedVal % 10;
WillReturn.Add(ModVal);
CopiedVal /= 10;
} while (CopiedVal > 0);
return WillReturn.ToArray();
}
//10進数を引数とし、2進数にして反転し、10進数に変換した数値を返す
static int DeriveRevBinNum(int pTarget)
{
string BinStr = Convert.ToString(pTarget, 2).PadLeft(8, '0');
string RevBinStr = new string(BinStr.Reverse().ToArray());
return Convert.ToInt32(RevBinStr, 2);
}
}