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
 A: 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.
$$
