コード例 #1
0
ファイル: Program.cs プロジェクト: SovereignStrike/AoC_2020
        static void Main(string[] args)
        {
            Terrain  ter = new Terrain(PATH_INPUT);
            Toboggan tob = new Toboggan(0, 0, ter);

            tob.Run();
            Console.Write("trees encountered " + tob.treeCount);

            Toboggan TB1 = new Toboggan(0, 0, ter, 1, 1);

            TB1.Run();
            Toboggan TB2 = new Toboggan(0, 0, ter, 3, 1);

            TB2.Run();
            Toboggan TB3 = new Toboggan(0, 0, ter, 5, 1);

            TB3.Run();
            Toboggan TB4 = new Toboggan(0, 0, ter, 7, 1);

            TB4.Run();
            Toboggan TB5 = new Toboggan(0, 0, ter, 1, 2);

            TB5.Run();
            long large = (Convert.ToInt64(TB1.treeCount) * Convert.ToInt64(TB2.treeCount) * Convert.ToInt64(TB3.treeCount) * Convert.ToInt64(TB4.treeCount) * Convert.ToInt64(TB5.treeCount));

            Console.Write("trees encountered multi-run " + large.ToString());
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Toboggan toboggan = new Toboggan(3, 1);

            toboggan.mountain = Helper.readInData("data.txt");
            long result = toboggan.HowManyTreeStrikes();

            Console.WriteLine($"Route {toboggan.slopeX}, {toboggan.slopeY} struck {result} trees.");

            // Challenge 2

            int             interimResult;
            List <Toboggan> differentRoutes = new List <Toboggan>()
            {
                new Toboggan(1, 1), new Toboggan(5, 1), new Toboggan(7, 1), new Toboggan(1, 2)
            };

            foreach (Toboggan t in differentRoutes)
            {
                t.mountain    = toboggan.mountain;
                interimResult = t.HowManyTreeStrikes();
                Console.WriteLine($"Route {t.slopeX}, {t.slopeY} struck {interimResult} trees.");
                result *= interimResult;
            }
            Console.WriteLine($"Multiplied together, this gives the answer {result}.");
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: osclee/AdventOfCode2020
        // https://adventofcode.com/2020/day/3
        static void Main(string[] args)
        {
            // Part 1
            Toboggan toboggan1 = new Toboggan();

            toboggan1.Sled(3, 1);

            Console.WriteLine(toboggan1.Collisions);

            // Part 2
            var collisionsMultiple = 0;

            Map map = new Map();

            Toboggan toboggan = new Toboggan(map);

            toboggan.Sled(1, 1);
            collisionsMultiple = toboggan.Collisions;

            toboggan = new Toboggan(map);
            toboggan.Sled(3, 1);
            collisionsMultiple *= toboggan.Collisions;

            toboggan = new Toboggan(map);
            toboggan.Sled(5, 1);
            collisionsMultiple *= toboggan.Collisions;

            toboggan = new Toboggan(map);
            toboggan.Sled(7, 1);
            collisionsMultiple *= toboggan.Collisions;

            toboggan = new Toboggan(map);
            toboggan.Sled(1, 2);
            collisionsMultiple *= toboggan.Collisions;

            Console.WriteLine(collisionsMultiple);
        }