105
8
Choose any five characters your language supports. There are 5! = 5×4×3×2×1 = 120 ways these can be arranged into a 5-character string that contains each character once; 120 permutations.
Choose your characters such that, when each of the 120 strings is run in your language, the 120 outputs produced will be as many unique integers from 1 to 120 (inclusive) as possible.
That is, for each of the 120 permutations of your 5 characters that produce runnable code that outputs a single number, you want the set of all those numbers to match as close as possible to the set of integers from 1 through 120.
So, ideally, your first permutation would output 1
, the next 2
, the next 3
, all the way up to 120
. But that ideal is likely impossible for most languages and characters.
The 5-character strings may be run as:
- a program with no input
- a function with no arguments
- a REPL command
Different strings can be run in different ways if desired
For the output to count, it must be a single integer output in a normal way, such as:
- being printed to stdout
- returned by the function
- the result of the REPL expression
The code should terminate normally (which may involve erroring out as long as the number has been output first). Code that does not run at all is fine, just the (nonexistent) output doesn't count. The numbers output should be in decimal unless a different base is the norm for your language.
The submission that generates the most distinct numbers from 1 through 120 wins. The earlier submission wins in case of a tie.
Notes
- Your 5 characters do not all need to be different, but of course having duplicate characters reduces the effective number of permutations.
- Float outputs such as
32.0
count as well as plain32
. (But32.01
would not.) - Leading zeroes such as
032
count as well as plain32
. - Valid outputs should be deterministic and time invariant.
- We are dealing with characters, not bytes.
Example
The characters 123+*
are a reasonable first choice for Python's (or many language's) REPL. The resulting 120 permutations and outputs are:
123+* n/a
123*+ n/a
12+3* n/a
12+*3 n/a
12*3+ n/a
12*+3 36
132+* n/a
132*+ n/a
13+2* n/a
13+*2 n/a
13*2+ n/a
13*+2 26
1+23* n/a
1+2*3 7
1+32* n/a
1+3*2 7
1+*23 n/a
1+*32 n/a
1*23+ n/a
1*2+3 5
1*32+ n/a
1*3+2 5
1*+23 23
1*+32 32
213+* n/a
213*+ n/a
21+3* n/a
21+*3 n/a
21*3+ n/a
21*+3 63
231+* n/a
231*+ n/a
23+1* n/a
23+*1 n/a
23*1+ n/a
23*+1 23
2+13* n/a
2+1*3 5
2+31* n/a
2+3*1 5
2+*13 n/a
2+*31 n/a
2*13+ n/a
2*1+3 5
2*31+ n/a
2*3+1 7
2*+13 26
2*+31 62
312+* n/a
312*+ n/a
31+2* n/a
31+*2 n/a
31*2+ n/a
31*+2 62
321+* n/a
321*+ n/a
32+1* n/a
32+*1 n/a
32*1+ n/a
32*+1 32
3+12* n/a
3+1*2 5
3+21* n/a
3+2*1 5
3+*12 n/a
3+*21 n/a
3*12+ n/a
3*1+2 5
3*21+ n/a
3*2+1 7
3*+12 36
3*+21 63
+123* n/a
+12*3 36
+132* n/a
+13*2 26
+1*23 23
+1*32 32
+213* n/a
+21*3 63
+231* n/a
+23*1 23
+2*13 26
+2*31 62
+312* n/a
+31*2 62
+321* n/a
+32*1 32
+3*12 36
+3*21 63
+*123 n/a
+*132 n/a
+*213 n/a
+*231 n/a
+*312 n/a
+*321 n/a
*123+ n/a
*12+3 n/a
*132+ n/a
*13+2 n/a
*1+23 n/a
*1+32 n/a
*213+ n/a
*21+3 n/a
*231+ n/a
*23+1 n/a
*2+13 n/a
*2+31 n/a
*312+ n/a
*31+2 n/a
*321+ n/a
*32+1 n/a
*3+12 n/a
*3+21 n/a
*+123 n/a
*+132 n/a
*+213 n/a
*+231 n/a
*+312 n/a
*+321 n/a
There are 36 numbers generated, all luckily within 1 to 120:
36, 26, 7, 7, 5, 5, 23, 32, 63, 23, 5, 5, 5, 7, 26, 62, 62, 32, 5, 5, 5, 7, 36, 63, 36, 26, 23, 32, 63, 23, 26, 62, 62, 32, 36, 63
However, only 8 of them are unique:
36, 26, 7, 5, 23, 32, 63, 62
So such a submission would only score 8 out of a maximal 120.
22I wanna do this challenge but it seems IMPOSSIBLE in
c
-like languages!!! – Mukul Kumar – 2016-12-09T08:57:56.8173@MukulKumar I believe there are REPLs in C-like language as well (e.g. gdb can be used - to a degree - as a REPL for C) so that the approach demonstrated for Python would still be an option. – Martin Ender – 2016-12-09T09:02:20.980
123+*
can't be improved by changing the digits (124+*
and125+*
still only generate 8 values). – Neil – 2016-12-09T10:03:25.4501Related (fixed link). – Fatalize – 2016-12-09T13:02:30.383
1In REPL or function entries, can we use
true
to mean1
? In JS, for example,true
coerces to1
whenever you use it for arithmetic. – ETHproductions – 2016-12-09T17:45:13.6333@ETH No to the true thing. Thats like allowing another base. – Calvin's Hobbies – 2016-12-09T22:06:54.523
Does output have to be static or can it be random? – OldBunny2800 – 2016-12-10T21:28:33.410
3@OldBunny2800 Valid outputs should be deterministic and time invariant. – Dennis – 2016-12-13T01:21:25.837
Whitespace, three chars only: Space, Tab and Enter. – sergiol – 2017-06-16T00:18:47.260
1Please reread the challenge. – CalculatorFeline – 2017-06-21T21:34:55.743