Ask HN: How does HN algrorithm work for displaying entries on the front page?

29 points by modinfo ↗ HN
I am very interested in how exactly the position of a given entry on the HN front page is calculated.

9 comments

[ 3.3 ms ] story [ 31.7 ms ] thread
Post are ordered using the formula

upvotes / age_in_hurs^1.6 * lot_of_penalties

The 1.6 is call gravity and may change from time to time without warning. I'm not even sure that it's the current number. It was 1.6 a long time ago.

The lot_of_penalties are added automatically by the software, or manually by the mods, or indirectly by the users if enough users flag a post

Also, sometimes the mods give a second chance to some post they like and they appear near the bottom of the front page for a short time.

just to make sure i understand, is the formula

(upvotes / age_in_hurs^1.6) * lot_of_penalties

or is it

(upvotes / (age_in_hurs^1.6 * lot_of_penalties))

I would imagine it the former:

    (upvotes / age_in_hurs^1.6) * lot_of_penalties
I found this from 2010.

https://news.ycombinator.com/item?id=1781013

    (= 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)))))
Python:

  def calculate_score(votes, item_hour_age, gravity=1.8):

      return (votes - 1) / pow((item_hour_age+2), gravity)
You're probably not going to get good answers here in the comments, I think people are rightly worried about hn-frontpage being seo-d / reddified / propagandized, not a good end result for hn regardless.
This is actually the correct answer. While the code for the original Arc forums does exist, it differs from what HN actually deploys. And the mods have mentioned that they don't want to give details because they don't want the system to be gamed.
Some user have compared the front page order with the published algorithm, and they almost agree. For example

"How Hacker News ranking really works: scoring, controversy, and penalties" (righto.com) https://news.ycombinator.com/item?id=6799854 (920 points | Nov 26, 2013 | 190 comments)

"How Hacker News ranking algorithm works" (amix.dk) https://news.ycombinator.com/item?id=1781013 (311 points | Oct 11, 2010 | 76 comments)

"Reverse Engineering the Hacker News Ranking Algorithm" (sangaline.com) https://news.ycombinator.com/item?id=13867739 (349 points | March 14, 2017 | 49 comments)

Some values may change, for example I think "gravity" changed from 1.6 to 1.8 or vice versa, or perhaps it changed more times, I'm not tracking it.

The secret part is more related to other things. For example how many post can you make in a day before the system mark you automatically as a spammer or how many before they manually mark you as a spammer. Perhaps the automatic threshold is 100 because if you make 100 submission you are obviously a spammer, insane or an idiot. If they publish that, someone will make a bot to post 99 daily, every single day and claim that it's fair. But they may decide to ban the account manually with a much lower threshold. Also, the total number is not the only criteria, it's probably important if you are submitting your stuff or other people stuff, how interesting they are, how on-topic they are, ... My guess is that twenty on-topic interesting posts are fine, but five v14gr4 post are more than enough to get banned.

Submissions with a lot of replies can get penalized if the secret algorithm concludes that flamewars are ongoing.

Reliability of the source: I read it on HN...

Even if your post gets on the front page, it has to pass the smell test. HN is very good at detecting self-promotion and attention seeking.