1
\$\begingroup\$

Recently I had an interesting interaction on one of my questions. A user posted this answer in C++. My question requires a function on the positive numbers that has some properties, the user's answer essentially implemented the function add 1, which does not satisfy these properties on the positive integers, however this function does satisfy these properties on a cyclic group, which C++'s unsigned type is (this actually not define as such in the C++ specification, however almost all implementations do it this way).

Needless to say I have asked the user to delete the answer and the obliged. However this brings me some concern. In order to "fix" their answer it seems that this user would have to implement their own dynamically allocated integer class, which is a big pain to do (believe me I've done it before). It feels to me as if this is overkill, we often allow answers that will occasionally calculate an incorrect, as long as the "algorithm" is correct.

What should I do in this case? Is there a way that answers in languages like C++ can reasonably compete on these types of challenges without "cheating"?

\$\endgroup\$
5
  • \$\begingroup\$ Is there a way that answers in languages like C++ can reasonably compete on these types of challenges without "cheating"? How would they implement it differently than the JavaScript answer, for example, which will have incorrect behavior at some point? \$\endgroup\$
    – Stephen
    Jul 23, 2017 at 16:49
  • \$\begingroup\$ @StepHen I don't know anything about Javascript, if it has the same problem it is in the same boat. \$\endgroup\$
    – Wheat Wizard Mod
    Jul 23, 2017 at 16:50
  • \$\begingroup\$ Isn't it the standard to allow answers that work for INT_MIN to INT_MAX in the language, if it does not have arbitrary length integers? \$\endgroup\$
    – Stephen
    Jul 23, 2017 at 16:52
  • \$\begingroup\$ @StepHen The problem with that on this particular challenge is that you could actually design a function that is just +1 on that range and complicated every where else (if you want to know this function ping me in chat and I'll explain), thus someone could implement +1 and claim that they are implementing that function. It would work just like the function on the range int min to max, but that would be the trivial portion of the function. \$\endgroup\$
    – Wheat Wizard Mod
    Jul 23, 2017 at 16:57
  • \$\begingroup\$ I'm not seeing the problem with Step Hen's comment. The response to the answer you hypothesise would be "No, you're not implementing that function. -1, vote to delete as not an answer". \$\endgroup\$ Jul 24, 2017 at 9:15

1 Answer 1

2
\$\begingroup\$

Specify mathematical or computational integers

For this question, your instinct was correct: you asked about integers in the mathematical sense, not the 32-bit unsigned integers used by that particular answer. Although this may seem to favor languages with an integral type of unbound size, this is a language-agnostic issue, as other languages may have integer representations with other limitations. For example, Erik the Outgolfer's answer on a recent question I asked about 32-bit integers did not originally work (see the original version) because Jelly's representation of integers is unbounded.

Allowing HolyBlackCat's answer would have been Abusing C++'s native number type to trivialize the problem. If the algorithm they had used would have worked in theory for any positive integer, it would have been an acceptable answer, regardless of the integer representation's ability to accept integers of large magnitude.

\$\endgroup\$
2
  • \$\begingroup\$ My issue is how do we define "algorithm". It seems to me like a highly subjective attribute of a program. And might be open to interpretation, for instance if the roll over behavior was defined is behavior caused by the overflow part of the algorithm? \$\endgroup\$
    – Wheat Wizard Mod
    Jul 23, 2017 at 16:55
  • \$\begingroup\$ That is definitely an issue. I think you could go about this two ways. The first is to implement an unbounded integral type in the language (or use an existing implementation) and test the code using it (in this specific case, the lambda function will accept any argument that defines the !, ++ (prefix), and + operators correctly), and don't count this implementation toward the byte count of the solution. The second is to translate the code to an equivalent solution with a different representation of integers and test there. This I think would be more difficult to judge. \$\endgroup\$ Jul 23, 2017 at 16:59

You must log in to answer this question.

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