Exemplo n.º 1
0
        public static void Solve()
        {
            var boardingPassPartitions = File.ReadAllLines("D5/Input.txt");

            Console.WriteLine("D5P1 answer: " + Part1.Solve(boardingPassPartitions));
            Console.WriteLine("D5P2 answer: " + Part2.Solve(boardingPassPartitions));
        }
Exemplo n.º 2
0
    public static void Main()
    {
        Part1.Run();
        Part2.Run();

        Console.ReadKey();
    }
Exemplo n.º 3
0
        public static void Solve()
        {
            var passwordsAndPolicies = File.ReadAllText("D3/Input.txt");

            Console.WriteLine("D3P1 answer: " + Part1.Solve(passwordsAndPolicies, new Step(3, 1)));
            Console.WriteLine("D3P2 answer: " + Part2.Solve(passwordsAndPolicies));
        }
Exemplo n.º 4
0
        public static void Solve()
        {
            var passwordsAndPolicies = File.ReadAllLines("D2/Input.txt");

            Console.WriteLine("D2P1 answer: " + Part1.Solve(passwordsAndPolicies));
            Console.WriteLine("D2P2 answer: " + Part2.Solve(passwordsAndPolicies));
        }
    void array()
    {
        array1 = new Part1[array1size];
        for (int i = 0; i < array1.Length; i++)
        {
            array1[i] = new Part1();
        }
        array1[0] = boatstatus.Turn1;
        array1[1] = boatstatus.Turn2;
        //array1[2] = boatstatus.Turn3;

        array2 = new Part2[array2size];
        for (int i = 0; i < array2.Length; i++)
        {
            array2[i] = new Part2();
        }
        array2[0] = boatstatus.Body1;
        array2[1] = boatstatus.Body2;
        array2[2] = boatstatus.Body3;

        array3 = new Part3[array3size];
        for (int i = 0; i < array3.Length; i++)
        {
            array3[i] = new Part3();
        }
        array3[0] = boatstatus.Ancor1;
        array3[1] = boatstatus.Ancor2;
        array3[2] = boatstatus.Ancor3;
        array3[3] = boatstatus.Ancor4;
    }
Exemplo n.º 6
0
        public static void Solve()
        {
            var bagRules = File.ReadAllText("D7/Input.txt");

            Console.WriteLine("D7P1 answer: " + Part1.Solve(bagRules));
            Console.WriteLine("D7P2 answer: " + Part2.Solve(bagRules));
        }
Exemplo n.º 7
0
    public static void Main()
    {
        var input = File.ReadAllLines("Input.txt");

        Part1.Solve(input);
        Part2.Solve(input);
    }
Exemplo n.º 8
0
        public static void Solve()
        {
            var customsDeclarationFormsYesses = File.ReadAllText("D6/Input.txt");

            Console.WriteLine("D6P1 answer: " + Part1.Solve(customsDeclarationFormsYesses));
            Console.WriteLine("D6P2 answer: " + Part2.Solve(customsDeclarationFormsYesses));
        }
Exemplo n.º 9
0
        public void Test1(string inputFile, int expected)
        {
            var input  = Program.Read(inputFile);
            var output = Part1.Run(input);

            output.ShouldBe(expected);
        }
 public override int GetHashCode()
 {
     return(Part1.GetHashCode() ^
            Part2.GetHashCode() ^
            Part3.GetHashCode() ^
            Part4.GetHashCode());
 }
Exemplo n.º 11
0
        public void CustomReportFile()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestReport.Document" });
                var repository = container.Resolve <Common.DomRepository>();

                var d1 = new Document {
                    ID = Guid.NewGuid(), Name = "d1"
                };
                var d2 = new Document {
                    ID = Guid.NewGuid(), Name = "d2"
                };
                repository.TestReport.Document.Insert(new[] { d1, d2 });

                var s11 = new Part1 {
                    ParentID = d1.ID, Name = "A s11"
                };
                var s12 = new Part1 {
                    ParentID = d1.ID, Name = "B s12"
                };
                var s13 = new Part1 {
                    ParentID = d2.ID, Name = "B s13"
                };
                repository.TestReport.Part1.Insert(new[] { s11, s12, s13 });

                var report = repository.TestReport.CustomFileReport.GenerateReport(new CustomFileReport {
                    Prefix = "B"
                });

                Assert.AreEqual("CustomFileReport.txt", report.Name);
                Assert.AreEqual("d1, d2|B s12, B s13", new UTF8Encoding().GetString(report.Content));
            }
        }
