コード例 #1
0
        public void Task2()
        {
            var testCases = new Vector2[]
            {
                new Vector2(1, 1),
                new Vector2(3, 1),
                new Vector2(5, 1),
                new Vector2(7, 1),
                new Vector2(1, 2)
            };

            var output = new Day3().Task2(_map, testCases);

            Assert.Pass(output.ToString());             // Answer: 6419669520.
        }
コード例 #2
0
        public void Day3_CalculatePart2()
        {
            var input1 = new List <string>()
            {
                "#1 @ 1,3: 4x4", "#2 @ 3,1: 4x4", "#3 @ 5,5: 2x2"
            };

            Assert.AreEqual(1, Day3.Calculate(8, 8, input1).NonOverlappingClaims.Count());
            Assert.AreEqual(3, Day3.Calculate(8, 8, input1).NonOverlappingClaims.First());

            var input2 = FileUtil.Get2018File("Day3.txt");

            Assert.AreEqual(1, Day3.Calculate(1000, 1000, input2).NonOverlappingClaims.Count());
            Assert.AreEqual(552, Day3.Calculate(1000, 1000, input2).NonOverlappingClaims.First());
        }
コード例 #3
0
ファイル: Day3Tests.cs プロジェクト: richmays/RMays.Aoc2018
        public void PartATests(string input, int expectedOutput)
        {
/*
 *          ........
 *          ...2222.
 *          ...2222.
 *          .11XX22.
 *          .11XX22.
 *          .111133.
 *          .111133.
 *          ........
 */
            var day    = new Day3();
            var result = day.SolveA(input);

            Assert.AreEqual(expectedOutput, result);
        }
コード例 #4
0
ファイル: UnitTests.cs プロジェクト: c-s-h-i-r/AdventForCode
        public void TestDay3()
        {
            var day3 = new Day3("");

            var wire1a = new string[] { "R75", "D30", "R83", "U83", "L12", "D49", "R71", "U7", "L72" };
            var wire2a = new string[] { "U62", "R66", "U55", "R34", "D71", "R55", "D58", "R83" };

            Assert.AreEqual(159, day3.FindClosestDistanceToOrigin(wire1a, wire2a));

            var wire1b = new string[] { "R98", "U47", "R26", "D63", "R33", "U87", "L62", "D20", "R33", "U53", "R51" };
            var wire2b = new string[] { "U98", "R91", "D20", "R16", "D67", "R40", "U7", "R15", "U6", "R7" };

            Assert.AreEqual(135, day3.FindClosestDistanceToOrigin(wire1b, wire2b));

            Assert.AreEqual(610, day3.FindIntersectionWithLeastSteps(wire1a, wire2a));
            Assert.AreEqual(410, day3.FindIntersectionWithLeastSteps(wire1b, wire2b));
        }
コード例 #5
0
ファイル: Day3Tests.cs プロジェクト: micheldupont/AoC2018
        public void CanReturnCollisionListForTwoInput()
        {
            var input = new List <Day3>
            {
                Day3.Parse("#1 @ 1,3: 4x4"),
                Day3.Parse("#2 @ 3,1: 4x4")
            };

            var map = new Day3CollisionMap(input);

            var result = map.CalculateAllCollisions();

            Assert.Contains(new Coord(3, 3), result);
            Assert.Contains(new Coord(3, 4), result);
            Assert.Contains(new Coord(4, 3), result);
            Assert.Contains(new Coord(4, 4), result);
        }
