高尔夫之王


9

介绍

在JRR Tolkien的《指环王》中,这句话都在每本书的封面上。

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

但是,这并不是那么有趣。只是。让我们将其更改为

你要做的

使用Stack Exchange API(或codegolf.stackexchange.com/users,或Stack Exchange Data Explorer)在以下位置找到得分最高的两个用户,最新用户和声誉最高的用户,但得分均为负 发布。

然后,您必须将这些用户名插入以下文本:

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

您必须将找到的四个用户名插入尖括号中的文本中。

其他规定

  • 这是 因此最短的代码胜出。
  • 没有网址缩短符(包括ppcg.(ga|lol)

1
您是否想要In the Land of Golfdor, where the Golfers lie输出两次,就像在书本上一样?
莱利

我们是否可以假设至少有一个用户的高尔夫球杆得分为负值?
马丁·恩德

1
@Riley哦,我知道了。编辑中。
NoOneIsHere16年

1
暗黑领主在代码高尔夫中可以得到0分,还是必须是负分?
MegaTom

1
@MegaTom必须为负。
NoOneIsHere16年

Answers:


2

PHP,577字节

未经测试;我目前没有可用的系统,allow_url_fopen=On
也没有花时间来复制和粘贴页面源。

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]));

分解

// 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
));
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.