Пример #1
0
        public static void PartOne()
        {
            string input = InputHelper.GetInputFromFile("22");

            string[]      lines = input.Split(Environment.NewLine);
            StackShuffler stack = new StackShuffler();

            stack.Start(10007);

            foreach (string line in lines)
            {
                if (line.StartsWith("deal with increment "))
                {
                    stack.DealWithIncrement(int.Parse(line.Split(' ')[3]));
                }
                if (line.StartsWith("cut "))
                {
                    stack.CutNCards(int.Parse(line.Split(' ')[1]));
                }
                if (line == "deal into new stack")
                {
                    stack.DealIntoNewStack();
                }
            }

            Console.WriteLine("Position of card 2019 : " + stack.GetStack().IndexOf(2019));
        }
Пример #2
0
        public void Start_Should_Setup_Stack_Of_Given_Size_In_Order()
        {
            StackShuffler shufflerTested = new StackShuffler();

            shufflerTested.Start(10);

            var stack = shufflerTested.GetStack();

            stack.Count.Should().Be(10);
            stack.Should().ContainInOrder(Enumerable.Range(0, 10));
        }
Пример #3
0
        public void Deal_Into_New_Stack_Should_Reverse_The_Stack()
        {
            StackShuffler shufflerTested = new StackShuffler();

            shufflerTested.Start(10);

            shufflerTested.DealIntoNewStack();

            var stack = shufflerTested.GetStack();

            stack.Count.Should().Be(10);
            stack.Should().ContainInOrder(Enumerable.Range(0, 10).Reverse());
        }
Пример #4
0
        public void DealWithIncrement_Should_Distibute_Cards_Every_N_Steps()
        {
            StackShuffler shufflerTested = new StackShuffler();

            shufflerTested.Start(10);

            shufflerTested.DealWithIncrement(9);

            var stack = shufflerTested.GetStack();

            stack.Count.Should().Be(10);
            stack.Should().ContainInOrder(new List <int> {
                0, 9, 8, 7, 6, 5, 4, 3, 2, 1
            });
        }
Пример #5
0
        public void CutNCards_Negative_Should_Put_Size_Minus_N_Cards_At_The_End()
        {
            StackShuffler shufflerTested = new StackShuffler();

            shufflerTested.Start(10);

            shufflerTested.CutNCards(-4);

            var stack = shufflerTested.GetStack();

            stack.Count.Should().Be(10);
            stack.Should().ContainInOrder(new List <int> {
                6, 7, 8, 9, 0, 1, 2, 3, 4, 5
            });
        }
Пример #6
0
        public void CutNCards_Should_Put_N_Cards_At_The_End()
        {
            StackShuffler shufflerTested = new StackShuffler();

            shufflerTested.Start(10);

            shufflerTested.CutNCards(3);

            var stack = shufflerTested.GetStack();

            stack.Count.Should().Be(10);
            stack.Should().ContainInOrder(new List <int> {
                3, 4, 5, 6, 7, 8, 9, 0, 1, 2
            });
        }
Пример #7
0
        public void Chaining_Calls_Should_Yield_Correct_Result()
        {
            StackShuffler shufflerTested = new StackShuffler();

            shufflerTested.Start(10);

            shufflerTested.DealIntoNewStack();
            shufflerTested.CutNCards(-2);
            shufflerTested.DealWithIncrement(7);
            shufflerTested.CutNCards(8);
            shufflerTested.CutNCards(-4);
            shufflerTested.DealWithIncrement(7);
            shufflerTested.CutNCards(3);
            shufflerTested.DealWithIncrement(9);
            shufflerTested.DealWithIncrement(3);
            shufflerTested.CutNCards(-1);

            var stack = shufflerTested.GetStack();

            stack.Count.Should().Be(10);
            stack.Should().ContainInOrder(new List <int> {
                9, 2, 5, 8, 1, 4, 7, 0, 3, 6
            });
        }