Пример #1
0
        public override Tuple <string, string> getResult()
        {
            int Sum          = 0;
            int Sum2         = 0;
            int SerialNumber = 0;

            Int32.TryParse(Instruction, out SerialNumber);
            int[,] TheGrid = new int[301, 301];
            for (int x = 1; x <= 300; x++)
            {
                for (int y = 1; y <= 300; y++)
                {
                    if (x == 122 && y == 79)
#pragma warning disable CS0642 // Possible mistaken empty statement
                    {
                        ;
                    }
#pragma warning restore CS0642 // Possible mistaken empty statement
                    int Number = ((x + 10) * y + SerialNumber) * (x + 10);
                    Number        = Number % 1000;
                    Number        = Number / 100;
                    Number       -= 5;
                    TheGrid[x, y] = Number;
                }
            }
            Coordinate TopLeft     = GetSum(ref TheGrid, ref Sum, 3);
            Coordinate PartOne     = new Coordinate(TopLeft);
            Coordinate ToppestLeft = new Coordinate(0, 0);
            int        ToppestInt  = 0;
            int        LargestSum  = 0;
            for (int i = 1; i <= 50; i++)
            {
                TopLeft = GetSum(ref TheGrid, ref Sum, i);
                if (Sum > LargestSum)
                {
                    LargestSum  = Sum;
                    ToppestLeft = new Coordinate(TopLeft);
                    ToppestInt  = i;
                }
            }
            return(Tuple.Create(PartOne.ToString(), ToppestLeft.ToString() + "," + ToppestInt.ToString()));
        }
Пример #2
0
        public override Tuple <string, string> getResult()
        {
            Coordinate Sum = new Coordinate(0, 0);
            Wagon      Sum2;

            char[,] TheGrid = new char[Instructions[0].Length, Instructions.Length];
            List <Wagon> Wagons = new List <Wagon>();

            for (int x = 0; x < Instructions[0].Length; x++)
            {
                for (int y = 0; y < Instructions.Length; y++)
                {
                    char c = Instructions[y][x];
                    TheGrid[x, y] = c;
                    if (c == '<' || c == '>' || c == '^' || c == 'v')
                    {
                        Wagons.Add(new Wagon(x, y, c));
                        TheGrid[x, y] = '-';
                    }
                }
            }
            bool         Safe          = true;
            int          DebugIterator = 0;
            List <Wagon> CrashWagons   = new List <Wagon>();

            while (Wagons.Count > 1)
            {
                DebugIterator++;
                Wagons = Wagons.OrderBy(s => s.y).ThenBy(s => s.x).ToList();
                foreach (Wagon w in Wagons)
                {
                    if (Wagons.Contains(w.PeekPush()))
                    {
                        Sum = w.PeekPush();
                        CrashWagons.Add(Wagons.Find(w.PeekPush().Equals));
                        CrashWagons.Add(w);
                    }
                    w.Push();
                    char c = TheGrid[w.x, w.y];
                    switch (c)
                    {
                    case '+':
                        w.Choice();
                        break;

                    case '-':
                    case '|':
                        ;
                        break;

                    case ' ':
                        ;    //for debug
                        break;

                    default:     //I guess corner then
                        w.Turn(c);
                        break;
                    }
                }
                foreach (Wagon w in CrashWagons)
                {
                    Wagons.Remove(w);
                }
                CrashWagons.Clear();
            }
            Sum2 = Wagons.First();
            return(Tuple.Create(Sum.ToString(), Sum2.ToString()));
        }