Beispiel #1
0
        public string Core(IEnumerable <long[]> phases)
        {
            var program = Lines.First().Split(',').Select(long.Parse).ToArray();
            var outputs = new List <long>();

            foreach (var phase in phases)
            {
                var inpA = new List <long> {
                    phase[0], 0
                };
                var inpB = new List <long> {
                    phase[1]
                };
                var inpC = new List <long> {
                    phase[2]
                };
                var inpD = new List <long> {
                    phase[3]
                };
                var inpE = new List <long> {
                    phase[4]
                };
                var ca = new SeqCompiler(inpA, inpB, program.ToArray());
                var cb = new SeqCompiler(inpB, inpC, program.ToArray());
                var cc = new SeqCompiler(inpC, inpD, program.ToArray());
                var cd = new SeqCompiler(inpD, inpE, program.ToArray());
                var ce = new SeqCompiler(inpE, inpA, program.ToArray());
                do
                {
                    while (ca.Step() == State.Running)
                    {
                    }
                    while (cb.Step() == State.Running)
                    {
                    }
                    while (cc.Step() == State.Running)
                    {
                    }
                    while (cd.Step() == State.Running)
                    {
                    }
                    while (ce.Step() == State.Running)
                    {
                    }
                } while (!ce.Done());
                outputs.Add(ce.LastOut);
            }

            return(outputs.Max() + "");
        }
Beispiel #2
0
 private void Run(SeqCompiler c)
 {
     while (c.Step() == State.Running)
     {
     }
 }