I've seen some answers that hard code the input or rely on the existence of a user-defined variable, see for example this question. The OP asked for a "function or equivalent subprogram". I don't think this kind of answers are acceptable. What's your opinion on this?

  • 2
    \$\begingroup\$ I don't know, it really depends. Ideally every OP should clearly specify which forms of input and output are acceptable. In this case "or equivalent subprogram" isn't all that specific and I think a snippet that computes the result based on predefined variables could well be considered equivalent. I also think this might be hard to answer generically for all languages. In some languages (REPL-based ones, like Mathematica, for instance) it's even natural to write a "program" as just a snippet that operates on the results of previous computations. \$\endgroup\$ – Martin Ender Jul 2 '14 at 9:08

In general:

  • Is it explicitly allowed? Then these answers are acceptable.
  • Is it explicitly disallowed? Then these answers are not acceptable.
  • None of above? Then:
    • If it explicitly specifies another way to receive input (e.g. STDIN), then I would assume that it's not allowed, because the spec gives another way to receive input.
    • If you are not sure, leave a comment. If the OP doesn't reply, then the chance that they will ever accept an answer is low, and then I think it is OK to use a variable as input.

In this case, leaving a comment seems the best, because if your submission is an "equivalent subprogram", then there is nowhere specified how the input for this subprogram should be given. But because the question is migrated from Stack Overflow and the OP doesn't have an account here, the chance that he will reply (and accept an answer) is very low, so in this case, I'd say it is OK.


Not the answer you're looking for? Browse other questions tagged .