Exemplo n.º 1
0
        public static long Run(string input)
        {
            //input = _input
            var joltages = InputUtils.SplitLinesIntoIntList(input);
            var volt1    = 0;
            var volt3    = 0;

            joltages.Sort();
            var prev = 0;

            for (int i = 0; i < joltages.Count; i++)
            {
                if (joltages[i] - prev == 1)
                {
                    volt1++;
                }
                else if (joltages[i] - prev == 3)
                {
                    volt3++;
                }
                prev = joltages[i];
            }
            volt3++;
            return(volt1 * volt3);
        }
Exemplo n.º 2
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);
        }