Ejemplo n.º 1
0
        private void InsertMarble(int value)
        {
            int currentIndex         = Marbles.IndexOf(CurrentMarble);
            int secondClockwiseIndex = (currentIndex + 2) % Marbles.Count;

            if (secondClockwiseIndex == 0)
            {
                Marbles.Add(value);
            }
            else
            {
                Marbles.Insert(secondClockwiseIndex, value);
            }

            CurrentMarble = value;
        }
Ejemplo n.º 2
0
        private long CalculateScore(int value)
        {
            long score = value;

            int seventhClockwiseIndex = (Marbles.IndexOf(CurrentMarble) - 7) % Marbles.Count;

            if (seventhClockwiseIndex < 0)
            {
                seventhClockwiseIndex = Marbles.Count + seventhClockwiseIndex;
            }

            score += Marbles[seventhClockwiseIndex];
            Marbles.RemoveAt(seventhClockwiseIndex);

            CurrentMarble = Marbles[seventhClockwiseIndex];

            return(score);
        }
Ejemplo n.º 3
0
        private static void CalculateScore(int numberOfPlayers, int numberOfMarbles)
        {
            Marbles     marbles = new Marbles();
            List <long> score   = new List <long>();

            foreach (int i in Enumerable.Repeat(0, numberOfPlayers + 1))
            {
                score.Add((long)i);
            }

            int currentPlayerID = 1;

            foreach (int i in Enumerable.Range(1, numberOfMarbles))
            {
                score[currentPlayerID] += marbles.InsertMarble(i);
                currentPlayerID         = (currentPlayerID >= numberOfPlayers) ? 1 : currentPlayerID + 1;
            }
            Console.WriteLine(score.Max());
        }