private static void Part2() { var lines = File.ReadAllLines("input.txt"); var logicNetwork = new LogicNetwork(); foreach (var line in lines) { AddElementsFromInputString(line, logicNetwork); } var aWire = logicNetwork.GetByName("a"); var aWireValue = aWire.GetValue(); var bWire = logicNetwork.GetByName("b"); logicNetwork.Elements.OfType<Wire>().ToList().ForEach(x => x.Reset()); bWire.SetValue(aWireValue); Console.WriteLine(aWire.GetValue()); }
private static IHasValue ParseElementaryElementAndAddToNetwork(LogicNetwork logicNetwork, string sourceElementaryStr) { IHasValue source; ConstantValue constantValue; if (!ConstantValue.TryParse(sourceElementaryStr, out constantValue)) { var sourceWireName = sourceElementaryStr; var wire = logicNetwork.GetByName(sourceWireName); if (wire == null) { wire = new Wire(sourceWireName); logicNetwork.Elements.Add(wire); } source = wire; } else { logicNetwork.Elements.Add(constantValue); source = constantValue; } return source; }
private static void Part1() { var lines = File.ReadAllLines("input.txt"); var logicNetwork = new LogicNetwork(); foreach (var line in lines) { AddElementsFromInputString(line, logicNetwork); } var aWire = logicNetwork.GetByName("a"); Console.WriteLine(aWire.GetValue()); }