28
0
Your input is a list/sequence/vector/array of 5-255 positive integers, not necessarily unique. You may assume whatever input format is most suitable, and that each integer (as well as the quantity of integers) is chosen uniformly at random from the range 5-255.
The goal is to output the same list, in the same (or equivalent) format, but sorted into increasing (nondecreasing) order. A common early exercise in learning a language. Submissions to include:
An answer which works correctly and achieves the goal; and
A second answer which contains an annoying bug. Between 1% and 10% of the time, the output needs to be a list in the correct format and containing the correct elements, but in the wrong order (any order except correctly sorted). The rest of the time, the program must work correctly and achieve the goal.
The two answers must have Levenshtein distance one; that is, we can get one from the other by deleting one byte, or adding one byte, or changing one byte.
Scoring as usual in code-golf (based on the shorter of your two answers), with usual loopholes forbidden.
10% bonus (decrease to score) if the annoying bug is input-independent, i.e. using the same input again doesn't reproduce the bug (except between 1% and 10% of the time).
9Welcome to PPCG! I suggest removing the bonus, it’s not really good practice. – Mr. Xcoder – 2017-11-04T05:50:56.337
It seems that an answer that simply doesn't distinguish between two of the values (say, it can't tell 5 apart from 6, so it leaves 5s and 6s in the order they were given) fails with probability approximately 10.8%, which is just over the threshold. – Misha Lavrov – 2017-11-04T06:36:24.090
2It's unclear what is the probability of each possible input length. – user202729 – 2017-11-04T07:32:33.700
Should the bugged program work correctly 1-10% of the time for each individual length, or is the length of the input also chosen at random? If it is, what is the distribution? – Zgarb – 2017-11-04T10:46:12.553
12Should the spec between 1% and 10% of the time be fulfilled for each input or just overall for the set of possible inputs? For some inputs like
[5,5,5]
it's impossible to produce the wrong order – Luis Mendo – 2017-11-04T11:19:39.8234
There's a subtlety regarding our default IO formats. If our code defines a function, is it OK if it has some chance of defining the function consistently buggy, as opposed to defining a function that has some chance of being buggy?
– xnor – 2017-11-04T12:08:53.580@LuisMendo, overall -- that's why I specified the probabilities as I did. – Vadim Ponomarenko – 2017-11-04T14:26:29.893
@Zgarb, the input length is 5-255, chosen uniformly at random. – Vadim Ponomarenko – 2017-11-04T14:29:18.900
@xnor, I'm afraid I don't understand the question. If I run your code on the input (as specified, with random integers of random length), I should get buggy output between 1% and 10% of the time. – Vadim Ponomarenko – 2017-11-04T14:31:17.060
1@VadimPonomarenko On this site people are allowed to provide functions as well as full programs. xnor is asking whether it is allowed to have a function that, 1% to 10% of the time when created, is a buggy function that will always have a bug. Keeping to the letter of your question the answer's probably no, but it would be more fun if it was yes. – wizzwizz4 – 2017-11-04T15:05:23.830
@wizzwizz, the purpose of the challenge is to simulate a programmer trying to track down an intermittent bug. If the buggy function always produces the wrong answer, then the bug is not intermittent. – Vadim Ponomarenko – 2017-11-04T15:11:10.373
@VadimPonomarenko I'm making a distinction between the function object that exists in the memory of the interpreter / program and the textual representation of code that creates the function. 1% to 10% of the time that the textual representation of code is evaluated, the function created will always have a bug. The rest of the time, the function created will not have the bug. Is this clearer? – wizzwizz4 – 2017-11-04T15:24:22.793
@wizzwizz4, the transitory storage of the function object in memory is immaterial to this challenge. What matters is usage of the code on data sets. If I evaluate the code, and run it on 1000 data sets, I should get (roughly) 10-100 wrong outputs. If instead there is a 5% chance of getting 1000 wrong outputs, then the bug is not intermittent. – Vadim Ponomarenko – 2017-11-04T15:51:24.127
It depends how you're doing it. If you are using something like Python's
timeit
with both the function definition and parameters, it would give you roughly 10-100 wrong outputs. – wizzwizz4 – 2017-11-04T15:54:10.393@wizzwizz4, if it gives 10-100 wrong outputs (1%-10% on average) then it is a valid submission. – Vadim Ponomarenko – 2017-11-04T15:57:00.320
But it depends how you test it. (cc: @xnor) I recommend allowing this since in most languages it won't shorten the program, but in languages where it's golfy it'll make it more interesting. But it's up to you as the OP. – wizzwizz4 – 2017-11-04T16:13:13.897
If you choose to accept an answer, you should accept the answer that wins by the winning criteria (here: lowest score). – ovs – 2017-11-08T17:52:50.317