コード例 #1
0
        static bool[,] LoadPaper(string filename)
        {
            var width  = 0;
            var height = 0;
            var reader = FileIterator.CreateLineReader(filename);

            for (var line = reader(); line != ""; line = reader())
            {
                var parts = line.Split(",");
                var x     = int.Parse(parts[0]);
                var y     = int.Parse(parts[1]);
                if (width < x)
                {
                    width = x;
                }
                if (height < y)
                {
                    height = y;
                }
            }

            var paper = new bool[width + 1, height + 1];

            reader = FileIterator.CreateLineReader(filename);
            for (var line = reader(); line != ""; line = reader())
            {
                var parts = line.Split(",");
                var x     = int.Parse(parts[0]);
                var y     = int.Parse(parts[1]);
                paper[x, y] = true;
            }

            return(paper);
        }
コード例 #2
0
            public Game(string filename)
            {
                var reader = FileIterator.CreateLineReader(filename);

                players[0] = int.Parse(reader().Groups(@"position: (\d)")[0]) - 1;
                players[1] = int.Parse(reader().Groups(@"position: (\d)")[0]) - 1;
            }
コード例 #3
0
ファイル: Day14.cs プロジェクト: elpollouk/Advent2017
        static (string template, Dictionary <(char, char), char> rules) LoadData(string filename)
        {
            Dictionary <(char, char), char> rules = new();

            var reader   = FileIterator.CreateLineReader(filename);
            var template = reader();

            reader();

            foreach (var mapping in FileIterator.Lines(reader))
            {
                var groups = mapping.Groups("(.)(.) -> (.)");
                rules.Add((groups[0][0], groups[1][0]), groups[2][0]);
            }

            return(template, rules);
        }
コード例 #4
0
            public Image(string filename)
            {
                var reader    = FileIterator.CreateLineReader(filename);
                var rulesLine = reader();

                for (var i = 0; i < rulesLine.Length; i++)
                {
                    rules[i] = rulesLine[i] == '#';
                }

                reader();

                var y = 0;

                foreach (var line in FileIterator.Lines(reader))
                {
                    for (var x = 0; x < line.Length; x++)
                    {
                        if (line[x] == '#')
                        {
                            points.Add((x, y));
                            if (x < minX)
                            {
                                minX = x;
                            }
                            else if (x > maxX)
                            {
                                maxX = x;
                            }
                            if (y < minY)
                            {
                                minY = y;
                            }
                            else if (y > maxY)
                            {
                                maxY = y;
                            }
                        }
                    }
                    y++;
                }
            }
コード例 #5
0
        static List <int> LoadFolds(string filename)
        {
            var reader = FileIterator.CreateLineReader(filename);

            while (reader() != "")
            {
            }

            var folds = new List <int>();

            for (var line = reader(); line != null; line = reader())
            {
                var parts = line.Groups("fold along (.)=(\\d+)");
                var axis  = int.Parse(parts[1]);
                if (parts[0] == "y")
                {
                    axis = -axis;
                }
                folds.Add(axis);
            }

            return(folds);
        }