POINTS_TABLE = [3, 5, 7, 1]

function score(answer) {
  result = 0
  for i in 0..4
    result += POINTS_TABLE[answer[i]]
  return result

answer = [1, 2, 1, 0]

s = score(answer)

The sum performed is 5 + 7 + 5 + 3 = 20. It uses the values from the input as the indexes to read from the POINTS_TABLE.

This is the style of the answer I'm trying to work out: \begin{equation} score(answer) = \sum_{i=1}POINTS\_TABLE_{answer_i} \end{equation}

  • 3
    $\begingroup$ I don't really understand. What's wrong with the expression you already have? "Mathematical notation" isn't a programming langauge with defined syntax and semantics; it's much more like a natural language and there are multiple ways of writing things. Some may be more or less appropriate, depending on what you want to use the notation for. $\endgroup$ – David Richerby Jan 14 '17 at 22:24
  • $\begingroup$ Oh, I thought math notation was strict. The expression I have was my best attempt, I assumed it was wrong. $\endgroup$ – Qgenerator Jan 14 '17 at 22:28
  • $\begingroup$ So do mathematicians reading the notation it have to interpret it and try to guess what's meant? $\endgroup$ – Qgenerator Jan 14 '17 at 22:29
  • $\begingroup$ No, the author of the paper should explain all non-standard notation. $\endgroup$ – Yuval Filmus Jan 14 '17 at 22:34
  • $\begingroup$ However did you get the idea that this was a functional program? O.o $\endgroup$ – Raphael Jan 14 '17 at 22:34

While you are free to use whatever notation you want, as long as you explain it, it seems that the simplest solution here would be

$$ score(answer) = \sum_{i=0}^3 POINTS\_TABLE[answer[i]] $$

This should be self-explanatory in most circumstances.

  • $\begingroup$ What makes this the simplest? I've never seen notation that uses an array index like that. Would a non-programmer understand it? $\endgroup$ – Qgenerator Jan 15 '17 at 0:18
  • $\begingroup$ It's something I bet a lot of readers will understand. It's definitely not the simplest. It's just one reasonable solutions, there are many others. $\endgroup$ – Yuval Filmus Jan 15 '17 at 5:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.