# Constructing a Function to Decrease a Quiz Score with Time

I wasn't sure which stack exchange site to pose this question to, so I'm asking it here, I hope it's appropriate. I thought it might be because it has to do with math. This game I'm writing for fun is basically a mental math speed quiz game. I'm writing it in javascript and html.

What I want to happen is for there to be a score depending on how fast you finished the quiz and how many you got correct. For an incorrect answer, you get 0 points. But for a correct answer, if you took 5 seconds to solve that question, you get more points than if someone took 8 seconds to answer the question.

This seems trivial but I was thinking about it and I don't really have a good algorithm or equation for judging a performance based on time.

For example: someone answering a question correctly in 5 seconds gets 20 points, someone answering correctly in 10 seconds gets 14 points (not exact figures, just example)

Does someone have an idea of this? Thanks

• I would use something logarithmic. The quicker the solve it, the more points they get, however as time goes on, the score they can get from the question decreases slower. – Christopher Liu Dec 23 '13 at 5:04
• can you possibly give me an example of a function that would do that? for example $f(x) = 5log(x)$ ? – Sam Creamer Dec 23 '13 at 5:07
• @ChristopherLiu A logarithmic function would give more points as time passed. I think you instead mean exponential decay (see my answer). – Austin Mohr Dec 23 '13 at 5:26

## 1 Answer

Let $n$ be the number of points you want awarded for an immediate, zero-second answer. The function $$ne^{-t}$$ (where $t$ is measured in seconds) awards $n$ points for such an answer, but quickly tends to $0$ with time. In fact, the decay is probably too quick if you are talking about point values in the tens. For example, if you set $n = 50$, then the point value is less than $1$ after just four seconds. You can slow down the decay by instead using $$ne^{-kt}, \text{ with }0 < k < 1.$$ The closer $k$ is to $0$, the slower the decay of points. You can experiment with values of $k$ and find one that suits you. A particularly interesting one is $k = 0.69$, which cuts the point value in half every second.

Finally, you might consider taking the greatest integer function of the formula above so that the point values are integers and at least one point is awarded for a correct answer. That is, you might award points based on the formula $$\left \lceil ne^{-kt} \right\rceil, \text{ with }0 < k < 1.$$

• very nice, thanks a lot. I'll have to do some work to decide how much I want the timing to affect the score. Cheers – Sam Creamer Dec 23 '13 at 5:42