Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm to determine sequence of votes needed to reach a score

Tags:

algorithm

I have to write some PHP code which determines what possible stackoverflow scores are.

When a user registers he gets 1 point of reputation (lets call this POR).

From here I have to find out what the possible POR values are until the user reaches 100 POR

example:

user1 = 1 (registration) + 10 (good answer) - 2 (bad answer) = 9 POR
user2 = 1 (registration) + 5 (good question) + 10 (good answer) = 16 POR

The possible choices are:

+10 good answer
+5 good question
-2 bad answer/question

What I was thinking of doing is:

until 100 POR and start from 1
 for all 3 possibilites
  choose a random posibility and append the current score with - and the actual score
 end
end

Is there a way to do this which will avoid repetitions?

like image 215
eric Avatar asked Nov 14 '11 13:11

eric


1 Answers

First abstract your problem: You are basically asking for the number of paths in a graph, with 100 nodes as the POR between 1 and 100 and 3 edges from each node (+10, +5, -2).

You might be asking for the number of paths in this graph. Unfortunately, the graph is cyclic (1 good answer, 5 bad answers, and you are back to 1). The answer is thus "infinite".

You might also be asking for the scores that can be reached (the nodes reachable from node 1). You can figure that out on paper, as well, by looking sharply at the combination of one good question and two bad answers.

like image 175
thiton Avatar answered Sep 20 '22 19:09

thiton