コード例 #1
0
ファイル: Day18.cs プロジェクト: FHoekstra74/aoc2018
        public static void Go()
        {
            string[] lines = File.ReadAllLines(@"C:\aoc2018\18\input.txt");
            int      size  = lines[0].Length;

            Acre[,] grid = new Acre[size, size];

            int    x             = 0;
            int    y             = 0;
            string tznd          = "";
            int    questionbsize = 1000000000;

            foreach (string line in lines)
            {
                foreach (char c in line)
                {
                    grid[x, y++] = new Acre(c);
                }
                x++;
                y = 0;
            }

            for (int i = 0; i < 1500; i++)
            {
                for (int j = 0; j < grid.GetLength(0); j++)
                {
                    for (int k = 0; k < grid.GetLength(1); k++)
                    {
                        grid[j, k].setnextcontent(Itemcount(j, k, '|', grid), Itemcount(j, k, '#', grid));
                    }
                }

                foreach (Acre a in grid)
                {
                    a.content = a.nextcontent;
                }

                if (i == 1000)
                {
                    tznd = UniquePrint(grid);
                }

                if (i > 1000 && UniquePrint(grid) == tznd && questionbsize > 1500)
                {
                    while (questionbsize > 1200)
                    {
                        questionbsize = questionbsize - (i - 1000);
                    }
                }

                if (i == 9 || i == (questionbsize - 1))
                {
                    Console.WriteLine("Resource value after {0} minutes: {1}", i + 1, Resourcevalue(grid));
                }
            }
        }
コード例 #2
0
        private static Acre[,] LoadArea(string path)
        {
            string[] lines = File.ReadAllLines(path);

            Acre[,] area = new Acre[lines.Length, lines[0].Length];

            for (int x = 0; x < area.GetLength(1); ++x)
            {
                for (int y = 0; y < area.GetLength(0); ++y)
                {
                    area[y, x] = Decode(lines[y][x]);
                }
            }

            return(area);
        }