HackerNews Ranking Algorithm

Posted 3 years ago     3989      algorithm php
28

For anyone creating a "hot" and "new" feed, an algorithm is a difficult thing to create.

(p - 1) / (t + 2)^1.5

where p = points and t = age in hours

I've converted this to PHP for everyone:

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

For more information, have a read of this article: http://amix.dk/blog/post/19574

Personally, I think it would be better to normalize time for the number of submissions: right now when I submit a story late night US time, usually it goes nowhere because there is no one to upvote it.

You can do this by just using the number of stories submitted as time measure instead of hours.

Comments


This reminds me of "possible reddit flawed algorithm"
http://technotes.iangreenleaf.com/posts/2013-12-09-reddits-empire-is-built-on-a-flawed-algorithm.html



I remember reading that before I posted this, interesting how Reddit aren't even interested in fixing it... Maybe they're just trying to create publicity - not that they need any.



You need to be logged in to post comments.



Welcome to Snippet Repo!

Discover, share and save useful code snippets.

Join our community over over 2,000 members! Currently a 48% acceptance rate. Apply for membership →