Exemplo n.º 12
0
 public static void Run()
 {
     //Part1.PlayGame(4, 8).Dump("21a sample (739785): ");
     Part1.PlayGame(8, 5).Dump("21a (597600): ");
     //Part2.PlayGame(4, 8).Dump("21b sample (444356092776315): ");
     Part2.PlayGame(8, 5).Dump("21b (634769613696613): ");
 }
Exemplo n.º 13
0
        public override int GetHashCode()
        {
            var hashCode = -1585277143;

            hashCode = hashCode * -1521134295 + Part1.GetHashCode();
            hashCode = hashCode * -1521134295 + Part2.GetHashCode();
            return(hashCode);
        }
Exemplo n.º 14
0
        public static void Solve()
        {
            var numbers = File.ReadAllLines("D1/Input.txt")
                          .Select(int.Parse)
                          .ToArray();

            Console.WriteLine("D1P1 answer: " + Part1.Solve(numbers, NeededSum));
            Console.WriteLine("D1P2 answer: " + Part2.Solve(numbers, NeededSum));
        }
Exemplo n.º 15
0
 // Start is called before the first frame update
 void Start()
 {
     PointsArray = GameObject.FindGameObjectsWithTag("SpawnPoint");
     rbP0        = Part0.GetComponent <Rigidbody2D>();
     rbP1        = Part1.GetComponent <Rigidbody2D>();
     rbP2        = Part2.GetComponent <Rigidbody2D>();
     TextBar     = GameObject.FindGameObjectWithTag("ScoreText");
     ScoreBar    = TextBar.GetComponent <Text>();
     StartCoroutine("SpeedUp", 1f);
 }
Exemplo n.º 16
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Part1.GetHashCode();
         hashCode = (hashCode * 397) ^ Part2.GetHashCode();
         hashCode = (hashCode * 397) ^ Part3.GetHashCode();
         return(hashCode);
     }
 }
Exemplo n.º 17
0
        public void SplitPart(string Part1FileName, string Part2FileName, int Dim = 0)
        {
            var       Slice = SplittingPlane(Dim);
            STLReader Part1;
            STLReader Part2;

            SplitPart(Slice, out Part1, out Part2);
            Part1.WriteToFile(Part1FileName);
            Part2.WriteToFile(Part2FileName);
        }
Exemplo n.º 18
0
    static async System.Threading.Tasks.Task Main(string[] args)
    {
        //Part 1
        Console.WriteLine("===PART 1===");
        await Part1.Run(args);

        //Part 2
        Console.WriteLine("===PART 2===");
        await Part2.Run(args);
    }
Exemplo n.º 19
0
    boat(Part1 part1_, Part2 part2_, Part3 part3_)
    {
        part1 = part1_;
        part2 = part2_;
        part3 = part3_;

        power         = part1_.power + part2_.power + part3_.power;
        weight        = part1_.weight + part2_.weight + part3_.weight;
        movementspeed = part1_.movementspeed + part2_.movementspeed + part3_.movementspeed;
        strength      = part1_.strength + part2_.strength + part3_.strength;
    }
Exemplo n.º 20
0
            /// <summary>
            /// Map of a mountain repeats itself to the right.
            /// It's either x- a tree.
            /// Or 0- an empty space.
            /// Descending down the slope starts from top left corner.
            /// It is done moving x steps right and y step down.
            /// The combos are: {1,1}, {3,1}, {5,1}, {7,1}, {1,2}.
            /// Return the count of trees stepped on traversing the slope in each a way multiplied.
            /// </summary>
            /// <param name="map">Map of slope</param>
            /// <returns>Count of trees in the way</returns>
            public static long Solve(string map)
            {
                Step[] stepCombos =
                {
                    new Step(1, 1),
                    new Step(3, 1),
                    new Step(5, 1),
                    new Step(7, 1),
                    new Step(1, 2),
                };

                return(stepCombos.Product(s => Part1.Solve(map, s)));
            }
