Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            DisplayScreen pb3display = new DisplayScreen();

            pb3display.ProblemTitle  = "Problem 3";
            pb3display.ProblemHeader = "Largest prime factor";
            pb3display.Description   = "The prime factors of 13195 are 5, 7, 13 and 29.\n What is the largest prime factor of the number 600851475143 ?";
            pb3display.DisplayHeader();


            // To make it work I needed long numbers instead of long

            long number = 600851475143; //600851475143 13195

            List <long> List = PrimeFactors.PrimeFactorNumbers(number);

            try
            {
                Console.WriteLine("Largest Prime Factor for " + number + " is : " + List.Max());
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was an error: " + ex.Message);
            }

            pb3display.DisplayFooter();
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            DisplayBorder mainBorder   = new DisplayBorder('#', 1, ConsoleColor.Cyan);
            DisplayBorder sideBorder   = new DisplayBorder('#', 1, ConsoleColor.Red);
            DisplayBorder bottomBorder = new DisplayBorder('#', 1, ConsoleColor.Yellow);
            DisplayBox    mainBox      = new DisplayBox("MainBox", 0, 0, 80, 30, mainBorder);
            DisplayBox    sideBox      = new DisplayBox("SideBox", mainBox.DisplayWidth, 0, 30, 30, sideBorder);
            DisplayBox    bottomBox    = new DisplayBox("BottomBox", 0, mainBox.DisplayHeight, mainBox.DisplayWidth + sideBox.DisplayWidth, 10, bottomBorder);
            DisplayScreen screen       = new DisplayScreen(150, 50);

            screen.Add(mainBox);
            screen.Add(sideBox);
            screen.Add(bottomBox);
            screen.LoadBorders();

            screen.WriteString("MainBox", "Hello World", ConsoleColor.White, ConsoleColor.Black, 15, 35);
            screen.WriteString("MainBox", "How are you today?", ConsoleColor.Red, ConsoleColor.Black, 16, 31);
            //screen.WriteString("SideBox", "Side box", ConsoleColor.White, ConsoleColor.Black, 15, 12);
            screen.WriteString("SideBox", "Welcome ", ConsoleColor.White, ConsoleColor.Black, 2, 2);
            screen.WriteString("SideBox", "Unnar", ConsoleColor.Yellow, ConsoleColor.Black, 2, 10);
            screen.WriteString("SideBox", "Today is: ", ConsoleColor.White, ConsoleColor.Black, 4, 2);
            screen.WriteString("SideBox", "Monday", ConsoleColor.Yellow, ConsoleColor.Black, 4, 12);
            screen.WriteString("SideBox", "New messages: ", ConsoleColor.White, ConsoleColor.Black, 6, 2);
            screen.WriteString("SideBox", "2", ConsoleColor.Yellow, ConsoleColor.Black, 6, 16);
            screen.WriteString("BottomBox", " 21.3.2021 14:23 - Some event has been logged", ConsoleColor.White, ConsoleColor.Black, 2, 1);
            screen.WriteString("BottomBox", " 21.3.2021 14:42 - Some event has been logged", ConsoleColor.White, ConsoleColor.Black, 3, 1);
            screen.WriteString("BottomBox", " 21.3.2021 17:42 - Some event has been logged", ConsoleColor.White, ConsoleColor.Black, 4, 1);
            //StringWriter sw = new StringWriter();
            //Console.SetOut(sw);
            screen.PrintScreen();
            Console.CursorVisible = true;
            Console.ReadKey();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            DisplayScreen pb5display = new DisplayScreen();

            pb5display.ProblemTitle  = "Problem 5";
            pb5display.ProblemHeader = "Smallest multiple";
            pb5display.Description   = "2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.\nWhat is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20 ? ";
            pb5display.DisplayHeader();

            int  number  = 2520;
            int  limit   = 20;
            bool isValid = false;

            while (isValid == false)
            {
                number++;
                isValid = SmallestMultiple.SmallestNumber(number, limit);
            }


            Console.WriteLine("Number " + number + " Pass Test: " + isValid);



            //pb5display.DisplayAnswer("number  :"+ number , isValid);



            pb5display.DisplayFooter();
            Console.ReadKey();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            DisplayScreen pb23display = new DisplayScreen();

            pb23display.ProblemTitle  = "Problem 23";
            pb23display.ProblemHeader = "Non-abundant sums";
            pb23display.Description   = "A perfect number is a number for which the sum of its proper divisors is exactly equal to the number.\n For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number.\nA number n is called deficient if the sum of its proper divisors is less than n and it is called abundant if this sum exceeds n.\nAs 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be written as the sum of two abundant numbers is 24.By mathematical analysis, it can be shown that all integers greater than 28123 can be written as the sum of two abundant numbers.However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit.\nFind the sum of all the positive integers which cannot be written as the sum of two abundant numbers.";
            pb23display.DisplayHeader();

            //////////////////////////////////////////////////////////////////
            int limit = 28123;//28123;

            List <long> list = NonAbundantSums.MakeabundantNumbersList(limit);

            //NonAbundantSums.DisplayList(list);
            bool[] isSumAbundant = NonAbundantSums.MakeSumOf2abundantNumbersList(list, limit);
            long   sum           = NonAbundantSums.NonSumOf2AbundantList(isSumAbundant);

            Console.WriteLine("sum of all numbers not able to be summed by two abundant numbers under {0} \nis {1} ", limit, sum);


            //////////////////////////////////////////////////////////////////

            pb23display.DisplayFooter();
            Console.ReadKey();
        }
