Esempio n. 1
0
        public void Part2()
        {
            BuildOrbitMap(InputData);

            OrbitBody Santa = OrbitMap["SAN"];
            OrbitBody You   = OrbitMap["YOU"];

            int       so         = 0;
            OrbitBody SantaOrbit = Santa.Orbits;

            while (SantaOrbit != null)
            {
                SantaOrbit.SantaOrbits = so;
                so++;
                SantaOrbit = SantaOrbit.Orbits;
            }

            int       yo       = 0;
            OrbitBody YouOrbit = You.Orbits;

            while (YouOrbit != null)
            {
                if (YouOrbit.SantaOrbits != -1)
                {
                    yo = yo + YouOrbit.SantaOrbits;
                    break;
                }
                yo++;
                YouOrbit = YouOrbit.Orbits;
            }

            Console.WriteLine("Day2 Part1 Result = {0}", yo);
        }
Esempio n. 2
0
        private void BuildOrbitMap(String Data)
        {
            OrbitMap = new Dictionary <string, OrbitBody>();

            String[] Orbits = Data.Split(new char[] { '\t', ' ', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (String Orbit in Orbits)
            {
                String[]  Bodies = Orbit.Split(')');
                OrbitBody Body   = new OrbitBody();
                Body.Name       = Bodies[1];
                Body.OrbitsName = Bodies[0];
                OrbitMap.Add(Bodies[1], Body);
            }

            foreach (KeyValuePair <string, OrbitBody> MapBody in OrbitMap)
            {
                OrbitMap.TryGetValue(MapBody.Value.OrbitsName, out MapBody.Value.Orbits);
            }
        }
Esempio n. 3
0
        public void Part1()
        {
            BuildOrbitMap(InputData);

            int oc = 0;

            foreach (KeyValuePair <string, OrbitBody> MapBody in OrbitMap)
            {
                oc += 1;
                OrbitBody Orbits = MapBody.Value.Orbits;
                while (Orbits != null)
                {
                    oc    += 1;
                    Orbits = Orbits.Orbits;
                }
            }

            Console.WriteLine("Day2 Part1 Result = {0}", oc);
        }