Exemplo n.º 21
0
            /// <summary>
            /// find the three entries that sum to 2020 and then multiply those three numbers together
            /// </summary>
            public static int Solve(int[] numbers, int neededSum)
            {
                foreach (var number in numbers)
                {
                    var result = Part1.Solve(numbers, neededSum - number);
                    if (result != -1)
                    {
                        return(result * number);
                    }
                }

                return(-1);
            }
Exemplo n.º 22
0
        public void Part1_Solve_Returns_MaxSeatId()
        {
            string[] partitions =
            {
                "BFFFBBFRRR",
                "FFFBBBFRRR",
                "BBFFBBFRLL",
            };
            const int expectedMax = 820;

            var max = Part1.Solve(partitions);

            max.Should().Be(expectedMax);
        }
Exemplo n.º 23
0
        public void MultipleSources()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestReport.Document" });
                var repository = container.Resolve<Common.DomRepository>();

                var d1 = new Document { ID = Guid.NewGuid(), Name = "d1" };
                var d2 = new Document { ID = Guid.NewGuid(), Name = "d2" };
                var d3 = new Document { ID = Guid.NewGuid(), Name = "d3" };
                var d4 = new Document { ID = Guid.NewGuid(), Name = "d4" };
                repository.TestReport.Document.Insert(new[] { d1, d2, d3, d4 });

                var s11 = new Part1 { ParentID = d1.ID, Name = "A s11" };
                var s12 = new Part1 { ParentID = d2.ID, Name = "A s12" };
                var s13 = new Part1 { ParentID = d1.ID, Name = "A s13" };
                var s14 = new Part1 { ParentID = d3.ID, Name = "A s14" };
                var s15 = new Part1 { ParentID = d4.ID, Name = "B s15" };
                repository.TestReport.Part1.Insert(new[] { s11, s12, s13, s14, s15 });

                var s21 = new Part2 { ParentID = d1.ID, Name = "s21" };
                var s22 = new Part2 { ParentID = d3.ID, Name = "s22 xx" };
                var s23 = new Part2 { ParentID = d3.ID, Name = "s23 xxx" };
                var s24 = new Part2 { ParentID = d3.ID, Name = "s24 x" };
                var s25 = new Part2 { ParentID = d4.ID, Name = "s25" };
                repository.TestReport.Part2.Insert(new[] { s21, s22, s23, s24, s25 });

                var reportData = repository.TestReport.MultipleSourcesReport.GetReportData(
                    new MultipleSourcesReport { Part1Prefix = "A" });

                var reportDump = string.Join("|", reportData.Select(group =>
                    string.Join(", ", group.Select(item => ((dynamic)item).Name))));

                const string expectedReport1 = "d3, d2, d1|s24 x, s22 xx, s23 xxx, s21|A s14, A s13, A s12, A s11";
                const string expectedReport2 = "d3, d1, d2|s24 x, s22 xx, s23 xxx, s21|A s14, A s13, A s12, A s11"; // Order of d1 and d2 is not defined.

                Console.WriteLine("Report result: " + reportDump);
                Console.WriteLine(expectedReport1);
                Console.WriteLine(expectedReport2);

                Assert.IsTrue(
                    new[] { expectedReport1, expectedReport2 }.Contains(reportDump),
                    "Report result should be one of the expected results.");
            }
        }
            public ISolver getSolver(int part)
            {
                ISolver Solver;

                switch (part)
                {
                case 1:
                    Solver = new Part1();
                    break;

                case 2:
                    Solver = new Part2();
                    break;

                default:
                    throw new Exception("Wrong part.");
                }

                return(Solver);
            }
Exemplo n.º 25
0
            public int Solve(IEnumerable <Claim> claims)
            {
                var c    = claims.ToList();
                var grid = new Part1().MakeGrid(c);

                for (int x = 0; x < 1000; x++)
                {
                    for (int y = 0; y < 1000; y++)
                    {
                        var ids = grid[y, x];
                        if (ids.Count > 1)
                        {
                            foreach (var id in ids)
                            {
                                c.Remove(c.Find(claim => claim.Id == id));
                            }
                        }
                    }
                }
                return(c[0].Id);
            }
