Example #1
0
        public void DealWithIncrementNBackwardsTest()
        {
            // Item 1: Deck size
            // Item 2: N
            // Item 3: Start card index
            // Item 4: Expected end card index
            // Test examples taken from here:
            // https://adventofcode.com/2019/day/22
            var testData = new List <Tuple <int, int, int, int> >()
            {
                // To deal with increment N, start by clearing enough space on
                // your table to lay out all of the cards individually in a long
                // line. Deal the top card into the leftmost position. Then, move
                // N positions to the right and deal the next card there. If you
                // would move into a position past the end of the space on your
                // table, wrap around and keep counting from the leftmost card
                // again.
                // Continue this process until you run out of cards.
                // For example, to deal with increment 3:
                //0 1 2 3 4 5 6 7 8 9   Your deck
                //. . . . . . . . . .   Space on table
                //^                     Current position
                //
                //Deal the top card to the current position:
                //
                //  1 2 3 4 5 6 7 8 9   Your deck
                //0 . . . . . . . . .   Space on table
                //^                     Current position
                //
                //Move the current position right 3:
                //
                //  1 2 3 4 5 6 7 8 9   Your deck
                //0 . . . . . . . . .   Space on table
                //      ^               Current position
                //
                //Deal the top card:
                //
                //    2 3 4 5 6 7 8 9   Your deck
                //0 . . 1 . . . . . .   Space on table
                //      ^               Current position
                //
                //Move right 3 and deal:
                //
                //      3 4 5 6 7 8 9   Your deck
                //0 . . 1 . . 2 . . .   Space on table
                //            ^         Current position
                //
                //Move right 3 and deal:

                //        4 5 6 7 8 9   Your deck
                //0 . . 1 . . 2 . . 3   Space on table
                //                  ^   Current position
                //
                //Move right 3, wrapping around, and deal:
                //
                //          5 6 7 8 9   Your deck
                //0 . 4 1 . . 2 . . 3   Space on table
                //    ^                 Current position
                //
                //And so on:
                //
                //0 7 4 1 8 5 2 9 6 3   Space on table
                Tuple.Create(10, 3, 0, 0),
                Tuple.Create(10, 3, 1, 7),
                Tuple.Create(10, 3, 2, 4),
                Tuple.Create(10, 3, 3, 1),
                Tuple.Create(10, 3, 4, 8),
                Tuple.Create(10, 3, 5, 5),
                Tuple.Create(10, 3, 6, 2),
                Tuple.Create(10, 3, 7, 9),
                Tuple.Create(10, 3, 8, 6),
                Tuple.Create(10, 3, 9, 3),

                // Deck size 10, deal with increment 7:
                // 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
                // 0                    1                    2                    3                    4                    5                    6                    7                    8                    9
                // =>
                // 00 01 02 03 04 05 06 07 08 09
                // 0                    1
                // 10 11 12 13 14 15 16 17 18 19
                //             2
                // 20 21 22 23 24 25 26 27 28 29
                //    3                    4
                // 30 31 32 33 34 35 36 37 38 39
                //                5
                // 40 41 42 43 44 45 46 47 48 49
                //       6                    7
                // 50 51 52 53 54 55 56 57 58 59
                //                   8
                // 60 61 62 63 64 65 66 67 68 69
                //          9
                // ->
                // 0  3  6  9  2  5  8  1  4  7
                Tuple.Create(10, 7, 0, 0),
                Tuple.Create(10, 7, 1, 3),
                Tuple.Create(10, 7, 2, 6),
                Tuple.Create(10, 7, 3, 9),
                Tuple.Create(10, 7, 4, 2),
                Tuple.Create(10, 7, 5, 5),
                Tuple.Create(10, 7, 6, 8),
                Tuple.Create(10, 7, 7, 1),
                Tuple.Create(10, 7, 8, 4),
                Tuple.Create(10, 7, 9, 7),
            };

            foreach (var testExample in testData)
            {
                var result = ShuffleHelper.GetShuffleFunctionDealWithIncrementN(
                    n: testExample.Item2,
                    deckSize: testExample.Item1)
                             .GetInverse()
                             .Evaluate(testExample.Item3);
                Assert.Equal(testExample.Item4, result);
            }
        }
Example #2
0
        public void DealWithIncrementNTest()
        {
            // Item 1: Deck size
            // Item 2: N
            // Item 3: Start card index
            // Item 4: Expected end card index
            // Test examples taken from here:
            // https://adventofcode.com/2019/day/22
            var testData = new List <Tuple <int, int, int, int> >()
            {
                // To deal with increment N, start by clearing enough space on
                // your table to lay out all of the cards individually in a long
                // line. Deal the top card into the leftmost position. Then, move
                // N positions to the right and deal the next card there. If you
                // would move into a position past the end of the space on your
                // table, wrap around and keep counting from the leftmost card
                // again.
                // Continue this process until you run out of cards.
                // For example, to deal with increment 3:
                //0 1 2 3 4 5 6 7 8 9   Your deck
                //. . . . . . . . . .   Space on table
                //^                     Current position
                //
                //Deal the top card to the current position:
                //
                //  1 2 3 4 5 6 7 8 9   Your deck
                //0 . . . . . . . . .   Space on table
                //^                     Current position
                //
                //Move the current position right 3:
                //
                //  1 2 3 4 5 6 7 8 9   Your deck
                //0 . . . . . . . . .   Space on table
                //      ^               Current position
                //
                //Deal the top card:
                //
                //    2 3 4 5 6 7 8 9   Your deck
                //0 . . 1 . . . . . .   Space on table
                //      ^               Current position
                //
                //Move right 3 and deal:
                //
                //      3 4 5 6 7 8 9   Your deck
                //0 . . 1 . . 2 . . .   Space on table
                //            ^         Current position
                //
                //Move right 3 and deal:

                //        4 5 6 7 8 9   Your deck
                //0 . . 1 . . 2 . . 3   Space on table
                //                  ^   Current position
                //
                //Move right 3, wrapping around, and deal:
                //
                //          5 6 7 8 9   Your deck
                //0 . 4 1 . . 2 . . 3   Space on table
                //    ^                 Current position
                //
                //And so on:
                //
                //0 7 4 1 8 5 2 9 6 3   Space on table

                Tuple.Create(10, 3, 0, 0),
                Tuple.Create(10, 3, 1, 3),
                Tuple.Create(10, 3, 2, 6),
                Tuple.Create(10, 3, 3, 9),
                Tuple.Create(10, 3, 4, 2),
                Tuple.Create(10, 3, 5, 5),
                Tuple.Create(10, 3, 6, 8),
                Tuple.Create(10, 3, 7, 1),
                Tuple.Create(10, 3, 8, 4),
                Tuple.Create(10, 3, 9, 7),
            };

            foreach (var testExample in testData)
            {
                var result = ShuffleHelper.GetShuffleFunctionDealWithIncrementN(
                    n: testExample.Item2,
                    deckSize: testExample.Item1)
                             .Evaluate(testExample.Item3);
                Assert.Equal(testExample.Item4, result);
            }
        }