Пример #1
0
        public long CalculatePartTwo()
        {
            var arrangements = new Dictionary <long, long> {
                { Jolts.Max() + 3, 1 }
            };

            foreach (var jolt in  new[] { 0 }.Concat(Jolts).Reverse())
            {
                arrangements.Add(jolt, Options
                                 .Where(option => arrangements.ContainsKey(jolt + option))
                                 .Sum(option => arrangements[jolt + option])
                                 );
            }

            return(arrangements.Last().Value);
        }
Пример #2
0
        public int CalculatePartOne()
        {
            var joltAmount = 0;

            while (joltAmount < Jolts.Max())
            {
                if (Jolts.Contains(joltAmount + 1))
                {
                    joltAmount++;
                    OneJoltDifference++;
                    continue;
                }

                if (Jolts.Contains(joltAmount + 3))
                {
                    joltAmount += 3;
                    ThreeJoltDifference++;
                }
            }

            return(OneJoltDifference * ThreeJoltDifference);
        }