php中的黑客新闻算法?

发布于 2024-09-28 08:18:13 字数 1176 浏览 5 评论 0原文

这是Hacker News排名算法,我认为这是一种简单的排名方式,特别是如果用户对项目进行投票,但我真的不明白这一点,可以将其转换为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)))))

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)
                                                   (if (mem 'gag s!keys)
                                                        gag-factor*
                                                       (lightweight s)
                                                        lightweight-factor*
                                                       1)))))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

难得心□动 2024-10-05 08:18:13

直接从 http://amix.dk/blog/post/19574 中提取并翻译为 PHP蟒蛇:

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

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);
}
⒈起吃苦の倖褔 2024-10-05 08:18:13

有关于该算法如何工作的文章。快速搜索发现:黑客新闻排名算法的工作原理

Lisp 可以让事情看起来比实际情况更复杂。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文