9
\$\begingroup\$

Intro

In J. R. R. Tolkien's Lord of the Rings, this phrase is on the cover of each book.

Three Rings for the Elven-kings under the sky,
Seven for the Dwarf-lords in their halls of stone, 
Nine for Mortal Men doomed to die,
One for the Dark Lord on his dark throne
In the Land of Mordor where the Shadows lie.
One Ring to rule them all, One Ring to find them,
One Ring to bring them all, and in the darkness bind them,
In the Land of Mordor where the Shadows lie

However, this isn't that interesting. It's just . Let's change this to .

What you have to do

Use the Stack Exchange API (or codegolf.stackexchange.com/users, or the Stack Exchange Data Explorer) and find the two users with the highest scores in , the newest user, and highest-reputation user with only negatively scored post.

Then, you must insert these usernames into the following text:

Three Golfs for the <highest-scored code-golf user>-king under the sky,
Seven for the <second-highest-scored code-golf user>-lord in their halls of stone,
Nine for the Mortal <newest user> doomed to die,
One for the Dark Lord <highest reuptation user with only negative scored code-golf posts>
In the land of Golfdor, where the Golfers lie
One Golf to rule them all, One Golf to find them,
One Golf to bring them all, and in the darkness bind them,
In the Land of Golfdor, where the Golfers lie

You must insert the four usernames you found into the text in the angle-brackets.

Other Rules

  • This is so the shortest code wins.
  • No URL Shorteners (including ppcg.(ga|lol))
\$\endgroup\$
  • 1
    \$\begingroup\$ Do you want In the Land of Golfdor, where the Golfers lie in the output twice like it is on the books? \$\endgroup\$ – Riley Sep 16 '16 at 17:29
  • \$\begingroup\$ Can we assume that there will be at least one user with only negatively scored code golf posts? \$\endgroup\$ – Martin Ender Sep 16 '16 at 17:49
  • 1
    \$\begingroup\$ @Riley Oh, I see. Editing. \$\endgroup\$ – NoOneIsHere Sep 16 '16 at 18:01
  • 1
    \$\begingroup\$ Could the dark lord have 0 points in code-golf, or must it be a negative score? \$\endgroup\$ – MegaTom Sep 16 '16 at 18:50
  • 1
    \$\begingroup\$ @MegaTom It must be negative. \$\endgroup\$ – NoOneIsHere Sep 16 '16 at 18:54
2
\$\begingroup\$

PHP, 577 bytes

not tested; I currently have no system available with allow_url_fopen=On
and I didn´t take the time to copy&paste the page sources.

function g($s){return join(file("http://codegolf.stackexchange.com/$s"));}$m=preg_match_all;$m("#r-de.+/(\d+)/.+>(.+)<#U",$a=g($u="$u&filter=all"),$b);$h=$b[2];$m("#>(.+)</a.+\s1 i#",g("users?tab=NewUsers&sort=creationdate"),$c);while($a){foreach($b[1]as$i=>$n)if($m("#st \"><strong>(-?)\d+#",$e=g("search?tab=votes&q=user:$n+[code-golf]"),$d)&&$d[1][0])break 2;if($a=strstr($a,"l=\"n"))$m("#r-de.+/(\d+)/.+>(.+)<#U",$a=g("$u&page=".$p+=!$p++),$b);}$m("#<code>(.+)</code>#U",g("q/93545"),$t);echo join([1=>$h[0],3=>$h[1],5=>$c[1][0],7=>$b[2][$i];]+split("#&[lg]t;#",$t[1][2]));

breakdown

// function to get page content from ppcg
function g($s){return join(file("http://codegolf.stackexchange.com/$s"));}

$m=preg_match_all;

// A,B: highest scores: find user names
$m("#r-de.+/(\d+)/.+>(.+)<#U",$a=g($u="users?filter=all"),$b);
$h=$b[2];   // remember the names

// C: new users: find username after "1 in one day"
$m("#>(.+)</a.+\s1 i#",g("$u&tab=NewUsers&sort=creationdate"),$c);

// D: loop through users from first query
while($a)
{
    foreach($b[1]as$i=>$n)
        // find "vote-count-post" in code-golf votes for that user
        if($m("#st \"><strong>(-?)\d+#",$e=g("search?tab=votes&q=user:$n+[code-golf]"),$d)
        &&$d[1][0])             // test if highest vote is negative
            break 2;
    // none found yet?
    if($a=strstr($a,"l=\"n"))   // if there is a "next" link, get next page
        $m("#r-de.+/(\d+)/.+>(.+)<#U",$a=g("$u&page=".$p+=!$p++),$b);
}

$m("#<code>(.+)</code>#U",g("q/93545"),$t); // get code blocks from question page

echo join([         // 4. join and print
    1=>$h[0],           // first two results from first preg_match
    3=>$h[1],
    5=>$c[1][0],        // first result from second preg_match
    7=>$b[2][$i];       // $i-th username from (latest) reputation list
]+                  // 3. and replace indexes 1,3,5,7 with above array
split("#&[lg]t;#",  // 2. split by "<" and ">"
    $t[1][2]        // 1. output template is the 3rd code block
));
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.