24
1
Write a function or program which takes as input a set of distinct, non-negative integers \$\{x_1, \ldots, x_n\}\$ and outputs the smallest gap between any two values in the set, i.e. \$\min_{i\neq j}|x_i-x_j|\$.
Scoring
This is not code golf. Your score is the smallest gap of the set of code points of characters in your code (highest score wins). In other words: convert your code to integer code points (using ASCII or whatever code page is standard for your language); remove duplicates; use that as input to your program; the output is your score.
For instance, if your code is min(alldifferences(input)), to get your score convert m->109, i->105, n->110, (->40, ... and your score will be 1, since the codepoints for m and n are only 1 apart.
You may assume that the input contains at least 2 distinct values; behaviour is undefined otherwise. Your code must include at least two distinct characters.
If your encoding is ASCII, you can use this online R code to verify your score.
Test cases
Input | Output
0 1 2 3 4 | 1
2 4 8 16 32 | 2
1 | undefined
3 14 159 2653 | 11
4 6 8 9 12 14 | 1
3 14 2 | 1
Default rules for input/output apply. In particular, since the input is a set, you may assume any structure for the input.
1Something that I just understood: we remove duplicates when scoring our code, but we get distinct integers when it’s normal inputs. So we don’t have to remove duplicates ourselves in the code, right? – Fatalize – 2019-12-09T09:32:38.753
@Fatalize That's correct: the input is made of distinct integers. – Robin Ryder – 2019-12-09T09:38:20.117
1Suggested test case:
[3,14,2]. Output should be1, right? – Fatalize – 2019-12-09T09:38:44.367@Fatalize Yes. Edited in. – Robin Ryder – 2019-12-09T09:39:30.127
Unary, Lenguage like language may get any large score if they are allowed. Otherwise, answers in languages like Aheui, PerlYuYan would win this challenge. But sadly I can speak none of them. – tsh – 2019-12-09T11:27:47.500
@LuisMendo Yes, largest score wins. It is already in the text, in bold. :-) – Robin Ryder – 2019-12-09T11:28:49.530
@tsh Agreed. I don't find answers in Unary and Lenguage very interesting for this challenge. I have added your suggestion. – Robin Ryder – 2019-12-09T11:55:11.730
@Robin Ah, sorry, I hadn’t seen it – Luis Mendo – 2019-12-09T12:31:35.110
1Where a language has its own codepage, can we opt to use UTF-8? Or do we have to use the language-specific codepage? – Nick Kennedy – 2019-12-09T17:06:03.847
@NickKennedy If the language has its own codepage, you may use ASCII if all your characters are ASCII, but you may not use UTF-8. – Robin Ryder – 2019-12-09T17:11:59.000
Unfortunately, since braces pairs (
(),[],{}) and the lambda expression symbols (=>) are consecutive (or 1 apart for the case of{}), it seems impossible to get a score of more than 1 for most "non-golf" languages - Any chance to relax the scoring a bit so that these symbols are ignored? – G0BLiN – 2019-12-10T08:51:53.083@G0BLiN
[]are also 2 apart, like{}. I agree this makes the challenge difficult, but adding exceptions would defeat the point of the challenge. Non-golfing languages should probably aim for a score of 2 or 3. For instance, R makes a heavy use of(), but I have an (unposted) R solution with a score of 2, which was fun to work on. – Robin Ryder – 2019-12-10T09:36:55.990Robin Ryder - it's your question :). My point is that any answer in a non-golfing answer is likely to reach the highest score possible without much effort - while with the relaxation of e.g. ignoring braces, these suddenly there's a possibility to reach a higher than trivial score - so there's a challenge, a competition and things become more interesting... – G0BLiN – 2019-12-10T12:47:36.663