Created
June 28, 2014 09:46
-
-
Save paralleltree/1e9baec96de5a0546457 to your computer and use it in GitHub Desktop.
STAP細胞を探すC#コード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
namespace STAP | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var rnd = new Random(); | |
string alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
bool[] history = new bool[(int)Math.Pow(26, 4)]; | |
int cnt = 0; | |
while (true) | |
{ | |
System.Threading.Thread.Sleep(50); | |
cnt++; | |
int[] num = new int[4]; | |
string cell = ""; | |
for (int i = 0; i < 4; i++) | |
{ | |
num[i] = rnd.Next(26); | |
cell += alpha[num[i]]; | |
} | |
int hash = getHash(num); | |
if (history[hash] == true) continue; | |
history[hash] = true; | |
Console.WriteLine("{0} : {1:000000}", cell + "細胞", cnt); | |
if (cell == "STAP") break; | |
} | |
Console.WriteLine("陽性確認!よかった"); | |
Console.ReadKey(); | |
} | |
static int getHash(int[] table) | |
{ | |
int hash = 0; | |
var factor = Enumerable.Range(0, table.Length).Reverse().Select(p => (int)Math.Pow(26, p)).ToArray(); | |
for (int i = 0; i < table.Length; i++) | |
hash += table[i] * factor[i]; | |
return hash; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment