Ejemplo n.º 1
0
        // http://www.pythonchallenge.com/pc/def/linkedlist.php

        /*
         * Problem 4, yooooooooo
         * From what I remember, each link has "and the next nothing is xxxx", with each link going to the next xxxx.
         * Like, it starts at http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345 with the next nothing as 44827.
         * Then http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=44827, and the next nothing is 45439 and so on...
         *
         * So here's what we need to do.
         * Http request to get the data from the page
         * Get "and the next nothing is <number>" (Maybe make it as a method for reasons...)
         * Then make the http request...
         * Going to make Http requests its own class.
         */
        static void Problem4()
        {
            // Start part
            HttpRequestHandler httphandler = new HttpRequestHandler();
            //string nothing = "12345";
            //string nothing = "8022";
            string       nothing       = "21545";
            string       nothingurl    = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=" + nothing;
            string       nothingSearch = @"and the next nothing is (\d+)";
            string       nothingnumber = @"[0-9]+";
            RegexHandler regexhandler  = new RegexHandler();
            int          well          = 1000;
            string       nexturl;

            for (int i = 0; i < well; i++)
            {
                nexturl = httphandler.Get(nothingurl);
                Console.WriteLine(nexturl);

                foreach (Match match in regexhandler.ReturnMatches(nothingSearch, nexturl))
                {
                    foreach (Match va in regexhandler.ReturnMatches(nothingnumber, match.Value))
                    {
                        nothing    = va.Value;
                        nothingurl = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=" + nothing;
                        System.Threading.Thread.Sleep(1000);
                    }
                }
            }
            //Console.WriteLine("And here's nothing");
        }
Ejemplo n.º 2
0
        // http://www.pythonchallenge.com/pc/def/equality.html

        /*
         * Problem 3, here we go.
         * Long string of text, "One small letter, surrounded by EXACTLY three big bodyguards"
         * So basic regex.
         * File is named "forP3.txt".
         *
         */
        static void Problem3()
        {
            // Load file
            FileHandling file    = new FileHandling();
            string       text    = (file.readFile("forP3.txt"));
            string       search  = "[^A-Z][A-Z]{3}[a-z]{1}[A-Z]{3}[^A-Z]";
            RegexHandler handler = new RegexHandler();

            // https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.matches?redirectedfrom=MSDN&view=net-5.0#overloads
            foreach (Match match in handler.ReturnMatches(search, text))
            {
                Console.Write(match.Value.Substring(4, 1));
            }
        }