public static void Main(string[] args) { Console.WriteLine("Hello World"); int[] arrayoftest = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 16, 32, 40 }; for (int i = 0; i < arrayoftest.Length; ++i) { ASWakeman as0 = new ASWakeman(arrayoftest[i]); Console.WriteLine("as " + arrayoftest[i] + " " + as0.mySize() + " " + as0.export()); } ASWakeman hard1 = new ASWakeman(8, "00001111", "11111111111111111"); Console.WriteLine("usecase: " + hard1.export()); ASWakeman hard2 = new ASWakeman(8, "01010101", "00000000000000000"); Console.WriteLine("usecase: " + hard2.export()); ASWakeman hard3 = new ASWakeman(8, "00001111", "11110000111111110"); Console.WriteLine("usecase: " + hard3.export()); Console.WriteLine("all good!"); string a = Console.ReadLine(); }
private void init(int a, string inputs, string gates) { m_myGateSize = recalc(a); m_mySize = a; m_myGates = new bool[m_myGateSize]; m_inputs = new bool[m_mySize]; m_outputs = new bool[m_mySize]; if (inputs.Length != 0) { Common.Assert(a == inputs.Length, "inputs length is wrong"); for (int i = 0; i < inputs.Length; ++i) { if (inputs[i] == '0') { m_inputs[i] = false; } else { m_inputs[i] = true; } } } if (gates.Length != 0) { Common.Assert(m_myGateSize == gates.Length, "" + a + " gates length is wrong " + m_myGateSize); for (int i = 0; i < gates.Length; ++i) { if (gates[i] == '0') { m_myGates[i] = false; } else { m_myGates[i] = true; } } } // recursive creation int topsize = a / 2; int botsize = (a % 2 == 0) ? a / 2 : a / 2 + 1; int roundeddowngates = ((a / 2) * 2); int leftovergates = m_myGateSize - roundeddowngates; if (leftovergates > 0) { // gates //Console.WriteLine("gazie: " + m_myGateSize + " " + a); //Console.WriteLine("create: " + a); int topgatesize = recalc(topsize); bool[] topgates = new bool[topgatesize]; if (topgatesize == 0) { // todo: nothing? //Console.WriteLine("topsize end:" + botsize); } else { for (int i = 0; i < topgatesize; ++i) { int offsettedcount = i + roundeddowngates - 1; //Console.WriteLine("top: " + offsettedcount + " into " + i); topgates[i] = m_myGates[offsettedcount]; } } int bottomgatesize = recalc(botsize); bool[] bottomgates = new bool[bottomgatesize]; if (bottomgatesize == 0) { // todo: nothing? //Console.WriteLine("botsize end:" + botsize); } else { for (int i = 0; i < bottomgatesize; ++i) { int offsettedcount = i + roundeddowngates - 1 + topgatesize; //Console.WriteLine("bottom: " + offsettedcount + " into " + i); bottomgates[i] = m_myGates[offsettedcount]; } } // inputs bool[] topinputs = new bool[topsize]; if (topsize == 0) { // todo: nothing? } else { for (int i = 0; i < topsize; ++i) { int offset = i * 2; topinputs[i] = m_inputs[offset]; } } bool[] bottominputs = new bool[botsize]; if (botsize == 0) { // todo: nothing? } else { for (int i = 0; i < botsize; ++i) { int offset = i * 2 + 1; if (offset >= m_inputs.Length) { break; // IMPT: do not overshot the array } bottominputs[i] = m_inputs[offset]; } } if (topsize > 1) // todo: is this correct logic? { m_top = new ASWakeman(topsize, topinputs, topgates); } if (botsize > 1) // todo: is this correct logic? { m_bottom = new ASWakeman(botsize, bottominputs, bottomgates); } } }