Ejemplo n.º 5
0
        public void TestResolutionChange()
        {
            DisplayScreen screen = new DisplayScreen();

            if (screen.ScreenWidth == 800)
            {
                screen.ScreenWidth  = 1024;
                screen.ScreenHeight = 768;
                screen.UpdateSettingsToFullscreen();

                DisplayScreen tmp = new DisplayScreen();
                Assert.IsTrue((tmp.ScreenWidth == screen.ScreenWidth) &&
                              (tmp.ScreenHeight == screen.ScreenHeight));

                DisplayScreen.ResetSettings();
            }
            else
            {
                screen.ScreenWidth  = 800;
                screen.ScreenHeight = 600;
                screen.UpdateSettingsToFullscreen();

                DisplayScreen tmp = new DisplayScreen();
                Assert.IsTrue((tmp.ScreenWidth == screen.ScreenWidth) &&
                              (tmp.ScreenHeight == screen.ScreenHeight));

                DisplayScreen.ResetSettings();
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            DisplayScreen pb16display = new DisplayScreen();

            pb16display.ProblemTitle  = "Problem 16";
            pb16display.ProblemHeader = "Power digit sum";
            pb16display.Description   = "2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.\nWhat is the sum of the digits of the number 21000 ? ";
            pb16display.DisplayHeader();


            //////////////////////////////////////////////////////////////////
            int        sum    = 0;
            int        power  = 1000;
            BigInteger number = 2;

            number = BigInteger.Pow(number, power);
            string s = number.ToString();

            //Console.WriteLine(s);
            foreach (char item in s)
            {
                sum += Convert.ToInt32(char.GetNumericValue(item));//converts char to double then converts double to int32
            }

            Console.WriteLine("sum is : " + sum);
            //////////////////////////////////////////////////////////////////
            pb16display.DisplayFooter();
            Console.ReadKey();
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            DisplayScreen pb10display = new DisplayScreen();

            pb10display.ProblemTitle  = "Problem 10";
            pb10display.ProblemHeader = "Summation of primes";
            pb10display.Description   = "The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.\nFind the sum of all the primes below two million.";
            pb10display.DisplayHeader();

            //////////////////////////////////////////////////////////////////

            bool check;
            int  limit = 2000000;
            long sum   = 5;//sum of 2 and 3

            for (int i = 5; i <= limit; i = i + 2)
            {
                check = IsPrime.CheckIfPrime(i);
                if (check)
                {
                    sum += i;
                }
            }

            Console.WriteLine("\nsum of primes up to " + limit + " is : " + sum);

            /////////////////////////////////////////////////////////////////
            pb10display.DisplayFooter();
            Console.ReadKey();
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            DisplayScreen pb4display = new DisplayScreen();

            pb4display.ProblemTitle  = "Problem 4";
            pb4display.ProblemHeader = "Largest palindrome product";
            pb4display.Description   = "A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.\nFind the largest palindrome made from the product of two 3 - digit numbers.";
            pb4display.DisplayHeader();



            int biggestPalindrome = 0;

            for (int i = 100; i < 1000; i++)
            {
                for (int j = 100; j < 1000; j++)
                {
                    int result = NumberProduct.Product2Numbers(i, j);
                    if (Palindrome.IsPalindrome(result) && result > biggestPalindrome)
                    {
                        biggestPalindrome = result;
                    }
                }
            }

            pb4display.DisplayAnswer("Biggest Palindrome is :", biggestPalindrome);



            pb4display.DisplayFooter();
            Console.ReadKey();
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            DisplayScreen pb8display = new DisplayScreen();

            pb8display.ProblemTitle  = "Problem 8";
            pb8display.ProblemHeader = "Largest product in a series";
            pb8display.Description   = "The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832.\nFind the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?";
            pb8display.DisplayHeader();

            //////////////////////////////////////////////////////////////////
            string filePath = @"numberTable.txt";

            StreamProcess.DisplayFile(filePath);
            StreamReader sr = new StreamReader(filePath);

            string line = StreamProcess.ConvertToString(sr);

            //Console.WriteLine("converted string : " + line);
            long[] tab   = StringProducts.BiggestProduct(13, line);
            int    count = 0;

            foreach (long n in tab)
            {
                count++;
                Console.WriteLine("item " + count + " : " + n + " ");
            }

            /////////////////////////////////////////////////////////////////
            //  For this to Work you need to work with long type not int
            //
            /////////////////////////////////////////////////////////////////
            pb8display.DisplayFooter();
            Console.ReadKey();
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            DisplayScreen pb25display = new DisplayScreen();

            pb25display.ProblemTitle  = "Problem 25";
            pb25display.ProblemHeader = "1000-digit Fibonacci number";
            pb25display.Description   = "The Fibonacci sequence is defined by the recurrence relation:\nFn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1.\nHence the first 12 terms will be:\nF1 = 1\nF2 = 1\nF3 = 2\nF4 = 3\nF5 = 5\nF6 = 8\nF7 = 13\nF8 = 21\nF9 = 34\nF10 = 55\nF11 = 89\nF12 = 144\nThe 12th term, F12, is the first term to contain three digits.\nWhat is the index of the first term in the Fibonacci sequence to contain 1000 digits ? ";
            pb25display.DisplayHeader();

            //////////////////////////////////////////////////////////////////


            BigInteger fib1  = 1;    //base case for index 1
            BigInteger fib2  = 1;    //base case for index 2
            BigInteger limit = 1000; //number of digits

            BigInteger fib3 = Fibonacci.fibDigitLimit(fib1, fib2, limit);

            Console.WriteLine("Fibonacci index  is: {0} for first Fibonacci number of {1} digits", fib3, limit);



            //////////////////////////////////////////////////////////////////

            pb25display.DisplayFooter();
            Console.ReadKey();
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            DisplayScreen pb26display = new DisplayScreen();

            pb26display.ProblemTitle  = "Problem 26";
            pb26display.ProblemHeader = "Reciprocal cycles";
            pb26display.Description   = "A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given:\n1 / 2 = 0.5\n1 / 3 = 0.(3)\n1 / 4 = 0.25\n1 / 5 = 0.2\n1 / 6 = 0.1(6)\n1 / 7 = 0.(142857)\n1 / 8 = 0.125\n1 / 9 = 0.(1)\n1 / 10 = 0.1\nWhere 0.1(6) means 0.166666..., and has a 1 - digit recurring cycle. It can be seen that 1 / 7 has a 6 - digit recurring cycle.\nFind the value of d < 1000 for which 1 / d contains the longest recurring cycle in its decimal fraction part.";
            pb26display.DisplayHeader();

            //////////////////////////////////////////////////////////////////


            float   fraction = 1 / 7f;
            double  dbl      = 1 % 7d;
            decimal d        = 1 / 7m;

            Console.WriteLine(fraction);
            Console.WriteLine(dbl);
            Console.WriteLine("d:" + d);
            string s = "";

            s = d.ToString();
            Console.WriteLine(s);



            //////////////////////////////////////////////////////////////////

            pb26display.DisplayFooter();
            Console.ReadKey();
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            DisplayScreen pb22display = new DisplayScreen();

            pb22display.ProblemTitle  = "Problem 22";
            pb22display.ProblemHeader = "Names scores";
            pb22display.Description   = "Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score.\nFor example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of 938 × 53 = 49714.\nWhat is the total of all the name scores in the file?";
            pb22display.DisplayHeader();

            //////////////////////////////////////////////////////////////////

            string filePath = @"p022_names.txt";

            string[] namesArray = ProcessNames.FileToArray(filePath);
            int      alphaValue, positionValue;

            ProcessNames.SortByAlphabet(namesArray);
            foreach (string name in namesArray)
            {
                alphaValue    = ProcessNames.GetNameAlphaValue(name);
                positionValue = ProcessNames.GetNameAlphaPosition(namesArray, name);
                ProcessNames.NameScore(alphaValue, positionValue);
            }

            Console.WriteLine("Total name score is {0}", ProcessNames.score);

            //////////////////////////////////////////////////////////////////

            pb22display.DisplayFooter();
            Console.ReadKey();
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            DisplayScreen pb20display = new DisplayScreen();

            pb20display.ProblemTitle  = "Problem 20";
            pb20display.ProblemHeader = "Factorial digit sum";
            pb20display.Description   = "n! means n × (n − 1) × ... × 3 × 2 × 1\nFor example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,\nand the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.\nFind the sum of the digits in the number 100!";
            pb20display.DisplayHeader();


            //////////////////////////////////////////////////////////////////
            int    factorialNumber = 100;
            double sum;
            // To make it work it requires to use BigInteger after adding System.Numerics namespace

            BigInteger factorialResult = 0;

            factorialResult = Factorials.BigFactorial(factorialNumber);
            sum             = Factorials.SumNumbers(factorialResult);

            Console.WriteLine("Factorial " + factorialNumber + "! is:\n\n" + factorialResult + "\n\nsum of all the digits is : \n" + sum);


            //////////////////////////////////////////////////////////////////
            pb20display.DisplayFooter();
            Console.ReadKey();
        }
Ejemplo n.º 14
0
        public void Clear_DisplayBoxGetsCleared()
        {
            //Set up
            int           boxLines = 10;
            int           boxCols  = 10;
            DisplayBorder border1  = new DisplayBorder('#', 1);
            DisplayBorder border2  = new DisplayBorder('#', 1);
            DisplayBox    box1     = new DisplayBox("Box1", 0, 0, boxCols, boxLines, border1);
            DisplayBox    box2     = new DisplayBox("Box2", 0, boxLines, boxCols, boxLines, border2);
            DisplayScreen screen   = new DisplayScreen(10, 20);

            screen.Add(box1);
            screen.Add(box2);
            screen.LoadBorders();
            screen.WriteString("Box1", "SomeText", ConsoleColor.Black, ConsoleColor.White, 0, 0);
            screen.WriteString("Box2", "SomeText", ConsoleColor.Black, ConsoleColor.White, 0, 0);
            string expectedString1 = string.Concat(Enumerable.Repeat(new string(' ', 10) + Environment.NewLine, 10));

            //Action
            screen.Clear("Box1");
            StringWriter sw = new StringWriter();

            Console.SetOut(sw);
            screen.PrintScreen();
            int    splitPtr      = (boxCols + 2) * boxLines;
            string actualString1 = sw.ToString().Substring(0, splitPtr);
            string actualString2 = sw.ToString().Substring(splitPtr);

            //Assertion
            Assert.Equal(expectedString1, actualString1);       // Box1 should be cleared
            Assert.NotEqual(expectedString1, actualString2);    // but not Box2
        }
Ejemplo n.º 15
0
        public void LoadBorders_BordersDisplayedCorrectly(char borderChar, int borderThickness_left, int borderThickness_top, int borderThickness_right, int borderThickness_bottom, int boxWidth, int boxHeight,
                                                          int checkLine, string expectedString)
        {
            //Set up
            DisplayScreen screen = new DisplayScreen(150, 50);
            DisplayBorder border = new DisplayBorder(borderChar);

            border.Thickness[DisplayBorder.LEFT]   = borderThickness_left;
            border.Thickness[DisplayBorder.TOP]    = borderThickness_top;
            border.Thickness[DisplayBorder.RIGHT]  = borderThickness_right;
            border.Thickness[DisplayBorder.BOTTOM] = borderThickness_bottom;
            DisplayBox box = new DisplayBox("MyBox", 0, 0, boxWidth, boxHeight, border);

            screen.Add(box);

            //Action
            screen.LoadBorders();
            StringWriter sw = new StringWriter();

            Console.SetOut(sw);
            screen.PrintScreen();
            string targetString = sw.ToString().Substring(checkLine * 150 + (checkLine * 2), boxWidth);

            //Assert
            Assert.True(targetString == expectedString);
        }
Ejemplo n.º 16
0
        public void PrintScreen_TextDisplayedCorrectly(string text, int line, int column, string expectedString)
        {
            //Set up
            int           displayWidth  = 150;
            int           displayHeight = 50;
            int           boxX          = 0;
            int           boxY          = 0;
            int           boxWidth      = 80;
            int           boxHeight     = 30;
            DisplayBox    box           = new DisplayBox("MyBox", boxX, boxY, boxWidth, boxHeight);
            DisplayScreen screen        = new DisplayScreen(displayWidth, displayHeight);

            screen.Add(box);
            int stringBufferPtr = displayWidth * line + (line * 2) + column;

            //Action
            screen.WriteString("MyBox", text, ConsoleColor.White, ConsoleColor.Black, line, column);
            StringWriter sw = new StringWriter();

            Console.SetOut(sw);
            screen.PrintScreen();
            string targetString = sw.ToString().Substring(stringBufferPtr, expectedString.Length);

            //Assert
            Assert.True(targetString == expectedString);
        }
Ejemplo n.º 17
0
        public void Clear_OutputGetsCleared()
        {
            //Set up
            int           lines  = 10;
            int           cols   = 10;
            DisplayBorder border = new DisplayBorder('#', 1);
            DisplayBox    box    = new DisplayBox("MyBox", 0, 0, cols, lines, border);
            DisplayScreen screen = new DisplayScreen(cols, lines);

            screen.Add(box);
            screen.LoadBorders();
            screen.WriteString("MyBox", "SomeText", ConsoleColor.Black, ConsoleColor.White, 0, 0);
            string expectedString = string.Concat(Enumerable.Repeat(new string(' ', 10) + Environment.NewLine, 10));

            //Action
            screen.Clear();
            StringWriter sw = new StringWriter();

            Console.SetOut(sw);
            screen.PrintScreen();
            string actualString = sw.ToString();

            //Assertion
            Assert.True(expectedString == actualString);
        }
Ejemplo n.º 18
0
        static void Main(string[] args)
        {
            DisplayScreen pb12display = new DisplayScreen();

            pb12display.ProblemTitle  = "Problem 12";
            pb12display.ProblemHeader = "Highly divisible triangular number";
            pb12display.Description   = "The sequence of triangle numbers is generated by adding the natural numbers.\n So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28.\n The first ten terms would be:\n1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...\nLet us list the factors of the first seven triangle numbers:\n1: 1\n3: 1,3\n6: 1,2,3,6\n10: 1,2,5,10\n15: 1,3,5,15\n21: 1,3,7,21\n28: 1,2,4,7,14,28\nWe can see that 28 is the first triangle number to have over five divisors.\nWhat is the value of the first triangle number to have over five hundred divisors?";
            pb12display.DisplayHeader();

            //////////////////////////////////////////////////////////////////
            int  solution = 500;
            long divisors = 1;
            long term     = 1;
            long number   = 1;

            while (divisors < solution)
            {
                number   = Triangle.TriangleNumber(term);
                divisors = Triangle.NumberOfDivisors(number, solution);
                term++;
            }
            Console.WriteLine("value is " + number + " with " + divisors + " divisors");

            // pb12display.DisplayAnswer("Prime number " + order + " is  :", result);

            pb12display.DisplayFooter();
            Console.ReadKey();
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            DisplayScreen pb6display = new DisplayScreen();

            pb6display.ProblemTitle  = "Problem 5";
            pb6display.ProblemHeader = "Sum square difference";
            pb6display.Description   = "The sum of the squares of the first ten natural numbers is,\n12 + 22 + ... + 102 = 385\nThe square of the sum of the first ten natural numbers is,\n(1 + 2 + ... + 10)2 = 552 = 3025\nHence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.\nFind the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.";
            pb6display.DisplayHeader();

            //////////////////////////////////////////////////////////////////

            long a, b, result;

            a = SumSquareDifference.SumSquares(100);
            b = SumSquareDifference.SquareOfSum(100);

            result = SumSquareDifference.Difference(b, a);
            //Console.WriteLine(result);


            pb6display.DisplayAnswer("difference is :", result);



            pb6display.DisplayFooter();
            Console.ReadKey();
        }
Ejemplo n.º 20
0
        public void WriteString_InvalidBoxNameExceptionThrown()
        {
            //Set up
            DisplayBox    box    = new DisplayBox("MyBox", 0, 0, 80, 30);
            DisplayScreen screen = new DisplayScreen(150, 50);

            screen.Add(box);

            //Action - assert
            Assert.Throws <ArgumentException>(() => screen.WriteString("BogusName", "SomeText", ConsoleColor.Black, ConsoleColor.White, 0, 0));
        }
Ejemplo n.º 21
0
        public void Add_NewBoxGetsAddedToNonEmptyList(int box1X, int box1Y, int box1Width, int box1Height, int box2X, int box2Y, int box2Width, int box2Height)
        {
            //Set up
            DisplayBox    box1   = new DisplayBox("Box1", box1X, box1Y, box1Width, box1Height);
            DisplayBox    box2   = new DisplayBox("Box2", box2X, box2Y, box2Width, box2Height);
            DisplayScreen screen = new DisplayScreen(150, 50);

            screen.Add(box1);
            screen.Add(box2);

            //No assert needed as test succeeds if no exception is thrown
        }
Ejemplo n.º 22
0
        public void Add_OverlappingBoxesThrowsException(int box1X, int box1Y, int box1Width, int box1Height, int box2X, int box2Y, int box2Width, int box2Height)
        {
            //Set up
            DisplayBox    box1   = new DisplayBox("Box1", box1X, box1Y, box1Width, box1Height);
            DisplayBox    box2   = new DisplayBox("Box2", box2X, box2Y, box2Width, box2Height);
            DisplayScreen screen = new DisplayScreen(150, 50);

            screen.Add(box1);

            //Assertion
            Assert.Throws <DisplayBoxOverlapException>(() => screen.Add(box2));
        }
Ejemplo n.º 23
0
        static void Main(string[] args)
        {
            DisplayScreen pb9display = new DisplayScreen();

            pb9display.ProblemTitle  = "Problem 9";
            pb9display.ProblemHeader = "Special Pythagorean triplet";
            pb9display.Description   = "A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,\na2 + b2 = c2\nFor example, 32 + 42 = 9 + 16 = 25 = 52.\nThere exists exactly one Pythagorean triplet for which a +b + c = 1000.\nFind the product abc.";
            pb9display.DisplayHeader();

            //////////////////////////////////////////////////////////////////
            long a, b, c, d, limit, sum;

            c   = 1;
            b   = 1;
            sum = 0;
            long product;

            limit = 500;

            for (a = 2; a < limit; a++)
            {
                for (b = 1; b < limit / 2; b++)
                {
                    d = (a * a) + (b * b);
                    //Console.WriteLine(d);
                    c = Convert.ToInt32(Math.Sqrt(d));
                    //Console.WriteLine(c);

                    sum = a + b + c;
                    //Console.WriteLine("a = " + a + " , b = " + b + " , c = " + c);

                    //Console.WriteLine("Sum is : " + sum);
                    if (sum == 1000 && ((a * a) + (b * b) == (c * c)))
                    {
                        Console.WriteLine("\nSuccess!!!!!!!!!!\n a = " + a + " , b = " + b + " , c = " + c);
                        product = a * b * c;
                        Console.WriteLine("product is: " + product);
                        break;
                    }
                }
            }



            Console.WriteLine("YEAH!");



            /////////////////////////////////////////////////////////////////
            pb9display.DisplayFooter();
            Console.ReadKey();
        }
Ejemplo n.º 24
0
        public void Add_BoxNameAlreadyExistsThrowsException()
        {
            //Set up
            string        boxName = "MyBox";
            DisplayScreen screen  = new DisplayScreen(150, 50);
            DisplayBox    box1    = new DisplayBox(boxName, 0, 0, 80, 30);
            DisplayBox    box2    = new DisplayBox(boxName, 0, 0, 80, 30);

            //Action
            screen.Add(box1);

            //Assert
            Assert.Throws <DisplayBoxExistsException>(() => screen.Add(box2));
        }
Ejemplo n.º 25
0
        static void Main(string[] args)
        {
            DisplayScreen pb17display = new DisplayScreen();

            pb17display.ProblemTitle  = "Problem 17";
            pb17display.ProblemHeader = "Number letter counts";
            pb17display.Description   = "If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.\nIf all the numbers from 1 to 1000(one thousand) inclusive were written out in words, how many letters would be used?\n\nNOTE: Do not count spaces or hyphens. For example, 342(three hundred and forty - two) contains 23 letters and 115(one hundred and fifteen) contains 20 letters.The use of \"and\" when writing out numbers is in compliance with British usage.";
            pb17display.DisplayHeader();


            //////////////////////////////////////////////////////////////////
            Console.BufferHeight = Int16.MaxValue - 1; // ***** Alters the BufferHeight *****

            for (int i = 1; i <= 1000; i++)
            {
                if (i <= 20)
                {
                    CountLetters.LetterSumLess20(i);
                    Console.WriteLine();
                }
                else if (i > 20 && i < 100)
                {
                    CountLetters.LetterSumOver20Less100(i);
                    Console.WriteLine();
                }
                else if (i >= 100 && i < 1000)
                {
                    CountLetters.LetterSumOver100(i);
                    Console.WriteLine();
                }
                else if (i == 1000)
                {
                    CountLetters.LetterSum1000(i);
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine("Case not handled");
                    Console.WriteLine();
                }
            }


            Console.WriteLine("Total number of letters used is : " + CountLetters.lettersSum);


            //////////////////////////////////////////////////////////////////
            pb17display.DisplayFooter();
            Console.ReadKey();
        }
Ejemplo n.º 26
0
        static void Main(string[] args)
        {
            DisplayScreen pb67display = new DisplayScreen();

            pb67display.ProblemTitle  = "Problem 67";
            pb67display.ProblemHeader = "Number letter counts";
            pb67display.Description   = "If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.\nIf all the numbers from 1 to 1000(one thousand) inclusive were written out in words, how many letters would be used?\n\nNOTE: Do not count spaces or hyphens. For example, 342(three hundred and forty - two) contains 23 letters and 115(one hundred and fifteen) contains 20 letters.The use of \"and\" when writing out numbers is in compliance with British usage.";
            pb67display.DisplayHeader();


            //////////////////////////////////////////////////////////////////
            //string filePath = @"TriangleExample.txt";
            //string filePath = @"NumbersTriangle.txt";
            string       filePath  = @"p067_triangle.txt";
            StreamReader sr        = new StreamReader(filePath);
            string       line      = sr.ReadLine();
            int          pathSteps = 100;//number of lines in triangle or file

            int[,] triangleArray = new int[pathSteps, pathSteps];
            int column = 0;
            int row    = 0;

            //trying solution on example
            while (line != null)
            {
                // Console.WriteLine(line);
                t = line.Split(' ');
                foreach (string item in t)
                {
                    triangleArray[column, row] = int.Parse(item);
                    row++;
                }
                line = sr.ReadLine();
                column++;
                row = 0;
            }

            computeTriangle.DisplayArray(triangleArray, pathSteps);

            //Console.WriteLine("length:" + triangleArray.Length);
            computeTriangle.CompareTriangle(triangleArray, pathSteps);

            //Console.WriteLine("new array: ");
            //computeTriangle.DisplayArray(triangleArray);

            //////////////////////////////////////////////////////////////////
            pb67display.DisplayFooter();
            Console.ReadKey();
        }
Ejemplo n.º 27
0
        void drawIt()
        {
            Draw3D.p = -100;
            Graphics print3D = DisplayScreen.CreateGraphics();

            print3D.Clear(Color.White);
            print3D.DrawLine(new Pen(Brushes.Black), 0, 200, 800, 200);
            print3D.DrawLine(new Pen(Brushes.Black), 400, 0, 400, 400);
            print3D.DrawRectangle(new Pen(Brushes.Black), 0, 0, 799, 399);
            for (int i = 0; i < drawList.Count; i++)
            {
                drawList[i].printIt(ref print3D, new Pen(Brushes.Red), Brushes.Pink);
            }
            showNow();
        }
Ejemplo n.º 28
0
        public Display(IMap map)
        {
            this.Map = map;

            m_extentChanged  = true;
            m_fontsizeFactor = m_widthFactor = m_refScale = -1.0;
            //m_fixScales=new ArrayList();

            _labelEngine = new LabelEngine2();

            _screen = new DisplayScreen();
            _screen.RefreshSettings();

            this.dpi = GraphicsEngine.Current.Engine.ScreenDpi;
        }
Ejemplo n.º 29
0
        static void Main(string[] args)
        {
            DisplayScreen pb1display = new DisplayScreen();

            pb1display.ProblemTitle  = "Problem 1";
            pb1display.ProblemHeader = "Multiples of 3 and 5";
            pb1display.Description   = "If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.Find the sum of all the multiples of 3 or 5 below 1000.";
            pb1display.DisplayHeader();

            int s = Multiples.SumOfMultiples(3, 5, 1000);

            pb1display.DisplayAnswer("the total sum of multiples is", s);


            Console.ReadKey();
        }
Ejemplo n.º 30
0
        public void Add_NewBoxGetsAddedCorrectly(string name, int x, int y, int width, int height, int screenWidth, int screenHeight)
        {
            //Set up
            DisplayScreen screen = new DisplayScreen(screenWidth, screenHeight);
            DisplayBox    box    = new DisplayBox(name, x, y, width, height);

            //Action
            screen.Add(box);
            List <DisplayBox> boxList = screen.GetDisplayBoxes();

            //Assert
            Assert.True(boxList.Count > 0);
            Assert.True(boxList[0].Name == name);
            Assert.True(boxList[0].DisplayX == x);
            Assert.True(boxList[0].DisplayY == y);
            Assert.True(boxList[0].DisplayWidth == width);
            Assert.True(boxList[0].DisplayHeight == height);
        }