public static int TestOP8_eq(OP8 o1, byte b) { int count = 0; for (int x = 0; x < 256; x++) { if ((b == x) == o1.eval((byte)x)) { count += 1; } } return(count); }
public static int TestOP8_lt(OP8 o1, byte b) // find operator greater equal than b { int count = 0; for (int x = 0; x < 256; x++) { if ((b > x) == o1.eval((byte)x)) { count += 1; } } return(count); }
public static int TestOP8_excludeRange(OP8 o1, byte min, byte max) { int count = 0; for (int x = 0; x < 256; x++) { bool b = (x >= min && x <= max); if (b && !o1.eval((byte)x)) { count += 1; } } return(count); }
public static void Test2OP8() // training 8*OP8, get byte->byte dict { OP8[] op8 = new OP8[8]; for (int x = 0; x < 8; x++) { op8[x] = new OP8(); } int k = 0; byte m = 0; while (true) { int z = (m + 1) % 256; // expected byte b1 = Make(op8, m); if (b1 == z) { Console.WriteLine("reached {0}", m); if (m == 255) { break; } m += 1; continue; } // change op OP8 o3 = op8[k % 8]; OP8 o2 = op8[k % 8].Mutate(); op8[k % 8] = o2; byte b2 = Make(op8, m); if (Math.Abs((double)b2 - (double)z) > Math.Abs((double)b1 - (double)z)) { // back track op8[k % 8] = o3; } k += 1; k = k % 8; } Console.WriteLine("OK2"); }
/* * learn: * M is used for K * * LIVE K: * get what is used for K * A = test if range belong to X * if A include in M * else do nothing * if M is good do nothing. * else create N, N is used for K * */ public static void TestOP8() { OP8 o1 = new OP8(); int amount = 0; int amountMax = 512; while (true) { int count1 = TestOP8_gt(o1, 10); OP8 o2 = o1.Mutate(); int count2 = TestOP8_gt(o2, 10); if (count2 > count1) { o1 = o2; Console.WriteLine("changed {0}", count2); } amount += 1; if (amount > amountMax) { break; } } Console.WriteLine("{0}", o1.bin()); }