2

I have read many topics on reputation but none of them fits my needs. I am implementing a Q & A site. Each post (question/answer) can be voted. Each user has a reputation score. Depending on user's reputation, the vote for each post caries more weight. However, I dont want to do an endless if else, for example

if (0 < user_reputation < 10) then post_vote += 1
if (10 < user_reputation < 20) then post_vote += 2
if (20 < user_reputation < 30) then post_vote += 3
if (30 < user_reputation < 40) then post_vote += 4
..........

Please, suggest a better way (a formula or so) to calculate the post's vote without using the above endless if/else. I'm using Java.

ipkiss
  • 13,311
  • 33
  • 88
  • 123
  • 4
    If you see there is a logical relation between `10 with 1` and `40 with 4` :) – Suresh Atta Sep 18 '13 at 10:15
  • 1
    what about 10? is it 1 or 2? – Philipp Sander Sep 18 '13 at 10:17
  • 1
    I suspect you'll find, as users gain more reputation, that simply dividing by 10 will still very heavily (too heavily) favor users with high reputations. In the past I've found that adding something `Log2(user_reputation)` prevents high-reputation users from completely dominating. – Jim Mischel Sep 18 '13 at 18:26
  • Thanks Jim Mischel, your solution and Pawan's combined is exactly what I was looking for. – ipkiss Sep 19 '13 at 02:37

1 Answers1

3

use post_vote += (int)(user_reputation/10);

gifpif
  • 4,507
  • 4
  • 31
  • 45