Esempio n. 1
0
        public override (string message, object answer) SolvePart2()
        {
            const long DeckSize   = 119_315_717_514_047;
            const long Iterations = 101_741_582_076_661;

            DeckData passData = new DeckData(DeckSize);

            // Determine the result of a single shuffle pass on the deck state
            foreach (Technique technique in _techniques)
            {
                technique.Apply(passData);
            }

            // Calculate the result of applying the shuffle many times
            DeckData finalData = new DeckData(DeckSize);

            finalData.increment = MathUtil.ModPower(passData.increment, Iterations, DeckSize);
            finalData.offset    = (passData.offset * (1 - finalData.increment) *
                                   MathUtil.ModPower(1 - passData.increment, DeckSize - 2, DeckSize)) % DeckSize;

            BigInteger card = (finalData.offset + (finalData.increment * 2020)) % DeckSize;

            return($"Card 2020 after {Iterations} shuffles:", card);
        }
Esempio n. 2
0
 public abstract void Apply(DeckData deck);
Esempio n. 3
0
 public override void Apply(DeckData deck)
 {
     deck.increment *= -1;
     deck.offset    += deck.increment;
 }