开发者

hacker news algorithm in php?

开发者 https://www.devze.com 2023-01-21 09:20 出处:网络
This is the Hacker News ranking algorithm, which I think is a simple way of ranking things, espcially if users are voting on items, but I really dnt understand this, can this be converted to PHP, so I

This is the Hacker News ranking algorithm, which I think is a simple way of ranking things, espcially if users are voting on items, but I really dnt understand this, can this be converted to PHP, so I can understand it fully?

; 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)
                                              开发者_如何学Go     (if (mem 'gag s!keys)
                                                        gag-factor*
                                                       (lightweight s)
                                                        lightweight-factor*
                                                       1)))))


Directly ripped from http://amix.dk/blog/post/19574 and translated to PHP from the Python:

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


There are write-ups about how this algorithm works. A quick search discovered: How Hacker News ranking algorithm works.

Lisp can make things seem more complicated than they really are.

0

精彩评论

暂无评论...
验证码 换一张
取 消