예제 #1
0
    public override string Part2(string input, object?args)
    {
        var pool = new ReceiverPool();

        foreach (var line in input.Lines())
        {
            Instructions.ApplyInstruction(pool, line);
        }

        var arr = args as int[];
        var res = 1;

        foreach (var outp in arr)
        {
            res *= pool.Outputs[outp].Chips[0];
        }
        return(res.ToString());
    }
예제 #2
0
    public override string Part1(string input, object?args)
    {
        var pool = new ReceiverPool();
        var arr  = args as int[];

        _chip1 = arr[0];
        _chip2 = arr[1];

        Instructions.OnBotComparing += Instructions_OnBotComparing;
        foreach (var line in input.Lines())
        {
            Instructions.ApplyInstruction(pool, line);
            if (_comparingBotFound)
            {
                break;
            }
        }

        return(_comparingBot.Id.ToString());
    }
예제 #3
0
        public static void Main(string[] args)
        {
            var          pool  = new ReceiverPool();
            const string input = Generic.Input;

            foreach (var line in input.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
            {
                Instructions.ApplyInstruction(pool, line);
            }


            //Print output contents
            foreach (var o in pool.Outputs.OrderBy(x => x.Key))
            {
                Console.Write(o.Key + " : ");
                o.Value.Chips.ForEach(x => Console.Write(x + ","));
                Console.WriteLine();
            }

            Console.ReadKey();
        }
예제 #4
0
            public static void ApplyInstruction(ReceiverPool pool, string s)
            {
                if (s.StartsWith("bot"))
                {
                    var botno    = int.Parse(s.Substring(4, s.IndexOf("gives") - 4));
                    var low      = s.Substring(s.IndexOf("low to") + 6, s.IndexOf("and") - s.IndexOf("low to") - 6).Trim();
                    var lowtype  = low.Split(' ')[0];
                    var lowid    = int.Parse(low.Split(' ')[1].Trim());
                    var high     = s.Substring(s.IndexOf("high to") + 8).Trim();
                    var hightype = high.Split(' ')[0];
                    var highid   = int.Parse(high.Split(' ')[1].Trim());

                    var bot = pool.GetBot(botno);
                    bot.SetInstructions(lowtype == "bot" ? (Receiver)pool.GetBot(lowid) : pool.GetOutput(lowid),
                                        hightype == "bot" ? (Receiver)pool.GetBot(highid) : pool.GetOutput(highid));
                }
                else
                {
                    var chipno = int.Parse(s.Substring(6, s.IndexOf("goes") - 6).Trim());
                    var botno  = int.Parse(s.Substring(s.IndexOf("bot") + 4));
                    pool.GetBot(botno).Receive(chipno);
                }
            }