Exemplo n.º 1
0
 public ShuffleSequence(ShuffleSequence copyMe) : this(copyMe.DeckSize)
 {
     foreach (IShuffleAction action in copyMe.shuffleActions)
     {
         shuffleActions.Add(action.Copy());
     }
 }
Exemplo n.º 2
0
        public void AddToSequence(ShuffleSequence other)
        {
            List <IShuffleAction> newActions = new List <IShuffleAction>();

            foreach (IShuffleAction action in other.shuffleActions)
            {
                newActions.Add(action.Copy());
            }
            shuffleActions.AddRange(newActions);
        }
Exemplo n.º 3
0
        protected override void SolvePartTwo()
        {
            BigInteger deckSize      = BigInteger.Parse("119315717514047");
            BigInteger shuffleNtimes = BigInteger.Parse("101741582076661");
            BigInteger findCard      = 2020;

            var shuffleSequence = new ShuffleSequence(shuffleMoves, deckSize);

            shuffleSequence.CompressSequence();

            var repeatedShuffles = SequenceAfterNRepetitions(shuffleSequence, shuffleNtimes);

            resultPartTwo = repeatedShuffles.CardPositionBeforeShuffle(findCard).ToString();
        }
Exemplo n.º 4
0
        public static ShuffleSequence SequenceAfterNRepetitions(ShuffleSequence shufSeq, BigInteger reps)
        {
            List <ShuffleSequence> shufflesPerBit = new List <ShuffleSequence> {
                new ShuffleSequence(shufSeq)
            };
            int        bitsNeeded       = 0;
            BigInteger previousBitValue = 1;
            BigInteger bitValue         = 2;

            //Create shufflesequences for each bit value up to and including the largest bit value smaller than "reps"
            while (bitValue < reps)
            {
                var next = new ShuffleSequence(shufflesPerBit[bitsNeeded]);
                next.AddToSequence(next);
                next.CompressSequence();
                shufflesPerBit.Add(next);
                previousBitValue = bitValue;
                bitValue         = previousBitValue * 2;
                bitsNeeded++;
            }

            //Combine shufflesequences for each activated bit in the bit-representation of "reps"
            var        repeatedShuffleSequence = new ShuffleSequence(shufSeq.DeckSize);
            BigInteger remaining = reps;

            for (int i = shufflesPerBit.Count - 1; i >= 0; i--)
            {
                if (previousBitValue <= remaining)
                {
                    repeatedShuffleSequence.AddToSequence(shufflesPerBit[i]);
                    repeatedShuffleSequence.CompressSequence();
                    remaining = remaining - previousBitValue;
                }
                previousBitValue = previousBitValue / 2;
            }

            return(repeatedShuffleSequence);
        }
Exemplo n.º 5
0
        protected override void SolvePartOne()
        {
            var shuffleSequence = new ShuffleSequence(shuffleMoves, 10007);

            resultPartOne = shuffleSequence.CardPositionAfterShuffle(2019).ToString();
        }