Esempio n. 1
0
        private static void MainDay25()
        {
            var stars          = Parse(Input);
            var constellations = new List <Constellation>();

            for (var i = 0; i < stars.Count; i++)
            {
                var scanner = stars[i];
                if (scanner.Constellation == null)
                {
                    var temp = new Constellation();
                    temp.Add(scanner);
                    constellations.Add(temp);
                }
                for (var j = i + 1; j < stars.Count; j++)
                {
                    var scanned = stars[j];
                    if (scanner.Constellation == scanned.Constellation)
                    {
                        continue;
                    }
                    if (scanner.Distance(scanned) <= 3)
                    {
                        if (scanned.Constellation == null)
                        {
                            scanner.Constellation.Add(scanned);
                        }
                        else
                        {
                            if (!constellations.Remove(scanner.Constellation))
                            {
                                Console.WriteLine($"Failed to remove constellation {scanner.Constellation}.");
                            }

                            scanned.Constellation.Merge(scanner.Constellation);
                        }
                    }
                }
            }
            Console.WriteLine($"Constellation count {constellations.Count}");
        }
Esempio n. 2
0
        private DeepSpaceData()
        {
            this.Stars              = new ArrayList();
            this.Messier            = new ArrayList();
            this.Constellation      = new ArrayList();
            this.ConstellationNames = new ArrayList();

            Assembly     asembly      = Assembly.GetExecutingAssembly();
            Stream       txtStream    = asembly.GetManifestResourceStream("SpaceObjects.Resources.HYG.txt");
            StreamReader streamReader = new StreamReader(txtStream);

            string delimStr = ";";

            char[]           delimiter = delimStr.ToCharArray();
            NumberFormatInfo provider  = new NumberFormatInfo();

            provider.NumberDecimalSeparator = ".";
            while (streamReader.Peek() >= 0)
            {
                string[] split = streamReader.ReadLine().Split(delimiter, 20);
                Stars.Add(
                    new Star(
                        split[0],
                        split[1],
                        Convert.ToDouble(split[2], provider) * 15,
                        Convert.ToDouble(split[3], provider),
                        Convert.ToDouble(split[4], provider),
                        split[5]));
            }
            Stars.TrimToSize();

            asembly      = Assembly.GetExecutingAssembly();
            txtStream    = asembly.GetManifestResourceStream("SpaceObjects.Resources.Messier.txt");
            streamReader = new StreamReader(txtStream);

            while (streamReader.Peek() >= 0)
            {
                string[] split = streamReader.ReadLine().Split(delimiter, 20);
                Messier.Add(new Messier(split[0], Convert.ToDouble(split[1], provider) * 15,
                                        Convert.ToDouble(split[2], provider), split[3], split[4]));
            }
            Messier.TrimToSize();

            asembly      = Assembly.GetExecutingAssembly();
            txtStream    = asembly.GetManifestResourceStream("SpaceObjects.Resources.Constellations.txt");
            streamReader = new StreamReader(txtStream);

            while (streamReader.Peek() >= 0)
            {
                string str = streamReader.ReadLine();
                if (str[0] != 'C')
                {
                    string[] split = str.Split(delimiter, 20);
                    Constellation.Add(new ConstellationLine(Convert.ToDouble(split[0], provider) * 15, Convert.ToDouble(split[1], provider),
                                                            Convert.ToDouble(split[2], provider) * 15, Convert.ToDouble(split[3], provider)));
                }
                else
                {
                    string[]    split       = str.Split(delimiter, 4);
                    SkyPosition skyPosition = new SkyPosition();
                    skyPosition.Rectascence = Convert.ToDouble(split[2], provider) * 15;
                    skyPosition.Declination = Convert.ToDouble(split[3], provider);
                    ConstellationNames.Add(new ConstellationName(split[1], skyPosition));
                }
            }
            Constellation.TrimToSize();
            ConstellationNames.TrimToSize();
        }