ruby reddit'hot'算法,在ruby中,用拼写错误修复

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby reddit'hot'算法,在ruby中,用拼写错误修复相关的知识,希望对你有一定的参考价值。

require 'date'

# Actually doesn't matter WHAT you choose as the epoch, it
# won't change the algorithm. Just don't change it after you
# have cached computed scores. Choose something before your first
# post to avoid annoying negative numbers. Choose something close
# to your first post to keep the numbers smaller. This is, I think,
# reddit's own epoch. 
$our_epoch = Time.local(2005, 12, 8, 7, 46, 43).to_time


def epoch_seconds(t)
  (t.to_i - $our_epoch.to_i).to_f
end


# date is a ruby Time
def hot(ups, downs, date)
    s = ups - downs
    displacement = Math.log( [s.abs, 1].max,  10 )

    sign = if s > 0
      1
    elsif s < 0
      -1
    else
      0
    end

    return (displacement * sign.to_f) + ( epoch_seconds(date) / 45000 )
end 

以上是关于ruby reddit'hot'算法,在ruby中,用拼写错误修复的主要内容,如果未能解决你的问题,请参考以下文章

Hot10020. 有效的括号

tf.pad(one_hot_encoding, [[0, 0], [1, 0]], mode='CONSTANT')

webpack 问题Can't resolve webpack/hot/dev-server'怎么解决

One Hot Encoding:ValueError:无法将字符串转换为float:'是'

ruby reddit_comments.rb

ruby 用于删除所有云文件和容器的Ruby脚本 - 也就是关闭帐户。需要宝石'雾'和'哑剧类型'