Exemplo n.º 26
0
        public void CustomReportFile()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestReport.Document" });
                var repository = container.Resolve<Common.DomRepository>();

                var d1 = new Document { ID = Guid.NewGuid(), Name = "d1" };
                var d2 = new Document { ID = Guid.NewGuid(), Name = "d2" };
                repository.TestReport.Document.Insert(new[] { d1, d2 });

                var s11 = new Part1 { Parent = d1, Name = "A s11" };
                var s12 = new Part1 { Parent = d1, Name = "B s12" };
                var s13 = new Part1 { Parent = d2, Name = "B s13" };
                repository.TestReport.Part1.Insert(new[] { s11, s12, s13 });

                var report = repository.TestReport.CustomFileReport.GenerateReport(new CustomFileReport { Prefix = "B" });

                Assert.AreEqual("CustomFileReport.txt", report.Name);
                Assert.AreEqual("d1, d2|B s12, B s13", new UTF8Encoding().GetString(report.Content));
            }
        }
Exemplo n.º 27
0
        static void Main(string[] args)
        {
            int taskNumber;

            while (true)
            {
                Console.Write("Enter the number of task you want to check (0 - exit): ");
                if (Int32.TryParse(Console.ReadLine(), out taskNumber))
                {
                    switch (taskNumber)
                    {
                    case 0:
                        return;

                    case 1:
                        Part1.DoIt("input.txt", "output.txt");
                        break;

                    case 2:
                        Part2.DoIt();
                        break;

                    case 3:
                        Part3.DoIt();
                        break;

                    default:
                        Console.WriteLine("Incorrect task number");
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("Can not resolve the task number");
                }
            }
        }
Exemplo n.º 28
0
        static void Main(string[] args)
        {
            dynamic x, y, result, expected, array, sortedArray;

            #region Divide and Conquer

            Console.WriteLine("\n--------------------------------------------- Divide and Conquer ---------------------------------------------");
            Console.WriteLine("\n- Karatsuba Multiplication\n");

            x = 1234;
            y = 5678;

            result   = Part1.Karatsuba(x, y);
            expected = x * y;
            Assert.AreEqual(result, expected);

            Console.WriteLine($"\tKaratsuba({x}, {y}) is: {result}\n");

            x = "1234";
            y = "5678";

            result   = Part1.Karatsuba(x, y);
            expected = int.Parse(x) * int.Parse(y);
            Assert.AreEqual(result, expected);

            Console.WriteLine($"\tKaratsuba(\"{x}\", \"{y}\") is: {result}\n");

            Console.WriteLine("\n- Merge Sort\n");

            array = new[] { 2, 4, 5, 7, 1, 2, 3, 6 };

            Console.WriteLine($"\tOriginal Array: ");
            Helpers.PrintArray(array);

            sortedArray = new[] { 1, 2, 2, 3, 4, 5, 6, 7 };

            Part1.MergeSort(array, 0, array.Length - 1);

            CollectionAssert.AreEqual(array, sortedArray);

            Console.WriteLine($"\tSorted Array: ");
            Helpers.PrintArray(array);

            Console.WriteLine("\n- Counting Inversions\n");

            array       = new[] { 4, 1, 3, 2, 9, 1 };
            sortedArray = new[] { 1, 1, 2, 3, 4, 9 };

            Console.WriteLine($"\tOriginal Array: ");
            Helpers.PrintArray(array);

            var count_inversions = Part1.Sort_and_Count(array);
            expected = 8;

            CollectionAssert.AreEqual(array, sortedArray);
            Assert.AreEqual(count_inversions, expected);

            Console.WriteLine($"\tSorted Array: ");
            Helpers.PrintArray(array);

            Console.Write($"\tNumber of inversions are: {count_inversions}\n");

            Console.WriteLine("\n- Find Max Crossing SubArray\n");

            var array1 = new[] { 13, -3, -25, 20, -3, -16, -23, 18, 20, -7, 12, -5, -22, 15, -4, 7 };

            Console.WriteLine($"\tArray: ");
            Helpers.PrintArray(array1);

            var(low, high, sum) = Part1.FindMaximunSubArray(array1, 0, array1.Length - 1);

            Assert.AreEqual(low, 7);
            Assert.AreEqual(high, 10);
            Assert.AreEqual(sum, 43);

            Console.Write($"\tThe maximum subarray is: from {low} (value {array1[low]}) to {high} (value {array1[high]}) and the sum is {sum}\n");

            Console.WriteLine("\n- Closet Pair \n");

            array = new Point[] { new Point(2, 3), new Point(5, 1), new Point(12, 10) };

            Console.WriteLine($"\tPoints: ");
            Helpers.PrintArray(array);

            result = Part1.ClosetPair(array, array.Length);

            Console.Write($"\tThe smallest distance is: {result}");

            #endregion

            Console.WriteLine();
        }
Exemplo n.º 29
0
        public void Part1_Solve_Returns_SumOf_UniqueAnswersCounts_PerGroup(string customsDeclarationFormsYesses, int expectedUniqueYesses)
        {
            var uniqueYesses = Part1.Solve(customsDeclarationFormsYesses);

            uniqueYesses.Should().Be(expectedUniqueYesses);
        }
Exemplo n.º 30
0
        public void Test(int input, bool expected)
        {
            var output = Part1.IsMatch(input);

            output.ShouldBe(expected);
        }
 public Part8([BundleImport] Part1 part, [BundleImport] Part2 part2)
 {
     _part = part;
     _part2 = part2;
 }
 public Part8([BundleImport] Part1 part)
 {
     _part = part;
 }
Exemplo n.º 33
0
        public void MultipleSources()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestReport.Document" });
                var repository = container.Resolve <Common.DomRepository>();

                var d1 = new Document {
                    ID = Guid.NewGuid(), Name = "d1"
                };
                var d2 = new Document {
                    ID = Guid.NewGuid(), Name = "d2"
                };
                var d3 = new Document {
                    ID = Guid.NewGuid(), Name = "d3"
                };
                var d4 = new Document {
                    ID = Guid.NewGuid(), Name = "d4"
                };
                repository.TestReport.Document.Insert(new[] { d1, d2, d3, d4 });

                var s11 = new Part1 {
                    ParentID = d1.ID, Name = "A s11"
                };
                var s12 = new Part1 {
                    ParentID = d2.ID, Name = "A s12"
                };
                var s13 = new Part1 {
                    ParentID = d1.ID, Name = "A s13"
                };
                var s14 = new Part1 {
                    ParentID = d3.ID, Name = "A s14"
                };
                var s15 = new Part1 {
                    ParentID = d4.ID, Name = "B s15"
                };
                repository.TestReport.Part1.Insert(new[] { s11, s12, s13, s14, s15 });

                var s21 = new Part2 {
                    ParentID = d1.ID, Name = "s21"
                };
                var s22 = new Part2 {
                    ParentID = d3.ID, Name = "s22 xx"
                };
                var s23 = new Part2 {
                    ParentID = d3.ID, Name = "s23 xxx"
                };
                var s24 = new Part2 {
                    ParentID = d3.ID, Name = "s24 x"
                };
                var s25 = new Part2 {
                    ParentID = d4.ID, Name = "s25"
                };
                repository.TestReport.Part2.Insert(new[] { s21, s22, s23, s24, s25 });

                var reportData = repository.TestReport.MultipleSourcesReport.GetReportData(
                    new MultipleSourcesReport {
                    Part1Prefix = "A"
                });

                var reportDump = string.Join("|", reportData.Select(group =>
                                                                    string.Join(", ", group.Select(item => ((dynamic)item).Name))));

                const string expectedReport1 = "d3, d2, d1|s24 x, s22 xx, s23 xxx, s21|A s14, A s13, A s12, A s11";
                const string expectedReport2 = "d3, d1, d2|s24 x, s22 xx, s23 xxx, s21|A s14, A s13, A s12, A s11"; // Order of d1 and d2 is not defined.

                Console.WriteLine("Report result: " + reportDump);
                Console.WriteLine(expectedReport1);
                Console.WriteLine(expectedReport2);

                Assert.IsTrue(
                    new[] { expectedReport1, expectedReport2 }.Contains(reportDump),
                    "Report result should be one of the expected results.");
            }
        }
Exemplo n.º 34
0
        public void Test(int mass, int expected)
        {
            var fuel = Part1.Fuel(mass);

            fuel.ShouldBe(expected);
        }