108
\$\begingroup\$

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 plain 32. (But 32.01 would not.)
  • Leading zeroes such as 032 count as well as plain 32.
  • 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.

\$\endgroup\$
10
  • 23
    \$\begingroup\$ I wanna do this challenge but it seems IMPOSSIBLE in c-like languages!!! \$\endgroup\$ Dec 9, 2016 at 8:57
  • 3
    \$\begingroup\$ @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. \$\endgroup\$ Dec 9, 2016 at 9:02
  • 2
    \$\begingroup\$ In REPL or function entries, can we use true to mean 1? In JS, for example, true coerces to 1 whenever you use it for arithmetic. \$\endgroup\$ Dec 9, 2016 at 17:45
  • 3
    \$\begingroup\$ @ETH No to the true thing. Thats like allowing another base. \$\endgroup\$ Dec 9, 2016 at 22:06
  • 3
    \$\begingroup\$ @OldBunny2800 Valid outputs should be deterministic and time invariant. \$\endgroup\$
    – Dennis
    Dec 13, 2016 at 1:21

36 Answers 36

1
2
2
\$\begingroup\$

Vyxal, 27 values

45²›d

And the numbers produced are:

[12, 11, 10, 5, 6, 50, 100, 25, 26, 36, 9, 8, 4, 32, 64, 16, 17, 92, 91, 110, 109, 90, 108, 45, 54, 46, 55]
\$\endgroup\$
1
\$\begingroup\$

OIL, 5 numbers

\n4120 (\n is the newline character)

For an OIL program to print anything, the print command (4) must be alone on a line. That can't be if the newline isn't somewhere inbetween the other characters. If the first character is a 4, followed by a newline and the other characters, the program will either:

  • print 0 (because it will try to print e.g. the 120th cell, which is empty, which is mapped to 0)
  • print 4, because e.g. 021 isn't a number (in OIL) and mapped to 0, and the 0th line contains a 4.

If the program starts with three characters, followed by the newline and then 4, the program prints the first line, because a missing argument from a non-existing line maps to 0. There are 6 possible permutations of that, but only four of them are integers in the range (012, 021, 102, 120).

The 5 legal numbers possible with this set of characters is therefore 4, 012, 021, 102, and 120.


I believe this is the best possible set of numbers for OIL. I found another set with which I get 4 numbers (0, 1, 2, 21): \n\n124.

\$\endgroup\$
1
\$\begingroup\$

Mathematica, 16 numbers

;1234

Not very interesting, but I can't seem to find anything better using arithmetic. The only thing that might work is using ! for factorial or double factorial, but this is so prone to generating massive numbers that it's impossible to brute force.

The 16 numbers (in range) that can be generated from the above 5 characters are:

1, 2, 3, 4, 12, 13, 14, 21, 23, 24, 31, 32, 34, 41, 42, 43
\$\endgroup\$
1
  • \$\begingroup\$ Why not ;6789 ? \$\endgroup\$ Apr 10, 2019 at 3:49
1
\$\begingroup\$

W, 5 numbers

3S*4+

The permutations can be printed by the following program, given that the Python interpreter is in your PATH. Don't count the preceding & trailing 0's as they are simply return codes:

import itertools
import os
for i in list(itertools.permutations("3S*4+",5)):
    os.system("echo "+''.join(list(i))+">code.w")
    os.system("W.py code.w []")
    print("END CASE")

This, with all the trailing/preceding 0's removed, is this.

Uniquified: {'43', '34', '3', '12', '4'}

\$\endgroup\$
1
\$\begingroup\$

Pyth, 18 numbers

579 t

Another challenge where being infix rather than prefix would be nice. This uses the space to "hide" some of the numbers and the decrement to get more numbers.

Here's all of the outputs.