コード例 #6
0
        public void DetectTrees_WhenProvidedWithMap_ShouldDetectAndMultiplyNUmberOfTreesInDifferentPaths()
        {
            var input = FileLoader.ReadListFromFile <string>("3.txt");
            var map   = input
                        .Select(line => string.Concat(Enumerable.Repeat(line, 100)))
                        .Select(line => line.Select(token => token == '#').ToList())
                        .ToList();

            var treesInPath1 = Day3.DetectTrees(map, 1, 1);
            var treesInPath2 = Day3.DetectTrees(map, 3, 1);
            var treesInPath3 = Day3.DetectTrees(map, 5, 1);
            var treesInPath4 = Day3.DetectTrees(map, 7, 1);
            var treesInPath5 = Day3.DetectTrees(map, 1, 2);

            var product = (long)treesInPath1 * treesInPath2 * treesInPath3 * treesInPath4 * treesInPath5;

            Assert.Equal(6708199680, product);
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: Yarince/AdventOFCode2020
        static void Main(string[] args)
        {
            // var day1 = new Day1();
            // var inputDay1 = ReadInput.ReadInt("/home/yarince/RiderProjects/AdventOFCode/AdventOfCode/input-day1");
            // day1.Execute1(inputDay1);
            // day1.Execute2(inputDay1);

            // var day2 = new Day2();
            // var inputDay2 = ReadInput.ReadStr("/home/yarince/RiderProjects/AdventOFCode/AdventOfCode/input-day2");
            // day2.Execute1(inputDay2);
            // day2.Execute2(inputDay2);

            var day3      = new Day3();
            var inputDay3 = ReadInput.ReadStr("C:\\Users\\Yarince Martis\\Documents\\adventOfCode2020\\AdventOfCode\\input-day3-test");

            day3.Execute1(inputDay3);
            // day3.Execute2(inputDay3);
        }
コード例 #8
0
ファイル: Day3Tests.cs プロジェクト: micheldupont/AoC2018
        public void ValidationC()
        {
            var input = new List <Day3>
            {
                Day3.Parse("#1 @ 1,3: 4x4"),
                Day3.Parse("#2 @ 5,5: 2x2"),
                Day3.Parse("#3 @ 3,1: 4x4")
            };

            var map = new Day3CollisionMap(input);

            var result = map.CalculateAllCollisions();

            Assert.Contains(new Coord(3, 3), result);
            Assert.Contains(new Coord(3, 4), result);
            Assert.Contains(new Coord(4, 3), result);
            Assert.Contains(new Coord(4, 4), result);
        }
コード例 #9
0
        public void SolveWithTestInput()
        {
            var testInput = @"..##.......
#...#...#..
.#....#..#.
..#.#...#.#
.#...##..#.
..#.##.....
.#.#.#....#
.#........#
#.##...#...
#...##....#
.#..#...#.#".Split("\r\n");
            var solver    = new Day3();
            var solution  = solver.Solve(testInput);

            Assert.AreEqual(("7", "336"), solution);
        }
コード例 #10
0
ファイル: UnitTests.cs プロジェクト: c-s-h-i-r/AdventForCode
        public void TestFinalAnswers()
        {
            var appFolder = new FileInfo(Environment.CurrentDirectory).Directory.Parent.Parent.Parent;
            var day1      = new Day1(Path.Join(appFolder.FullName, "inputDay1.txt"));

            Assert.AreEqual(3346639, day1.TotalFuelNeeded);
            Assert.AreEqual(5017110, day1.TotalFuelNeededBetter);

            var day2 = new Day2(Path.Join(appFolder.FullName, "inputDay2.txt"));;

            Assert.AreEqual(3760627, day2.RunChallengePart1());
            Assert.AreEqual(7195, day2.RunChallengePart2());

            var day3 = new Day3(Path.Join(appFolder.FullName, "inputDay3.txt"));

            Assert.AreEqual(1064, day3.RunChallengePart1());
            Assert.AreEqual(25676, day3.RunChallengePart2());

            var day4 = new Day4("158126-624574");

            Assert.AreEqual(1665, day4.RunChallengePart1());
            Assert.AreEqual(1131, day4.RunChallengePart2());

            var day5 = new Day5(Path.Join(appFolder.FullName, "inputDay5.txt"));

            Assert.AreEqual("0,0,0,0,0,0,0,0,0,9961446", string.Join(',', day5.RunChallengePart1()));
            Assert.AreEqual(742621, day5.RunChallengePart2()[0]);

            //var day6 = new Day6(Path.Join(appFolder.FullName, "inputDay6.txt"));
            //Assert.AreEqual(, day6.RunChallengePart1());

            var day7 = new Day7(Path.Join(appFolder.FullName, "inputDay7.txt"));

            Assert.AreEqual(21760, day7.RunChallengePart1());
            //Assert.AreEqual(, day7.RunChallengePart2());

            var day8 = new Day8(Path.Join(appFolder.FullName, "inputDay8.txt"), 25, 6);

            Assert.AreEqual(2684, day8.RunChallengePart1());
            var day9 = new Day9(Path.Join(appFolder.FullName, "inputDay9.txt"));

            Assert.AreEqual(3533056970, day9.RunChallengePart1());
            Assert.AreEqual(72852, day9.RunChallengePart2());
        }
コード例 #11
0
        static void Main(string[] args)
        {
            Day1 day1 = new Day1();

            Console.WriteLine($"Day 1, part 1:\t{day1.Part1()}");
            Console.WriteLine($"Day 1, part 2:\t{day1.Part2()}");

            Day2 day2 = new Day2();

            Console.WriteLine($"Day 2, part 1:\t{day2.Part1()}");
            Console.WriteLine($"Day 2, part 2:\t{day2.Part2()}");

            Day3 day3 = new Day3();

            Console.WriteLine($"Day 3, part 1:\t{day3.Part1()}");
            Console.WriteLine($"Day 3, part 1:\t{day3.Part2()}");

            Console.ReadLine();
        }
コード例 #12
0
    public static void Main()
    {
        Console.WriteLine($"Day 1 Problem 1\t{Day1.Problem1()}");
        Console.WriteLine($"Day 1 Problem 2\t{Day1.Problem2()}");

        Console.WriteLine($"Day 2 Problem 1\t{Day2.Problem1()}");
        Console.WriteLine($"Day 2 Problem 2\t{Day2.Problem2()}");

        Console.WriteLine($"Day 3 Problem 1\t{Day3.Problem1()}");
        Console.WriteLine($"Day 3 Problem 2\t{Day3.Problem2()}");

        Console.WriteLine($"Day 4 Problem 1\t{Day4.Problem1()}");
        Console.WriteLine($"Day 4 Problem 2\t{Day4.Problem2()}");

        // these require user input, so skip them here
        //Console.WriteLine($"Day 5 Problem 1\t{Day5.Problem1()}");
        //Console.WriteLine($"Day 5 Problem 2\t{Day5.Problem2()}");

        Console.WriteLine($"Day 6 Problem 1\t{Day6.Problem1()}");
        Console.WriteLine($"Day 6 Problem 2\t{Day6.Problem2()}");
    }
コード例 #13
0
        public void Refresh()
        {
            var result = _getTimesheets(Day1.Date, Day5.Date);

            Day1.SetItems(result.Where(x => x.StartTime.Date == Day1.Date));
            Day2.SetItems(result.Where(x => x.StartTime.Date == Day2.Date));
            Day3.SetItems(result.Where(x => x.StartTime.Date == Day3.Date));
            Day4.SetItems(result.Where(x => x.StartTime.Date == Day4.Date));
            Day5.SetItems(result.Where(x => x.StartTime.Date == Day5.Date));
            //LoadAsync(() => _getCalendarItems(Day1.Date, Day5.Date), (result) =>
            //{
            //    Day1.SetItems(result.Where(x => x.From.Date == Day1.Date));
            //    Day2.SetItems(result.Where(x => x.From.Date == Day2.Date));
            //    Day3.SetItems(result.Where(x => x.From.Date == Day3.Date));
            //    Day4.SetItems(result.Where(x => x.From.Date == Day4.Date));
            //    Day5.SetItems(result.Where(x => x.From.Date == Day5.Date));
            //}, ex =>
            //{
            //    //ignore
            //});
        }
コード例 #14
0
ファイル: Day3Test.cs プロジェクト: Jupotter/AdventOfCode
        public void LoadTrees()
        {
            var expected = new[, ]
            {
                { false, false, true, true, false, false, false, false, false, false, false },
                { true, false, false, false, true, false, false, false, true, false, false },
                { false, true, false, false, false, false, true, false, false, true, false },
            };
            var result = Day3.LoadTrees(SampleData);

            Assert.Equal(11, result.GetLength(0));
            Assert.Equal(11, result.GetLength(1));

            for (int i = 0; i < expected.GetLength(0); i++)
            {
                for (int j = 0; j < expected.GetLength(1); j++)
                {
                    Assert.Equal(expected[i, j], result[i, j]);
                }
            }
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: ctafield/adventofcode2019
        static void Main(string[] args)
        {
            var masses = LoadInput("input-day1.txt");
            var day1   = new Day1(masses);

            Console.WriteLine($"Day 1 - pt1. {day1.GetDay1Part1()}");
            Console.WriteLine($"Day 1 - pt2. {day1.GetDay1Part2()}");

            var opcodes = LoadFlatInput("input-day2.txt");
            var day2    = new Day2(opcodes);

            Console.WriteLine($"Day 2 - pt1. {day2.GetDay2Part1()}");
            Console.WriteLine($"Day 2 - pt2. {day2.GetDay2Part2()}");

            var paths = LoadFlatInput("input-day3.txt");
            var day3  = new Day3(paths);

            day3.GetDay3();

            var day4 = new Day4();

            day4.GetPart1();
            day4.GetPart2();

            var opcodesDay5 = LoadFlatInput("input-day5.txt");
            var day5        = new Day5(opcodesDay5);

            day5.GetPart1();

            var orbits = LoadInput("input-day6.txt");
            var day6   = new Day6(orbits);

            Console.WriteLine($"Day 6 - pt1. {day6.GetPart1()}");
            Console.WriteLine($"Day 6 - pt2. {day6.GetPart2()}");

            var day7input = LoadFlatInput("input-day7.txt");
            var day7      = new Day7(day7input);

            day7.GetPart1();
        }
コード例 #16
0
            public void Should_calculate_CO2()
            {
                var input = new[]
                {
                    "00100",
                    "11110",
                    "10110",
                    "10111",
                    "10101",
                    "01111",
                    "00111",
                    "11100",
                    "10000",
                    "11001",
                    "00010",
                    "01010"
                };
                var target = new Day3();

                var result = target.Execute(input);

                result.CO2ScrubberRating.Should().Be(10);
            }
コード例 #17
0
            public void Should_calculate_life_support_rating()
            {
                var input = new[]
                {
                    "00100",
                    "11110",
                    "10110",
                    "10111",
                    "10101",
                    "01111",
                    "00111",
                    "11100",
                    "10000",
                    "11001",
                    "00010",
                    "01010"
                };
                var target = new Day3();

                var result = target.Execute(input);

                result.LifeSupportRating.Should().Be(230);
            }
コード例 #18
0
            public void Should_calculate_oxygen()
            {
                var input = new[]
                {
                    "00100",
                    "11110",
                    "10110",
                    "10111",
                    "10101",
                    "01111",
                    "00111",
                    "11100",
                    "10000",
                    "11001",
                    "00010",
                    "01010"
                };
                var target = new Day3();

                var result = target.Execute(input);

                result.OxygenGeneratorRating.Should().Be(23);
            }
コード例 #19
0
 public void Setup()
 {
     _adventResourcesMock = new Mock <IResources>();
     _day3 = new Day3(_adventResourcesMock.Object);
 }
コード例 #20
0
 public void First1() =>
 Assert.AreEqual(0, Day3.First(1));
コード例 #21
0
        public void Part1(int input, int output)
        {
            var result = Day3.Part1(input);

            Assert.True(result == output, $"Expected: {output}, Received: {result}");
        }
コード例 #22
0
 public void Second3() =>
 Assert.AreEqual(54, Day3.Second(50));
コード例 #23
0
 public void Second4() =>
 Assert.AreEqual(304, Day3.Second(148));
コード例 #24
0
 public void Second1() =>
 Assert.AreEqual(10, Day3.Second(9));
コード例 #25
0
 public void Second2() =>
 Assert.AreEqual(23, Day3.Second(20));
コード例 #26
0
 public void First4() =>
 Assert.AreEqual(31, Day3.First(1024));
コード例 #27
0
 public void First3() =>
 Assert.AreEqual(2, Day3.First(23));
コード例 #28
0
 public void First2() =>
 Assert.AreEqual(3, Day3.First(12));
コード例 #29
0
 public void Day3_Part1()
 {
     var input  = 12;
     var result = Day3.CalculateManhattanDistance(input);
 }
コード例 #30
0
        public void Task1()
        {
            var output = new Day3().Task1(_map);

            Assert.Pass(output.ToString());             // Answer: 159.
        }