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