2
$\begingroup$
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}

$\endgroup$
6
  • 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$ Commented Jan 14, 2017 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
    Commented Jan 14, 2017 at 22:28
  • $\begingroup$ So do mathematicians reading the notation it have to interpret it and try to guess what's meant? $\endgroup$
    – Qgenerator
    Commented Jan 14, 2017 at 22:29
  • $\begingroup$ No, the author of the paper should explain all non-standard notation. $\endgroup$ Commented Jan 14, 2017 at 22:34
  • $\begingroup$ However did you get the idea that this was a functional program? O.o $\endgroup$
    – Raphael
    Commented Jan 14, 2017 at 22:34

1 Answer 1

2
$\begingroup$

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.

$\endgroup$
2
  • $\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
    Commented Jan 15, 2017 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$ Commented Jan 15, 2017 at 5:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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