Exemplo n.º 1
0
        public bool isSuperSpecialValidPassword(int pw)
        {
            int[] pwDigits = SantasLittleHelperClass.IntToDigitArray(pw);

            int nr  = pwDigits[0];
            int end = pwDigits.Length - 1;

            if (nr == pwDigits[1] && nr != pwDigits[2])
            {
                return(true);
            }
            nr = pwDigits[end];
            if (nr == pwDigits[end - 1] && nr != pwDigits[end - 2])
            {
                return(true);
            }

            for (int i = 1; i < end - 1; i++)
            {
                int current   = pwDigits[i];
                int before    = pwDigits[i - 1];;
                int next      = pwDigits[i + 1];;
                int afterNext = pwDigits[i + 2];;
                if (current == next && current != before && current != afterNext)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        private List <Point> handleInstruction(string[] instructions)
        {
            int          x      = 0;
            int          y      = 0;
            List <Point> result = new List <Point>();

            foreach (string instruction in instructions)
            {
                char c     = instruction[0];
                int  steps = SantasLittleHelperClass.StringToInt(instruction.Substring(1));

                int step = (c == 'D') || (c == 'L') ? -1 : 1;

                int goal = 0;
                if (c == 'U')
                {
                    goal = y + steps;
                    while (y < goal)
                    {
                        y += step;
                        result.Add(new Point(x, y));
                    }
                }
                else if (c == 'D')
                {
                    goal = y - steps;
                    while (y > goal)
                    {
                        y += step;
                        result.Add(new Point(x, y));
                    }
                }
                else if (c == 'R')
                {
                    goal = x + steps;
                    while (x < goal)
                    {
                        x += step;
                        result.Add(new Point(x, y));
                    }
                }
                else if (c == 'L')
                {
                    goal = x - steps;
                    while (x > goal)
                    {
                        x += step;
                        result.Add(new Point(x, y));
                    }
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        private int[] readImageDataFromInputfile()
        {
            string[]   fileLines = SantasLittleHelperClass.TextfileToStringArray(INPUT_FILE_PATH);
            string     input     = fileLines[0];
            List <int> numbers   = new List <int>();

            foreach (char c in input)
            {
                numbers.Add(int.Parse(c.ToString()));
            }
            return(numbers.ToArray());
        }
Exemplo n.º 4
0
        private void loadDirectionsFromFile()
        {
            string[]      input      = SantasLittleHelperClass.TextfileToStringArray(INPUT_FILE_PATH);
            List <string> directions = new List <string>();

            for (int i = 0; i < input.Length; i++)
            {
                directions.Add(input[i]);
            }

            wire1_dirs = directions.ToArray()[0].Split(',');
            wire2_dirs = directions.ToArray()[1].Split(',');
        }
Exemplo n.º 5
0
        public Day2()
        {
            string[]   fileLines = SantasLittleHelperClass.TextfileToStringArray(INPUT_FILE_PATH);
            List <int> program   = new List <int>();

            for (int i = 0; i < fileLines.Length; i++)
            {
                string[] split = fileLines[i].Split(',');
                for (int j = 0; j < split.Length; j++)
                {
                    program.Add(SantasLittleHelperClass.StringToInt(split[j]));
                }
            }
            originalMemory = program.ToArray();
        }
Exemplo n.º 6
0
        private int[] inputFileToIntArray()
        {
            string[]   fileLines = SantasLittleHelperClass.TextfileToStringArray(InputFilePath);
            List <int> program   = new List <int>();

            for (int i = 0; i < fileLines.Length; i++)
            {
                string[] split = fileLines[i].Split(',');
                for (int j = 0; j < split.Length; j++)
                {
                    program.Add(SantasLittleHelperClass.StringToInt(split[j]));
                }
            }
            return(program.ToArray());
        }
Exemplo n.º 7
0
        public int calcTotalFuelRequirement()
        {
            string[] fileLines = SantasLittleHelperClass.TextfileToStringArray(INPUT_FILE_PATH);
            int[]    masses    = new int[fileLines.Length];
            for (int i = 0; i < fileLines.Length; i++)
            {
                masses[i] = SantasLittleHelperClass.StringToInt(fileLines[i]);
            }
            int totalFuelReq = 0;

            for (int i = 0; i < masses.Length; i++)
            {
                totalFuelReq += calcFuel(masses[i]);
            }
            return(totalFuelReq);
        }
Exemplo n.º 8
0
        public Day4()
        {
            var minAndMaxVal = input.Split('-');

            if (minAndMaxVal.Length != 2)
            {
                throw new ArgumentException("wrong kind of input string, must be two numbers seperated by a '-'");
            }

            min = SantasLittleHelperClass.StringToInt(minAndMaxVal[0]);
            max = SantasLittleHelperClass.StringToInt(minAndMaxVal[1]);

            if (min > max)
            {
                throw new ArgumentException("wrong kind of input string, first number must be smaller than the second");
            }
        }
Exemplo n.º 9
0
        private void ParseOpCodeValue(int opCodeValue, out OpCode opCode, out ParameterMode[] paramModes)
        {
            int[] digits = SantasLittleHelperClass.IntToDigitArray(opCodeValue);
            opCode = (OpCode)(opCodeValue % 100);
            if (!Enum.IsDefined(typeof(OpCode), opCode))
            {
                throw new ArgumentException();
            }

            List <ParameterMode> modes = new List <ParameterMode>();

            for (int i = digits.Length - 3; i >= 0; i--)
            {
                modes.Add((ParameterMode)digits[i]);
            }

            while (modes.Count < 3)
            {
                modes.Add(ParameterMode.Position);
            }
            paramModes = modes.ToArray();
        }
Exemplo n.º 10
0
        public bool isValidPassword(int pw)
        {
            int[] pwDigits = SantasLittleHelperClass.IntToDigitArray(pw);

            // It is a six-digit number.
            if (pwDigits.Length != 6)
            {
                return(false);
            }
            //Two adjacent digits are the same (like 22 in 122345).
            if (!areThereAdjacentDigits(pwDigits))
            {
                return(false);
            }
            //Going from left to right, the digits never decrease; they only ever increase or stay the same (like 111123 or 135679).
            if (!doDigitsIncrease(pwDigits))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 11
0
 private string[] getCommandsFromFile()
 {
     return(SantasLittleHelperClass.TextfileToStringArray(INPUT_FILE_PATH));
 }
Exemplo n.º 12
0
        private Dictionary <Point, int> instructionsToWireDictionary(string[] instructions)
        {
            Dictionary <Point, int> result = new Dictionary <Point, int>();
            int wire_length = 0;
            int x           = 0;
            int y           = 0;

            foreach (string instruction in instructions)
            {
                char c     = instruction[0];
                int  steps = SantasLittleHelperClass.StringToInt(instruction.Substring(1));


                int step = (c == 'D') || (c == 'L') ? -1 : 1;

                int goal = 0;
                if (c == 'U')
                {
                    goal = y + steps;
                    while (y < goal)
                    {
                        y += step;
                        wire_length++;
                        try {
                            result.Add(new Point(x, y), wire_length);
                        }
                        catch (Exception e) { }
                    }
                }
                else if (c == 'D')
                {
                    goal = y - steps;
                    while (y > goal)
                    {
                        y += step;
                        wire_length++;
                        try {
                            result.Add(new Point(x, y), wire_length);
                        }
                        catch (Exception e) { }
                    }
                }
                else if (c == 'R')
                {
                    goal = x + steps;
                    while (x < goal)
                    {
                        x += step;
                        wire_length++;
                        try {
                            result.Add(new Point(x, y), wire_length);
                        }
                        catch (Exception e) { }
                    }
                }
                else if (c == 'L')
                {
                    goal = x - steps;
                    while (x > goal)
                    {
                        x += step;
                        wire_length++;
                        try {
                            result.Add(new Point(x, y), wire_length);
                        }
                        catch (Exception e) { }
                    }
                }
            }
            return(result);
        }