Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changes from Version 1 of PythonChallenge4

Show
Ignore:
Author:
jpelcis (IP: 68.112.60.116)
Timestamp:
08/29/06 22:26:40 (18 years ago)
Comment:

Added the code.

Legend:

Unmodified
Added
Removed
Modified
  • PythonChallenge4

    v0 v1  
     1= Python Challenge -- Level 4 -- Solution = 
     2 
     3==== Code ==== 
     4 
     5{{{ 
     6#!d 
     7import tango.io.Stdout; 
     8import tango.net.Uri, tango.net.http.HttpClient; 
     9import tango.stdc.stdlib; 
     10import tango.text.Regex; 
     11 
     12pragma (lib, "WS2_32.lib"); 
     13 
     14void[] lastQuery; 
     15Uri uri; 
     16HttpClient client; 
     17 
     18void main () { 
     19        char[] changeQuery (Regex match) { 
     20                uri.setQuery("nothing=" ~ match.match(1)); 
     21                return match.match(1); 
     22        } 
     23 
     24        void sink (void[] content) { 
     25                debug Stdout.print(cast(char[])content ~ "\n"); 
     26                if (find(cast(char[])content, "Divide") != -1) { 
     27                        uri.setQuery("nothing=46059"); 
     28                } else if (find(cast(char[])content, "nothing is ") != -1) { 
     29                        size_t location = rfind(cast(char[])content, "nothing is "); 
     30                        sub(cast(char[])content[location .. length], "(([0-9])+)", &changeQuery); 
     31                } else if (cast(char[])content != "" && lastQuery == content) { 
     32                        Stdout.print(cast(char[])content).flush(); 
     33                        exit(0); 
     34                } 
     35                if (cast(char[])content != "") { 
     36                        lastQuery = content; 
     37                } 
     38        } 
     39 
     40        uri = new Uri("http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345"); 
     41        client = new HttpClient(HttpClient.Get, uri); 
     42 
     43        while (true) { 
     44                auto data = client.open(); 
     45                if (client.isResponseOK()) { 
     46                        client.read(&sink); 
     47                } 
     48                client.close(); 
     49                client.reset(); 
     50        } 
     51} 
     52}}}