PHP中的黑客新闻算法?
题
这是黑客新闻排名算法,我认为这是一种对事物进行排名的简单方法,尤其是用户在项目上投票,但是我真的不明白这一点,可以将其转换为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)))))
解决方案
直接从 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);
}
其他提示
有关于该算法如何工作的文章。发现了一个快速搜索: 黑客新闻排名算法的工作方式.
LISP可以使事情看起来比实际更复杂。
不隶属于 StackOverflow