コード例 #1
0
        private static void VisualizeSky(EnumerableReader <Star> stars, int minX, int maxX)
        {
            for (Star star = stars.TakeFirst(), nextStar = null; star != null; star = nextStar)
            {
                var builder = new StringBuilder(new string(Enumerable.Repeat('.', 1 + maxX - minX).ToArray()));
                int y       = star.Position.Y;
                builder[star.Position.X - minX] = '#';

                for (nextStar = stars.TakeFirst(); nextStar != null && nextStar.Position.Y == star.Position.Y; nextStar = stars.TakeFirst())
                {
                    builder[nextStar.Position.X - minX] = '#';
                }

                Console.WriteLine(builder);

                if (nextStar != null)
                {
                    for (int i = star.Position.Y + 1; i < nextStar.Position.Y; i++)
                    {
                        builder = new StringBuilder(new string(Enumerable.Repeat('.', 1 + maxX - minX).ToArray()));
                        Console.WriteLine(builder);
                    }
                }
            }
        }
コード例 #2
0
        private static LicenseNode GetNode(EnumerableReader <int> input)
        {
            var numChildren = input.TakeFirst();
            var numMetadata = input.TakeFirst();

            var children = new LicenseNode[numChildren];

            for (int i = 0; i < numChildren; i++)
            {
                children[i] = GetNode(input);
            }

            return(new LicenseNode(children, input.TakeN(numMetadata)));
        }