public void TestPentagonalNumberGenerator()
        {
            var expected = new[] { 1, 5, 12, 22, 35 };
            var actual   = PentagonalNumberGenerator.Generate().Take(5).ToArray();

            Assert.AreEqual(expected.Length, actual.Length);

            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], actual[i]);
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            var pentagonNums = PentagonalNumberGenerator.Generate().TakeWhile(n => n < 10000000).ToList();

            var answer = (from p1 in pentagonNums
                          from p2 in pentagonNums
                          where p1 > p2
                          where pentagonNums.Contains(p1 + p2)
                          where pentagonNums.Contains(p1 - p2)
                          select p1 - p2)
                         .Min();

            Console.WriteLine(answer);

            Console.WriteLine("Done");
            Console.ReadKey();
        }
 public void TestGeneration(int n, int expectedResult)
 {
     Assert.That(generator.Generate(n), Is.EqualTo(expectedResult));
 }