Exemplo n.º 1
0
        private List <Amplifier> GetAmplifiers(List <decimal> fileContent, int[] phases)
        {
            List <decimal> signalsA = new List <decimal>()
            {
                phases[0], 0
            };
            List <decimal> signalsB = new List <decimal>()
            {
                phases[1]
            };
            List <decimal> signalsC = new List <decimal>()
            {
                phases[2]
            };
            List <decimal> signalsD = new List <decimal>()
            {
                phases[3]
            };
            List <decimal> signalsE = new List <decimal>()
            {
                phases[4]
            };

            Amplifier a = new Amplifier()
            {
                Input = signalsA, Memory = fileContent, Output = signalsB, Name = "A"
            };
            Amplifier b = new Amplifier()
            {
                Input = signalsB, Memory = fileContent, Output = signalsC, Name = "B"
            };
            Amplifier c = new Amplifier()
            {
                Input = signalsC, Memory = fileContent, Output = signalsD, Name = "C"
            };
            Amplifier d = new Amplifier()
            {
                Input = signalsD, Memory = fileContent, Output = signalsE, Name = "D"
            };
            Amplifier e = new Amplifier()
            {
                Input = signalsE, Memory = fileContent, Output = signalsA, Name = "E"
            };

            return(new List <Amplifier> {
                a, b, c, d, e
            });;
        }
Exemplo n.º 2
0
        public List <decimal> GetBoostCode(string path, int?input)
        {
            Day7InputReader day2InputReader = new Day7InputReader();
            List <decimal>  fileContent     = day2InputReader.ReadArray(path, ',').ToList();

            Amplifier amp = new Amplifier();

            amp.Memory = fileContent;
            amp.Input  = new List <decimal>();
            if (input.HasValue)
            {
                amp.Input.Add(input.Value);
            }

            amp.Output = new List <decimal>();
            while (!amp.Finished)
            {
                amp.IntCode();
            }

            return(amp.Output);
        }