[ 57 t9 ] => '57'
[ 57t 9 ] => '57\n8'
[ 59 t7 ] => '59'
[ 59t 7 ] => '59\n6'
[ 5 7t9 ] => '5\n8'
[ 5 9t7 ] => '5\n6'
[ 5 t79 ] => '5'
[ 5 t97 ] => '5'
[ 5t7 9 ] => '5\n6'
[ 5t9 7 ] => '5\n8'
[ 5t 79 ] => '5\n78'
[ 5t 97 ] => '5\n96'
[ 75 t9 ] => '75'
[ 75t 9 ] => '75\n8'
[ 79 t5 ] => '79'
[ 79t 5 ] => '79\n4'
[ 7 5t9 ] => '7\n8'
[ 7 9t5 ] => '7\n4'
[ 7 t59 ] => '7'
[ 7 t95 ] => '7'
[ 7t5 9 ] => '7\n4'
[ 7t9 5 ] => '7\n8'
[ 7t 59 ] => '7\n58'
[ 7t 95 ] => '7\n94'
[ 95 t7 ] => '95'
[ 95t 7 ] => '95\n6'
[ 97 t5 ] => '97'
[ 97t 5 ] => '97\n4'
[ 9 5t7 ] => '9\n6'
[ 9 7t5 ] => '9\n4'
[ 9 t57 ] => '9'
[ 9 t75 ] => '9'
[ 9t5 7 ] => '9\n4'
[ 9t7 5 ] => '9\n6'
[ 9t 57 ] => '9\n56'
[ 9t 75 ] => '9\n74'
[  57t9 ] => '8'
[  59t7 ] => '6'
[  5t79 ] => '78'
[  5t97 ] => '96'
[  75t9 ] => '8'
[  79t5 ] => '4'
[  7t59 ] => '58'
[  7t95 ] => '94'
[  95t7 ] => '6'
[  97t5 ] => '4'
[  9t57 ] => '56'
[  9t75 ] => '74'
[  t579 ] => ''
[  t597 ] => ''
[  t759 ] => ''
[  t795 ] => ''
[  t957 ] => ''
[  t975 ] => ''
[ t57 9 ] => '56'
[ t59 7 ] => '58'
[ t5 79 ] => '4'
[ t5 97 ] => '4'
[ t75 9 ] => '74'
[ t79 5 ] => '78'
[ t7 59 ] => '6'
[ t7 95 ] => '6'
[ t95 7 ] => '94'
[ t97 5 ] => '96'
[ t9 57 ] => '8'
[ t9 75 ] => '8'
[ t 579 ] => '578'
[ t 597 ] => '596'
[ t 759 ] => '758'
[ t 795 ] => '794'
[ t 957 ] => '956'
[ t 975 ] => '974'
{96, 97, 4, 5, 6, 7, 8, 9, 74, 75, 78, 79, 56, 57, 58, 59, 94, 95}
\$\endgroup\$
-3
\$\begingroup\$

Brainfuck, 3

<>+-.

It can produce -1 (or whatever the wraparound value is in the implementation), 0, or 1.

Unfortunately, since output in a loop is not counted, Brainfuck is very limited, since any loop is guaranteed to end on a 0, and the character space is too small to have both loop operators, +,-, output, and a register shift.

\$\endgroup\$
5
  • 4
    \$\begingroup\$ I don't see how brainfuck could output any number (in range) in 5 chars. You'd need to increment to 49 in order to print 1. \$\endgroup\$
    – Emigna
    Dec 9, 2016 at 22:57
  • 5
    \$\begingroup\$ In addition to Emigna's comment, only numbers in the range 1 to 120, inclusive, are counted. \$\endgroup\$ Dec 9, 2016 at 23:42
  • \$\begingroup\$ @MartinEnder What about this? This is accepted by consensus on the meta question the OP linked to. Also this. \$\endgroup\$
    – mbomb007
    Dec 13, 2016 at 16:07
  • \$\begingroup\$ @mbomb007 Brainfuck is not a Turing machine. \$\endgroup\$ Dec 13, 2016 at 16:11
  • 2
    \$\begingroup\$ @mbomb007 The second link is arguable. The challenge says "The numbers output should be in decimal unless a different base is the norm for your language." You might say that base-256 is the norm for Brainfuck. \$\endgroup\$ Dec 13, 2016 at 16:12
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.