# On type restrictions

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"?

• 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? Jul 23 '17 at 16:49
• @StepHen I don't know anything about Javascript, if it has the same problem it is in the same boat.
– Wheat Wizard Mod
Jul 23 '17 at 16:50
• 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? Jul 23 '17 at 16:52
• @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.
– Wheat Wizard Mod
Jul 23 '17 at 16:57
• 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". Jul 24 '17 at 9:15

• 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. Jul 23 '17 at 16:59