php中的黑客新闻算法?

时间:2010-10-20 18:57:42

标签: 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
           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)))))

2 个答案:

答案 0 :(得分:12)

直接从http://amix.dk/blog/post/19574翻录并从Python翻译成PHP:

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

答案 1 :(得分:6)

有关于此算法如何工作的文章。发现了一个快速搜索:How Hacker News ranking algorithm works

Lisp可以使事情看起来比实际上更复杂。