我想创建一个排序算法,它采用项目得分(基于向上/向下投票),并根据考虑时间衰减的不可改变的潜在得分对它们进行排序。
从分析哲学的角度来看,我的数学算法并不总是最好的。在下面的示例中,解决InverseTimeRelationship(currentItem.CreationDate)的一个简单而优雅的方法是什么:
class Item()
{
int upvotes;
int downvotes;
int SortScore;
DateTime CreationDate;
}
var currentItem = GetSomeSpecificItemMethod();
int Score = currentItem.upvotes - currentItem.downvotes;
currentItem.SortScore = Score * InverseTimeRelationship(currentItem.CreationDate);
SortItemsBySortScore(Item[]);
InverseTimeRelationship(DateTime CreationDate)
{
//Code To Write
}希望在一天后,SortScore会稍微低一点,但在2-3天后,无论它有多少选票,它都会从列表/首页的顶部消失。
发布于 2012-08-08 03:50:22
你可以看看the algorithm reddit uses。这似乎就是你想要的。
发布于 2012-08-08 03:57:22
也许:
e^-x (= 1/e^x)
请参阅(来自Wikipedia的) this image。
下面是代码:
double InverseTimeRelationship(DateTime CreationDate)
{
double HowFast = 0.1;
return Math.Exp(-DateTime.Now.Subtract(CreationDate).Days * HowFast);
}您可以使用以下命令进行尝试:
Text = InverseTimeRelationship(DateTime.Today.AddDays(-3)).ToString();https://stackoverflow.com/questions/11853002
复制相似问题