Skip to content

Instantly share code, notes, and snippets.

@mbillard
Created February 16, 2014 17:09
Show Gist options
  • Save mbillard/9037350 to your computer and use it in GitHub Desktop.
Save mbillard/9037350 to your computer and use it in GitHub Desktop.
A comparison of Reddit's previous and new algorithm
old new
# score > 0
_hot(1, 0, 1262304000) 2850.0 2850.0
_hot(1, 0, 1353107345) 4868.0 4868.0
_hot(1000, 500, 1262304000) 2852.69897 2852.69897
_hot(1000, 500, 1353107345) 4870.69897 4870.69897
# score < 0
_hot(0, 1, 1262304000) -2851.0 2850.0
_hot(0, 1, 1353107345) -4869.0 4868.0
_hot(1000, 1500, 1262304000) -2848.30103 2847.30103
_hot(1000, 1500, 1353107345) -4866.30103 4865.30103
# score == 0
_hot(500, 500, 1353107345) 0.0 4868.0
_hot(1000, 1000, 1262304000) 0.0 2850.0
require 'date'
def score(ups, downs)
ups - downs
end
def common_hot(ups, downs, date)
s = score(ups, downs)
order = Math.log([s.abs, 1].max, 10)
sign = if s > 0
1
elsif s < 0
-1
else
0
end
seconds = date - 1134028003
return sign, order, seconds
end
def old_hot(ups, downs, date)
sign, order, seconds = common_hot(ups, downs, date)
(order + sign * seconds / 45_000).round(7)
end
def new_hot(ups, downs, date)
sign, order, seconds = common_hot(ups, downs, date)
(sign * order + seconds / 45_000).round(7)
end
def both_hot(ups, downs, date)
o = old_hot(ups, downs, date)
n = new_hot(ups, downs, date)
{ old: o, new: n }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment