Exemple #1
0
        static void Puzzle2(OrigamiGrid grid)
        {
            foreach (var item in grid.Instuctions)
            {
                if (item.Direction == FoldDirection.X)
                {
                    grid.FoldX(item.Target);
                    continue;
                }

                grid.FoldY(item.Target);
            }

            grid.DumpPoints();
        }
Exemple #2
0
        static long Puzzle1(OrigamiGrid grid)
        {
            var direction = grid.Instuctions[0].Direction;
            var target    = grid.Instuctions[0].Target;

            if (direction == FoldDirection.X)
            {
                grid.FoldX(target);
            }
            else
            {
                grid.FoldY(target);
            }

            return(grid.CountPoints());
        }
Exemple #3
0
        static OrigamiGrid ParseInput(List <string> data)
        {
            var maxX   = -1;
            var maxY   = -1;
            var coords = new List <(int x, int y)>();
            var folds  = new List <Fold>();
            var isData = true;

            foreach (var line in data)
            {
                if (line.Length == 0)
                {
                    isData = false;
                    continue;
                }

                if (isData)
                {
                    var p = line.Split(",").Select(int.Parse).ToList();
                    maxX = (p[0] > maxX) ? p[0] : maxX;
                    maxY = (p[1] > maxY) ? p[1] : maxY;
                    coords.Add((p[0], p[1]));
                    continue;
                }

                // Read fold instructions
                var detail = line.Split(INSTURCTION_SPLIT, StringSplitOptions.RemoveEmptyEntries).ToList();
                var fold   = new Fold();
                fold.Direction = (detail[0] == "x" || detail[0] == "X") ? FoldDirection.X : FoldDirection.Y;
                fold.Target    = int.Parse(detail[1]);
                folds.Add(fold);
            }

            var result = new OrigamiGrid(maxX + 1, maxY + 1);

            result.Plot(coords);
            result.Instuctions = folds;
            return(result);
        }