public static void Problem22() { var nodes = new GridNodeFactory().Create(FileStringReader.Read("P22.txt").Skip(2)); var pairs = nodes.PairAll().WhereViable(); Console.WriteLine("Number Viable Pairs = {0}", pairs.Count()); }
public static void Problem7() { var supportsSSL = FileStringReader.Read("P7.txt") .Select(a => new IPv7(a)) .Where(a => a.SupportsSsl) .Count(); Console.WriteLine("How Many Support SSL? {0}", supportsSSL); }
public static void Problem9() { var strings = FileStringReader.Read("P9.txt"); var d = new StringDecompressorV2(); var lengths = strings.Select(a => d.Decompress(a)); lengths.ToList().ForEach(s => Console.WriteLine("Length = {0}", s)); }
public static void Problem21() { var instructions = FileStringReader.Read("P21.txt"); var reversedInstructions = instructions.Reverse(); var take = 3; var scrambler = new Scrambler(); var scrambled = new Scrambler().Scramble("abcdefgh", instructions); var descrambled = new Scrambler().Descramble("fbgdceah", instructions.Reverse()); }
public static void Problem20() { var ips = new IpRanges(); foreach (var range in FileStringReader.Read("P20.txt")) { ips.Block(Range.From(range)); } ips.AvailableRanges().ToList().ForEach(a => Console.WriteLine(string.Format("{0} == {1}", a, a.HowManyInRange))); Console.WriteLine("\nLowest Available = {0}", ips.Lowest()); Console.WriteLine("Number Blocked = {0}", ips.HowManyBlocked); Console.WriteLine("Number Available = {0}", ips.HowManyAvailable); }
public static void Problem8() { var screen = new Screen(); var commands = new PixelViewerCommandFactory().Create(() => FileStringReader.Read("P8.txt")); commands.Process(screen); var display = new RowBasedPixelViewerDisplay(screen, s => Console.WriteLine(s)); display.Refresh(); var on = screen.Rows.Select(a => a.Count(b => b.IsOn)).Sum(); Console.WriteLine("\nNumber On = {0}", on); }
public static void Problem10() { //var instructions = new[] //{ // "value 5 goes to bot 2", // "bot 2 gives low to bot 1 and high to bot 0", // "value 3 goes to bot 1", // "bot 1 gives low to output 1 and high to bot 0", // "bot 0 gives low to output 2 and high to output 0", // "value 2 goes to bot 2" //}; var instructions = FileStringReader.Read("P10.txt"); var factory = new Factory(); var executors = new IInstructionExecutor[] { new LoadBotInstructionExecutor(), new MoveChipsInstructionExecutor( (label, values) => { if (values.Contains(61) && values.Contains(17)) { Console.WriteLine("Bot {0} is comparing values {1} and {2}", label, values.First(), values.Last()); } }) }; new Foreman().Execute(executors.First(), executors.Last(), factory, instructions); //foreach (var bot in factory.Bots) //{ // Console.WriteLine("Bot {0} contains values [{1}]", bot, factory.BotValues(bot).Format()); //} foreach (var bin in factory.OutputBins.OrderBy(a => a)) { Console.WriteLine("Bin {0} contains values [{1}]", bin, factory.OutputBinValues(bin).Format()); } }
public static void Problem6() { var s = LetterFrequency.StringifyLeastFrequent(() => FileStringReader.Read("P6.txt")); Console.WriteLine("Frequented string = {0}", s); }