public void Solve() { long mask = 0; int minflips = Bits + 1; long maxvalue = 1; maxvalue <<= Bits; var flippedOutlets = new HashSet <long>(Outlets); int numBits = 0; while (mask < maxvalue) { if (numBits < minflips) { flippedOutlets = new HashSet <long>(Outlets.Select(x => x ^ mask)); if (flippedOutlets.IsSubsetOf(Devices) && flippedOutlets.IsSupersetOf(Devices)) { minflips = numBits; } } for (long j = 1; (j & mask) != 0; j <<= 1) { numBits--; } numBits++; mask++; } if (minflips <= Bits) { NumFlips = minflips; } }
protected override Action <TMessage> FindReceiver(IInlet <TMessage> inletSendingMessage) { var receivers = Outlets.Select((outlet, index) => new Tuple <int, Action <TMessage> >(index, outlet.FindReceiver())).Where(t => t.Item2 != null).ToList(); if (!receivers.Any()) { return(null); } var result = TieBreaker.ResolveTie(receivers.Select(s => s.Item1)); return(receivers.Single(s => s.Item1 == result).Item2); }