Example #1
0
            public void Puzzle_9B()
            {
                var cracker = new XmasCracker();

                cracker.Init(PuzzleInputs.Puzzle9.Take(25));

                var candidates = PuzzleInputs.Puzzle9.Skip(25);

                var contiguousSet = new long[0];

                foreach (var candidate in candidates)
                {
                    var valid = cracker.ValidateNumber(candidate);
                    if (!valid)
                    {
                        contiguousSet = cracker.FindContiguousNumbersOfSum(candidate);
                        break;
                    }
                }

                Assert.Equal(17, contiguousSet.Length);
                var result = contiguousSet.Min() + contiguousSet.Max();

                Assert.Equal(1766397, result);
            }
Example #2
0
            public void Example_2()
            {
                var cracker = new XmasCracker();

                cracker.Init(new long[] { 35, 20, 15, 25, 47 });

                var candidates = new long[] { 40, 62, 55, 65, 95, 102, 117, 150, 182, 127, 219, 299, 277, 309, 576 };

                var contiguousSet = new long[0];

                foreach (var candidate in candidates)
                {
                    var valid = cracker.ValidateNumber(candidate);
                    if (!valid)
                    {
                        contiguousSet = cracker.FindContiguousNumbersOfSum(candidate);
                        break;
                    }
                }

                Assert.Equal(4, contiguousSet.Length);
                Assert.Equal(15, contiguousSet[0]);
                Assert.Equal(25, contiguousSet[1]);
                Assert.Equal(47, contiguousSet[2]);
                Assert.Equal(40, contiguousSet[3]);

                var result = contiguousSet.Min() + contiguousSet.Max();

                Assert.Equal(62, result);
            }