Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm php中的黑客新闻算法?_Algorithm_Lisp_Ranking_Arc Lisp - Fatal编程技术网

Algorithm php中的黑客新闻算法?

Algorithm php中的黑客新闻算法?,algorithm,lisp,ranking,arc-lisp,Algorithm,Lisp,Ranking,Arc Lisp,这是黑客新闻排名算法,我认为这是一种简单的排名方法,特别是如果用户对项目进行投票,但我真的不明白这一点,这能转换成PHP吗,这样我就能完全理解它了 ; Votes divided by the age in hours to the gravityth power. ; Would be interesting to scale gravity in a slider. (= gravity* 1.8 timebase* 120 front-threshold* 1 n

这是黑客新闻排名算法,我认为这是一种简单的排名方法,特别是如果用户对项目进行投票,但我真的不明白这一点,这能转换成PHP吗,这样我就能完全理解它了

; Votes divided by the age in hours to the gravityth power.
; Would be interesting to scale gravity in a slider.


(= gravity* 1.8 timebase* 120 front-threshold* 1
           nourl-factor* .4 lightweight-factor* .17 gag-factor* .1)

        (def frontpage-rank (s (o scorefn realscore) (o gravity gravity*))
          (* (/ (let base (- (scorefn s) 1)
                  (if (> base 0) (expt base .8) base))
                (expt (/ (+ (item-age s) timebase*) 60) gravity))
             (if (no (in s!type 'story 'poll))  .8
                 (blank s!url)                  nourl-factor*
                 (mem 'bury s!keys)             .001
                                                (* (contro-factor s)
                                                   (if (mem 'gag s!keys)
                                                        gag-factor*
                                                       (lightweight s)
                                                        lightweight-factor*
                                                       1)))))

关于这个算法是如何工作的,有很多评论。发现了一个快速搜索:

Lisp会使事情看起来比实际情况更复杂。

直接从Python中提取并翻译成PHP:

function calculate_score($votes, $item_hour_age, $gravity=1.8){
    return ($votes - 1) / pow(($item_hour_age+2), $gravity);
}

谢谢你的回答,你能给我解释一下$item\u hour\u age吗?谢谢,顺便说一句,请从我这里向上投票:)@getaway-
$item\u hour\u age
是你排名的东西的年龄(自创建以来的时间量),以小时为单位(从0开始计算)@MarkElliot,后续问题-如何在mysql语句之外基于此计算算法对mysql select查询中的行进行排序?@Andypandy:我想我不理解你的问题;你想用这个算法对MySQL行进行排序,但不想让MySQL运行这个算法?谁能解释一下,重力是什么。在什么情况下它会增加,为什么会使用它。我在构建mysql查询时也遇到问题,我不认为从数据库中提取所有提交的内容,然后对它们进行排序是个好主意。HN会限制它吗?很抱歉,这是一堆不相关的问题!谢谢,这就是我从lol获得lisp算法的地方,无论如何,干杯+我的投票