Beispiel #1
0
        public static long Run(string input)
        {
            //input = _input;
            var nums = InputUtils.SplitLinesIntoLongList(input);

            for (int i = PREAMBLE; i < nums.Count; i++)
            {
                var sum = nums[i];
                if (!Has2Addends(nums, sum, i))
                {
                    return(GetSmallPlusLarge(nums, sum, i));
                }
            }
            return(-1);
        }
Beispiel #2
0
        public static int Run(string input)
        {
            int matches      = 0;
            var passwordSets = InputUtils.SplitLinesIntoPasswordList(input);

            foreach (var passwordSet in passwordSets)
            {
                var count = passwordSet.Password.Count(c => c == passwordSet.Letter.ToCharArray()[0]);
                if (count >= passwordSet.Min && count <= passwordSet.Max)
                {
                    matches++;
                }
            }
            return(matches);
        }
Beispiel #3
0
        public static int RunPart2(string input)
        {
            int matches      = 0;
            var passwordSets = InputUtils.SplitLinesIntoPasswordList(input);

            foreach (var passwordSet in passwordSets)
            {
                var password = passwordSet.Password;
                var letter   = passwordSet.Letter;
                if ((password[passwordSet.Min - 1] == letter.ToCharArray()[0] && password[passwordSet.Max - 1] != letter.ToCharArray()[0]) ||
                    (password[passwordSet.Min - 1] != letter.ToCharArray()[0] && password[passwordSet.Max - 1] == letter.ToCharArray()[0]))
                {
                    matches++;
                }
            }
            return(matches);
        }
Beispiel #4
0
        public static int Run(string input)
        {
            var commands = new List <Day8Command>();
            //input = _input;
            var lines = InputUtils.SplitLinesIntoStringArray(input);

            foreach (var line in lines)
            {
                var tokens  = line.Trim().Split(" ");
                var command = new Day8Command()
                {
                    Command = tokens[0], Value = int.Parse(tokens[1])
                };
                commands.Add(command);
            }

            for (int i = 0; i < commands.Count; i++)
            {
                var commandsCopy = commands.ConvertAll(command => new Day8Command()
                {
                    Command = command.Command, Value = command.Value
                });
                if (commandsCopy[i].Command == "acc")
                {
                    continue;
                }
                else
                {
                    if (commandsCopy[i].Command == "nop")
                    {
                        commandsCopy[i].Command = "jmp";
                    }
                    else
                    {
                        commandsCopy[i].Command = "nop";
                    }
                }
                var result = new Day8Program().RunProgram(commandsCopy);
                if (result != -999999)
                {
                    return(result);
                }
            }
            return(-1);
        }
Beispiel #5
0
        public static long Run(string input)
        {
            var map        = InputUtils.SplitLinesIntoStringArray(input);
            var treeValues = new List <int>();

            treeValues.Add(GetTreesValue(map, 1, 1));
            treeValues.Add(GetTreesValue(map, 3, 1));
            treeValues.Add(GetTreesValue(map, 5, 1));
            treeValues.Add(GetTreesValue(map, 7, 1));
            treeValues.Add(GetTreesValue(map, 1, 2));
            long product = 1;

            foreach (var treeValue in treeValues)
            {
                product *= (long)treeValue;
            }
            return(product);
        }
Beispiel #6
0
        //private static Dictionary<string, List<Day7BagContents>> _dynamicColorDict;

        public static long Run(string input)
        {
            //input = _input2;
            var lines = InputUtils.SplitLinesIntoStringArray(input);

            _colorDict          = GetColorDict(lines);
            _dynamicNumBagsDict = new Dictionary <string, long>();

            //foreach (var kvp in _colorDict)
            //{
            //    var bagCount = GetBagCount(kvp.Key);
            //    if (!_dynamicNumBagsDict.ContainsKey(kvp.Key))
            //    {
            //        _dynamicNumBagsDict.Add(kvp.Key, bagCount);
            //    }
            //}
            return(GetBagCount("shiny gold"));
        }
Beispiel #7
0
        public static long Run(string input)
        {
            //input = _input;
            var joltageIntList = InputUtils.SplitLinesIntoIntList(input);

            joltageIntList.Sort();
            joltageIntList.Reverse();
            long combos      = 0;
            var  joltageList = new List <Day10Joltage>();

            for (int i = 0; i < joltageIntList.Count; i++)
            {
                joltageList.Add(new Day10Joltage {
                    Joltage = joltageIntList[i], Pos = i
                });
            }
            var nextJoltages = GetValidNextJoltages(joltageList, 0);

            foreach (var joltage in nextJoltages)
            {
                combos += GetCombinations(joltageList, joltage.Pos, 0);
            }
            return(combos);
        }