This is a , , challenge to produce a fixed output with no input.

The output format, however, is flexible - it may be printed to standard out, printed to standard error, returned as a list of characters, returned as a list of bytes, or returned as a list of integers. If you think anything else seems reasonable just ask in the comments!

Here is a simple, big-letter ASCII art CODEGOLF:

 CCCC   OOO   DDDD   EEEEE   GGG    OOO   L      FFFFF
C      O   O  D   D  E      G      O   O  L      F
C      O   O  D   D  EEE    G  GG  O   O  L      FFF
C      O   O  D   D  E      G   G  O   O  L      F
 CCCC   OOO   DDDD   EEEEE   GGGG   OOO   LLLLL  F

Without any newlines (or trailing spaces on any lines) it is 256 characters long:

 CCCC   OOO   DDDD   EEEEE   GGG    OOO   L      FFFFFC      O   O  D   D  E      G      O   O  L      FC      O   O  D   D  EEE    G  GG  O   O  L      FFFC      O   O  D   D  E      G   G  O   O  L      F CCCC   OOO   DDDD   EEEEE   GGGG   OOO   LLLLL  F

The (0-based) indices of the non-space characters are:

1, 2, 3, 4, 8, 9, 10, 14, 15, 16, 17, 21, 22, 23, 24, 25, 29, 30, 31, 36, 37, 38, 42, 49, 50, 51, 52, 53, 54, 61, 65, 68, 72, 75, 82, 89, 93, 96, 103, 104, 111, 115, 118, 122, 125, 126, 127, 132, 135, 136, 139, 143, 146, 153, 154, 155, 156, 163, 167, 170, 174, 177, 184, 188, 191, 195, 198, 205, 207, 208, 209, 210, 214, 215, 216, 220, 221, 222, 223, 227, 228, 229, 230, 231, 235, 236, 237, 238, 242, 243, 244, 248, 249, 250, 251, 252, 255

You may not use any of these 97 bytes in your code but must produce a list (or similarly output) these bytes, in this order, with the missing bytes replaced by the 32nd byte in the code page you are using (in many, many code-pages a space character).

You may include the pretty-printing* newlines (but no trailing spaces on the lines) if it helps.

For example using the Jelly code-page this output is acceptable:

 ¢£¤¥   ®µ½   ÇÐÑ×   ßæçðı   øœþ    $%&   *      12345
6      =   A  D   H  K      R      Y   ]  `      g
h      o   s  v   z  }~¶    ⁴  ⁷⁸  ⁻   Ɓ  Ƒ      ƲȤɓ
ƈ      ɲ   ʂ  ȥ   Ẹ  Ḳ      Ṭ   Ỵ  Ḃ   Ḟ  İ      Ṡ
 ẆẊẎŻ   ẹḥị   ṇọṛṣ   ẉỵẓȧḃ   ḟġḣŀ   ṗṙṡ   ẏż«»‘  ”

...but so is:

 ¢£¤¥   ®µ½   ÇÐÑ×   ßæçðı   øœþ    $%&   *      123456      =   A  D   H  K      R      Y   ]  `      gh      o   s  v   z  }~¶    ⁴  ⁷⁸  ⁻   Ɓ  Ƒ      ƲȤɓƈ      ɲ   ʂ  ȥ   Ẹ  Ḳ      Ṭ   Ỵ  Ḃ   Ḟ  İ      Ṡ ẆẊẎŻ   ẹḥị   ṇọṛṣ   ẉỵẓȧḃ   ḟġḣŀ   ṗṙṡ   ẏż«»‘  ”

...and so is:

[32, 1, 2, 3, 4, 32, 32, 32, 8, 9, 10, 32, 32, 32, 14, 15, 16, 17, 32, 32, 32, 21, 22, 23, 24, 25, 32, 32, 32, 29, 30, 31, 32, 32, 32, 32, 36, 37, 38, 32, 32, 32, 42, 32, 32, 32, 32, 32, 32, 49, 50, 51, 52, 53, 54, 32, 32, 32, 32, 32, 32, 61, 32, 32, 32, 65, 32, 32, 68, 32, 32, 32, 72, 32, 32, 75, 32, 32, 32, 32, 32, 32, 82, 32, 32, 32, 32, 32, 32, 89, 32, 32, 32, 93, 32, 32, 96, 32, 32, 32, 32, 32, 32, 103, 104, 32, 32, 32, 32, 32, 32, 111, 32, 32, 32, 115, 32, 32, 118, 32, 32, 32, 122, 32, 32, 125, 126, 127, 32, 32, 32, 32, 132, 32, 32, 135, 136, 32, 32, 139, 32, 32, 32, 143, 32, 32, 146, 32, 32, 32, 32, 32, 32, 153, 154, 155, 156, 32, 32, 32, 32, 32, 32, 163, 32, 32, 32, 167, 32, 32, 170, 32, 32, 32, 174, 32, 32, 177, 32, 32, 32, 32, 32, 32, 184, 32, 32, 32, 188, 32, 32, 191, 32, 32, 32, 195, 32, 32, 198, 32, 32, 32, 32, 32, 32, 205, 32, 207, 208, 209, 210, 32, 32, 32, 214, 215, 216, 32, 32, 32, 220, 221, 222, 223, 32, 32, 32, 227, 228, 229, 230, 231, 32, 32, 32, 235, 236, 237, 238, 32, 32, 32, 242, 243, 244, 32, 32, 32, 248, 249, 250, 251, 252, 32, 32, 255]

(This last one is a valid list output in any language with any code-page, and one may use any reasonable list-formatting too.)


Here is Python 3 code which shows the unavailable ASCII bytes.

* Although the printing itself might not actually be all that pretty!

  • You may not use any of these 97 bytes in your code Does that mean I may not use these ASCII characters: $%&*123456=ADHKRY]``ghosvz}~ and no newline? – Titus Nov 21 at 14:39
  • @Titus If your code-page aligns with ASCII then yes - or a tab or any of the other chars in the range given, e.g. the unprintables or extended. (Also - see the linked Python script at TIO) – Jonathan Allan Nov 21 at 14:44
  • 2
    For what it's worth, here is a code validator (assuming no special code-page). – Arnauld Nov 21 at 16:55
  • I almost have it in PHP ... only need a way to array_map(function($n){return sprintf("%6b",$n);},...) without a $ (I could do that) AND without } (no idea). Yes; I want to pack the data! – Titus Nov 23 at 12:48

10 Answers 10

Python 2, 321 203 bytes

print map(lambda(i,x):(x>'0'and i-8-8-8-8)+8+8+8+8,enumerate(bin(int(reduce(lambda x,y:x+repr('abcdefijkl'.find(y)),'cfjdbljcibkeajjejiljjlcbjddlafklebajjlceljdeadficijflealkeklkljadfbbckjebclkf','')))))

Try it online!


Explanation:

from the inside out:

cfjdbljcibkeajjejiljjlcbjddlafklebajjlceljdeadficijflealkeklkljadfbbckjebclk is the number 25731972618407747697792173390589410779249734035626759409848989703511287412985 encoded with allowed characters. (No 123456's allowed)

reduce(lambda x,y:x+repr('abcdefijkl'.find(y)),'cfjdbl..bclkf','') maps the string to its decimal string:

  • reduce(lambda x,y:x+y,'..','') is the same as ''.join('..') (No o's allowed)
  • repr('..') instead of str('..') (No s's allowed)
  • 'abcdefijkl'.find(y) maps a char to a digit.

enumerate(bin(int(...))) converts the number string to a binary string, and enumerates. This gives the pairs [(0,0), (1,b), (2,1), (3,1), ...]

map(lambda(i,x):(x>'0'and i-8-8-8-8)+8+8+8+8, ... ) converts the enumerated list to the final result.

  • map(lambda(i,x):.. , .. ) instead of [... for(i,x)in ...] (No o]'s allowed)
  • lambda(i,x): .. converts each (index,value) pair to either the index or 32.
  • (x>'0'and i-8-8-8-8)+8+8+8+8 is the same as:
    • x>'0'and i or 8+8+8+8, (No o's allowed)
    • [8+8+8+8,i][x>'0'] or [8<<9-7,i][x>'0'], (No ]'s allowed)
  • 8+8+8+8 = 32 (No 23's allowed)

This means that the program is essentially the same as:

print[[32,i][x>'0']for i,x in enumerate(bin(25731972618407747697792173390589410779249734035626759409848989703511287412985))]

C (gcc), 318 bytes

main(_){--_<88+80+88?printf((int[:>){77707-989908070??>,((int[:>){0xE8E8C79E^0xB0B0080,0xC07E0870^0xE0000C00,0xCC08099C^0xEE0C008E,0xE8888989^0xCC00808,0x9E088990^0x800C0000,0x990C8888^0x080ECC00,0xF9C7a088^0x080000C0,0x9F8C78F8^0x900000??>[_>>(0xC^0x9):>>>(_<<9+9+9>>9+9+9))<<(70^89)>>(70^89)?_:' '),main(_+9-7):0;??>

Try it online!

This one is a bit of a journey...

1. Compressing the list

Somehow we will need to check if a given integer is one of the special code points. Any 'naked' list will be far too long, so we use a check list. This list has a non-zero value at code points that are 'restricted' and a zero value at those that aren't.

Unfortunately this still takes 512 bytes just to have the list (it looks like 0,0,7,7,0,7,0,...). This can be shortened with a bitmask.

To make use of the bitmask we will break each byte into two pieces. The first 3 bits will pick a mask from an array while the last 5 will pick a bit in the array. We can't shrink the array any further because the 32-bit integers used by default don't support any more than 2^5=32 bits.

Using a reference implementation I wrote:

int main() {
    int i;
    int vals[] = {1, 2, 3, 4, 8, 9, 10, 14, 15, 16, 17, 21, 22, 23, 24, 25, 29, 30, 31, 36, 37, 38, 42, 49, 50, 51, 52, 53, 54, 61, 65, 68, 72, 75, 82, 89, 93, 96, 103, 104, 111, 115, 118, 122, 125, 126, 127, 132, 135, 136, 139, 143, 146, 153, 154, 155, 156, 163, 167, 170, 174, 177, 184, 188, 191, 195, 198, 205, 207, 208, 209, 210, 214, 215, 216, 220, 221, 222, 223, 227, 228, 229, 230, 231, 235, 236, 237, 238, 242, 243, 244, 248, 249, 250, 251, 252, 255, 0};

    for (i = 0; i <= 0xFF; ++i) {
        int j,f;
        f = 0;
        for (j = 0; vals[j]; ++j)
            if (vals[j] == i)
                f = 1;
        if (f)
            printf("1");
        else
            printf("0");

        if (i%32 == 31)
            printf("\n");
    }

    return 0;
}

I was able to generate the appropriate values for this new array using the command echo "obase=16;ibase=2;$(./a.out | rev)" | bc. This passes the output of the above program (./a.out) to the rev program, which reverses each line. It prints this along with a header to bc that sets the output base to 16 and input base to 2. Thus bc converts the binary digits to a hexadecimal bitmask.

The resulting array is can be seen in this 'beta' solution:

f(){
    int x;
    int arr[] = {0xE3E3C71E, 0x207E0470, 0x22040912, 0xE4488181, 0x1E048990, 0x91024488, 0xF1C7A048, 0x9F1C78F8};
    for (x=0; x<=0xFF; ++x) {
        int mask = arr[x >> 5];
        int bit = mask >> (x & 0x1F);

        if (bit & 1)
            printf("%c", x);
        else
            printf(" ");
    }
}

2. Dealing with the constraints

There are a lot of constraints that need to be placed on the above code. Here I go through each of them 1-by-1.

  1. No assignment

This is felt by other languages as well, without assignment in C it is very hard to get any guaranteed values into variables. The easiest way for us is to write our function as a full program. The first argument of main will be passed the value of argc which will be 1 if called with no arguments.

  1. No looping

The only looping constructs in C are for, while, and goto all of which contain restricted characters. This leaves us with using recursion. The main function will start at 1 and recurse until the argument is >256, meanwhile it will decrement the argument internally to use a 0-indexed value.

  1. Hex values

The values in the above array are hexadecimal, even when converted to decimal, these contain some restricted symbols, most notably 123456 (AD can be lower-cased). To work around this each constant is XORed with another such that the restricted characters are removed. 1 becomes 9^B, 2 becomes C^E, 3 becomes B^8, 4 becomes 8^C, 5 becomes 9^C, and 6 becomes 9^F (there are more ways to do it, I chose this way).

  1. Printing

The restrictions don't leave many printing functions left to us. putchar and puts are both restricted, leaving printf. Unfortunately we have to send printf a format string, ideally "%c". All such strings have that pesky percent sign that we wish to remove. Luckily we assume a little-endian machine (because apparently that's what TIO uses, and that's pretty typical). By constructing the integer whose bytes in memory are 0x25 (%), 0x63 (c), 0x00 (\0), anything (doesn't matter, its after the null terminator) we can just pass its address to printf and it will assume it is a string. One such number that works is -989830363 (0xC5006325). This is easy to create under the restrictions as 77707-989908070.

There's still the issue that we can't reference any values (because we can't assign them and because we can't use &), so we have to use an array literal (int[]){...}. We actually use this for the bitmask array above as well.

  1. Closing brackets

We can't use ']' or '}' to close either our arrays or functions. Luckily C has digraphs and trigraphs that work. :> will become ], while ??> will become }. This requires gcc to take the -trigraphs switch, as it ignores trigraphs by default (in violation of the standard).

  1. Bitwise operations

We can't use & to mask bits off of our index, nor can we use % to get there the old-fashioned way. Therefore we rely on implementation specific behaviour. In particular we shift our 32-bit integers far enough to the left to lose bits, then back to the right. For example to get the last 5 bits of our number we first shift it left 27 bits (leaving abcde00000...) then shift it back to the right by 27 bits (leaving ...00000abcde).

  1. Miscellaneous values

We need a few more literal values throughout the code - these are taken from Arnauld's JS answer, plus 27 (for the reason above) is added by me as 9+9+9.

3. Putting it together

Here is the description of the source with all of these changes together.

main(_){                // This is our main entry point
--_<88+80+88            // This subtracts 1 from the argument (_) and checks if it is less than 256
    ?                   // If it is less than 256 we 'continue'
printf(                 // first we call printf with...
    (int[:>){           // An integer array that will be interpreted as a string
    77707-989908070     // With the value we determined above, to represent "%c\0\xC5"
    ??>,                // This is a trigraph for }, just as the :> above is a digraph for ]
    ((int[:>){          // We immediately create another integer array
0xE8E8C79E^0xB0B0080,   // Each row is the bit-mask for 32 characters
0xC07E0870^0xE0000C00,
0xCC08099C^0xEE0C008E,
0xE8888989^0xCC00808,
0x9E088990^0x800C0000,
0x990C8888^0x080ECC00,
0xF9C7a088^0x080000C0,
0x9F8C78F8^0x900000??>
[_>>(0xC^0x9):>         // This is {arr}[_>>5] just in a roundabout way
>>(_<<9+9+9>>9+9+9))    // Similarly this is (...)>>(_&0x1F)
<<(70^89)>>(70^89)      // This is <<31>>31 or &1, to check the last bit
?_:' ')                 // If its 1, we print the character, otherwise we print a space
,main(_+9-7):0;         // We recurse, the :0 is the other branch of the if, it terminates execution
??>
  • Great job! Nice explanation too. (I'm not 100% but believe the header should read "C (gcc) -trigraphs") – Jonathan Allan Nov 21 at 22:20
  • 1
    It's up for debate. The code is not gcc specific, its not fully standards compliant code, but on my machine cc compiles it fine with no arguments. There's just no built-in compiler on TIO that conforms to the standard by default, if there were (or an older build of gcc) then the trigraphs would just generate warnings. – LambdaBeta Nov 22 at 0:32
  • Using g++ ?: extension, abuse bitwise shift modulo 32, 273 bytes – user202729 Nov 25 at 9:57
  • That's clever. I'm going to keep it as is however, as this version doesn't need the -trigraphs option on some C compilers, while ?: requires gcc which requires -trigraphs. – LambdaBeta Nov 26 at 15:17

brainfuck, 635 bytes

++++++++++++++++++++++++++++++++.>+.+.+.+.<...>++++.+.+.<...>++++.+.+.+.<...>++++.+.+.+.+.<...>++++.+.+.+....++++.+.+.<...>++++.<......>+++++++.+.+.+.+.+.<......>+++++++.<...>++++.<..>+++.<...>++++.<..>+++.<......>+++++++.<......>+++++++.<...>++++.<..>+++.<......>+++++++.+.<......>+++++++.<...>++++.<..>+++.<...>++++.<..>+++.+.+.<....>+++++.<..>+++.+.<..>+++.<...>++++.<..>+++.<......>+++++++.+.+.+.<......>+++++++.<...>++++.<..>+++.<...>++++.<..>+++.<......>+++++++.<...>++++.<..>+++.<...>++++.<..>+++.<......>+++++++.<.>++.+.+.+.<...>++++.+.+.<...>++++.+.+.+.<...>++++.+.+.+.+.<...>++++.+.+.+.<...>++++.+.+.<...>++++.+.+.+.+.<..>>-.

Try it online!

In response to finally being beaten by Javascript, I have golfed what I can out of this:

1 byte saved by having 32 in cell 0 and incrementing cell 1 (the only reason I initially had it the other way was because of a quick fix when OrjanJohansen pointed out I couldn't use ])

1 byte saved by decrementing a third cell (initially at 0) to generate 255 = -1

2 bytes saved by printing spaces between characters 31 and 36 without using <> but instead simply stopping at 32 to print from cell 0 when incrementing from 31 through 33.

brainfuck, 639 bytes

>++++++++++++++++++++++++++++++++.<+.+.+.+.>...<++++.+.+.>...<++++.+.+.+.>...<++++.+.+.+.+.>...<++++.+.+.>....<+++++.+.+.>...<++++.>......<+++++++.+.+.+.+.+.>......<+++++++.>...<++++.>..<+++.>...<++++.>..<+++.>......<+++++++.>......<+++++++.>...<++++.>..<+++.>......<+++++++.+.>......<+++++++.>...<++++.>..<+++.>...<++++.>..<+++.+.+.>....<+++++.>..<+++.+.>..<+++.>...<++++.>..<+++.>......<+++++++.+.+.+.>......<+++++++.>...<++++.>..<+++.>...<++++.>..<+++.>......<+++++++.>...<++++.>..<+++.>...<++++.>..<+++.>......<+++++++.>.<++.+.+.+.>...<++++.+.+.>...<++++.+.+.+.>...<++++.+.+.+.+.>...<++++.+.+.+.>...<++++.+.+.>...<++++.+.+.+.+.>..<+++.

Try it online!

First we generate the number 32. Then we just go through incrementing one cell and switching the printing between that cell and the one containing 32. Steadily increasing numbers are something Brainfuck does well.

It's nice to beat Javascript with Brainfuck, it doesn't happen often!

  • Sorry, but ] isn't a permitted character. Although you should still be able to fix that and beat the Javascript. :) – Ørjan Johansen Nov 22 at 5:10
  • @ØrjanJohansen fixed – Level River St Nov 22 at 5:16
  • Sorry, you lost Javascript. – user202729 Nov 25 at 16:51
  • @user202729 pretty good! still, I had Javascript beaten for 3 days. As I can't use loops because ] is not allowed, I think my BF answer is probably optimal now. – Level River St Nov 25 at 18:13

JavaScript (SpiderMonkey), 1918 1598 1487 1431 bytes

Saved 56 bytes thanks to @user202729

print(8<<98,7/7,9-7,7>>97,8>>97,8<<98,8<<98,8<<98,8,9,0xa,8<<98,8<<98,8<<98,0xe,0xf,7+9,8+9,8<<98,8<<98,8<<98,7+0xe,7+0xf,8+0xf,9+0xf,78^87,8<<98,8<<98,8<<98,77^80,70^88,70^89,8<<98,8<<98,8<<98,8<<98,9<<98,70^99,77>>97,8<<98,8<<98,8<<98,98-070,8<<98,8<<98,8<<98,8<<98,8<<98,8<<98,9^070,80^98,80^99,87^99,87^98,9^077,8<<98,8<<98,8<<98,8<<98,8<<98,8<<98,70-9,8<<98,8<<98,8<<98,7^70,8<<98,8<<98,9^77,8<<98,8<<98,8<<98,7^79,8<<98,8<<98,70^0xd,((8<<98)+' ').repeat(8^0xe)+(8^90),((8<<98)+' ').repeat(8^0xe)+89,8<<98,8<<98,8<<98,7^90,8<<98,8<<98,7+89,((8<<98)+' ').repeat(8^0xe)+(7|97),7+97,((8<<98)+' ').repeat(8^0xe)+(77|98),8<<98,8<<98,8<<98,80|99,8<<98,8<<98,8^0x7e,8<<98,8<<98,8<<98,0x7a,8<<98,8<<98,0x7d,0x7e,0x7f,8<<98,8<<98,8<<98,8<<98,7+0x7d,8<<98,8<<98,0x87,0x88,8<<98,8<<98,0x8b,8<<98,8<<98,8<<98,0x8f,8<<98,8<<98,7+0x8b,((8<<98)+' ').repeat(8^0xe)+0x99,0x9a,0x9b,0x9c,((8<<98)+' ').repeat(8^0xe)+(7+0x9c),8<<98,8<<98,8<<98,0xa7,8<<98,8<<98,0xaa,8<<98,8<<98,8<<98,0xae,8<<98,8<<98,78+99,((8<<98)+' ').repeat(8^0xe)+0xb8,8<<98,8<<98,8<<98,0xbc,8<<98,8<<98,0xbf,8<<98,8<<98,8<<98,97+98,8<<98,8<<98,99+99,((8<<98)+' ').repeat(8^0xe)+0xcd,8<<98,0xcf,0xd0,7+0xca,7+0xcb,8<<98,8<<98,8<<98,7+0xcf,0xd7,0xd8,8<<98,8<<98,8<<98,0xdc,0xdd,0xde,0xdf,8<<98,8<<98,8<<98,7+0xdc,7+0xdd,7+0xde,7+0xdf,0xe7,8<<98,8<<98,8<<98,0xeb,0xec,0xed,0xee,8<<98,8<<98,8<<98,7+0xeb,7+0xec,7+0xed,8<<98,8<<98,8<<98,0xf8,0xf9,0xfa,0xfb,0xfc,8<<98,8<<98,0xff)

Try it online!

How?

The fact that = is not allowed is a show-killer in JS. We can't do any variable assignment, and we also can't use any arrow function.

The above code is instead computing each number separately, using the allowed digits in either decimal, octal or hexadecimal (\$0\$, \$7\$, \$8\$, \$9\$ and 0xa to 0xf) and the following operators: +, -, /, |, ^, << and >>.

  1 = 7/7     |   50 = 80^98   |  136 = 0x88    |  216 = 0xd8
  2 = 9-7     |   51 = 80^99   |  139 = 0x8b    |  220 = 0xdc
  3 = 7>>97   |   52 = 87^99   |  143 = 0x8f    |  221 = 0xdd
  4 = 8>>97   |   53 = 87^98   |  146 = 7+0x8b  |  222 = 0xde
  8 = 8       |   54 = 9^077   |  153 = 0x99    |  223 = 0xdf
  9 = 9       |   61 = 70-9    |  154 = 0x9a    |  227 = 7+0xdc
 10 = 0xa     |   65 = 7^70    |  155 = 0x9b    |  228 = 7+0xdd
 14 = 0xe     |   68 = 9^77    |  156 = 0x9c    |  229 = 7+0xde
 15 = 0xf     |   72 = 7^79    |  163 = 7+0x9c  |  230 = 7+0xdf
 16 = 7+9     |   75 = 70^0xd  |  167 = 0xa7    |  231 = 0xe7
 17 = 8+9     |   82 = 8^90    |  170 = 0xaa    |  235 = 0xeb
 21 = 7+0xe   |   89 = 89      |  174 = 0xae    |  236 = 0xec
 22 = 7+0xf   |   93 = 7^90    |  177 = 78+99   |  237 = 0xed
 23 = 8+0xf   |   96 = 7+89    |  184 = 0xb8    |  238 = 0xee
 24 = 9+0xf   |  103 = 7|97    |  188 = 0xbc    |  242 = 7+0xeb
 25 = 78^87   |  104 = 7+97    |  191 = 0xbf    |  243 = 7+0xec
 29 = 77^80   |  111 = 77|98   |  195 = 97+98   |  244 = 7+0xed
 30 = 70^88   |  115 = 80|99   |  198 = 99+99   |  248 = 0xf8
 31 = 70^89   |  118 = 8^0x7e  |  205 = 0xcd    |  249 = 0xf9
 32 = 8<<98   |  122 = 0x7a    |  207 = 0xcf    |  250 = 0xfa
 36 = 9<<98   |  125 = 0x7d    |  208 = 0xd0    |  251 = 0xfb
 37 = 70^99   |  126 = 0x7e    |  209 = 7+0xca  |  252 = 0xfc
 38 = 77>>97  |  127 = 0x7f    |  210 = 7+0xcb  |  255 = 0xff
 42 = 98-070  |  132 = 7+0x7d  |  214 = 7+0xcf  |
 49 = 9^070   |  135 = 0x87    |  215 = 0xd7    |

Note: Bitwise shifts are processed modulo \$32\$. This is explicitly stated in the ECMAScript specification:

Let shiftCount be the result of masking out all but the least significant 5 bits of rnum, that is, compute rnum & 0x1F.

For instance, 8<<98 really does 8<<2 (which is \$32\$).

  • 32 as 8<<9-7 saves a byte for each 32. – TFeld Nov 21 at 14:29
  • 1
    @TFeld Actually, I was adding shifts to my solver, which has just found 32 = 8<<98 (because \$98 \equiv 2 \pmod{32}\$). A few more expressions can be shortened this way. Still working on it. – Arnauld Nov 21 at 14:37
  • 3
    "show-killer" or "fun-maker"? – Jonathan Allan Nov 21 at 16:11
  • 2
    @JonathanAllan ;-) The latter comes out of the former! – Arnauld Nov 21 at 16:18
  • Sorry if I'm being stupid, but why are you linking to an old version of SpiderMonkey? – Solomon Ucko Nov 21 at 19:28

Haskell, 623 617 614 594 360 342 bytes

Edit: -234 bytes thanks to @Lynn by finding a pattern encoding as a string. -18 bytes thanks to @Ørjan Johansen.

map(\i->cycle(8+8+8+8:filter(\_->" XXXX   XXX   XXXX   XXXXX   XXX    XXX   X      XXXXXX      X   X  X   X  X      X      X   X  X      XX      X   X  X   X  XXX    X  XX  X   X  X      XXXX      X   X  X   X  X      X   X  X   X  X      X XXXX   XXX   XXXX   XXXXX   XXXX   XXX   XXXXX  X"!!i>' ')(pure i))!!9)(take(0xf8+8)(iterate(9-8+)0))

Try it online!

How it works

map(\i->    )                   -- map the lambda over the
        (take(0xf8+8)           -- first 256 elements of
           (iterate(9-8+)0))    -- the list [0,1,2,....]

                                -- the lambda is:

    cycle                       -- make an infinite list by repeating the list
      8+8+8+8:                  -- wih element 32 followed by
                  pure i        -- the singleton list with 'i'
       filter                   -- but keep 'i' only if
          \_->" XXXX..."!!i>' ' -- the pattern has an 'X' at index 'i', else
                                -- remove it to make an empty list
                                -- i.e. the cycled list is, if the pattern is
                                -- a space: [32,32,32,32,32,32,32,32,32,32,...]
                                -- an 'X':  [32, i,32, i,32, i,32, i,32, i,...]
                                --                                       ^
                                --                        9th element ---/ 
                      !!9       -- pick the 9th element which is the result
                                -- of the lambda
  • 3
    You can index (id:pure(\_->8+8+8+8)) by until((||" XXXX XXX XXXX XXXXX XXX XXX X XXXXXX X X X X X X X X X XX X X X X XXX X XX X X X XXXX X X X X X X X X X X X XXXX XXX XXXX XXXXX XXXX XXX XXXXX X"!!i<'X').(<1))pred 1 and save a bunch of bytes. – Lynn Nov 21 at 23:02
  • 1
    342 bytes with filter instead of until to branch (and cycle to avoid an extra ++pure(...)). – Ørjan Johansen Nov 22 at 7:21

Brain-Flak -r, 4190 4188 bytes

(()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((())())())())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())())())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())())())())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())())())())())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())())())())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())())())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())()<((((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))))))>()()()()()())())())())())())()<((((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))))))>()()()()()())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())()<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())()<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()())()<((((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))))))>()()()()()())()<((((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))))))>()()()()()())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())()<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()())()<((((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))))))>()()()()()())())()<((((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))))))>()()()()()())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())()<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())()<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()())())())()<((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))))>()()()())()<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()())())()<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())()<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()())()<((((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))))))>()()()()()())())())())()<((((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))))))>()()()()()())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())()<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())()<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()())()<((((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))))))>()()()()()())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())()<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())()<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()())()<((((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))))))>()()()()()())()<(()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())>())())())())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())())())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())())())())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())())())())())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())())())())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())())())()<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()())())())())())()<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()())

Try it online!

This one is a little bit difficult for Brain-flak since we can't use ] or }. Meaning the only useful characters are <>().

Here's a Haskell program that helped me write this

It just counts up skipping where spaces need to be and pushing those individually.

  • Is this provably optimal? – user202729 Nov 23 at 10:38
  • @user202729 I suspect not. It could be though. There is not a ton of wiggle room but I am far from being able to prove that it is optimal. Although since we don't have {} a computer search could actually find the optimal in finite time. – Post Left Garf Hunter Nov 23 at 13:30
  • I end up writing a program that generates the optimal solution, however it's a bit slower than what I expect.i Still fast enough to run, though. – user202729 Nov 23 at 17:13
  • @user202729 Well it wasn't optimal. I found a shorter one. – Post Left Garf Hunter Nov 24 at 0:23

JavaScript (SpiderMonkey), 1001 919 789 441 bytes

print(/u/.exec().map.call('0777700077700077770007777700077700007770007000000777777000000700070070007007000000700000070007007000000770000007000700700070077700007007700700070070000007777000000700070070007007000000700070070007007000000707777000777000777700077777000777700077700077777007',''.repeat.bind(Number)).map(/u/.exec().find.bind(/()/.exec().fill(Number.bind(0,88-070)).fill(/u/.exec().fill,!0),''.indexOf)).map(Map.call.bind(Map.call)))

Try it online!

Finally beats BF!!!

General idea

Convert each character of the long string string to its index or 32, depends on the value.

Array.prototype.map? How to get array

Brute force to see which objects are accessible by accessing object properties (because ] is not allowed, so only properties with name matching an identifier is accessible).

RegExp.prototype.exec returns an array-like object when there is a match. When no argument is provided, the argument defaults to undefined, so /u/.exec() matches and return an array.

Get 2 arbitrary distinct values on 2 different characters

We want to have (x,y)=>x=='0'?32:y, but we can't use =.

Instead, we're going to do

new Array(a)
    .map(x=>x=='0'?()=>32:function()this)
    .map((x,y,z)=>x.call(y,z))

We can map the string over some function, but => is not allowed, so only a few functions can be used. It may have bound this and some bound arguments (so it has the form (x,y,z)=>pre_filled_function.call(pre,filled,args,etc,x,y,z))

After considering a list of functions (repeat exec bind create map indexOf replace fill find reduce filter findIndex call bind apply), I decide that the following functions will be used (after considering all other combinations)

  • repeat: number -> different strings.
  • find: thisArg -> first element in array match.

The general idea would be:

[].map.call('07070707...', (x,y,z)=>[elem1,elem2].find(somefunction,x,y,z)

where somefunction considers the this argument (x) and the first argument (elem1 or elem2) and return whether it matches.

The last arrow function is rewritten to [].find.bind([elem1,elem2],somefunction).

Array literal

We can use regex exec to get an array, and fill it with different values. For example /()/.exec() returns a length-2 array, then we can fill it as we need.

Which somefunction do we need?

We need one that returns a truthy/falsy value depends on this (which is 1 of 2 functions we're going to return) and first argument (must be a string or array).

For that, I used indexOf -- it returns falsy value iff the first argument is a prefix of the this argument.

Represent the function literals

  • 1
    stumbles off end of explanation and winds up hanging off a branch – Ørjan Johansen Nov 27 at 3:48

TI-Basic (83 series), 578 bytes

8XFact8-ΔTbl
seq(X and XX≤8+8 or 8≤X and X≤Xmax or 7+7≤X and X<9+9 or 7+7+7≤X and X<8π or 9π<X and X<πXmax or 9 nCr 7≤X and X+X<77 or X=7²-7 or 7²≤X and X≤7*9-9 or X=70-9 or X=8²+ΔTbl or X=78-Xmax or X=9*8 or X=89-7-7 or X=89-7 or X=89 or X=900-807 or X=88+8 or 809-707<X and X≤97+77-70 or 9X=999 or 8X=990-70 or X=888-770 or X=899-777 or 8*7+77-8≤X and X+X<Ans or 7²X/77=77+7 or 999+77<8X and 7X<970-9-7 or 8²X=8888+8 or X+X=99+99+88 or 7X=9099-8077 or 9+8≤X/9 and X<997-770-70 or X=99+8² or X=87+80 or X=80+90 or X=87+87 or X=87+90 or X=87+97 or X=98+90 or X=999-808 or X=97+98 or X=99+99 or X=99+99+7 or 9²8<πX and X+X+X≤70*9 or 70π-π-π<Xand X+X+X≤9²8 or 70π<X and X<70π+π or 997-770≤X and X+X+X≤99*7 or 77+79+79≤X and X+8+9≤Ans or 77π<X and X<Ans-Xmax or 7*8*9-8≤X+X and X+X≤7*8*9 or X=Ans,X,0,Ans
8XFact+Ansseq(X,X,⁻8XFact,70π+π

TI-Basic has its own very special "code-page" with weird design choices like moving the space character over to 0x29 so that 0x20 can be the randM( command.

It's tricky to figure out how to get TI-Basic to output the right kind of object. Strings wouldn't work for multiple reasons: there's no way to reference a token without using the token, and also we're not allowed the " character. We can't just write a list, because { and } are forbidden. We are allowed the [ and ] characters for matrices, but a 1 by 256 matrix doesn't work, since matrices are allowed at most 99 rows and columns. We can't use to assign to variables, and we can't get at the list variables ʟ or L₁ through L₆ anyway.

So here, we write down a complicated logical formula with inequalities that says when a character is one of the ones we want to output. Then we use the seq( command to generate a list with 1 in those positions and 0 elsewhere. From there, another seq( command and some arithmetic finishes the job.

That was the exciting part; the rest is golfing the constants and I probably haven't done that as much as possible. One of the tricks I use is that by default, Xmax is 10, XFact is 4, and ΔTbl is 1.

  • While a 1*256 matrix won't work, can you make something like a 3*99 matrix and use div/mod to index the matrix? – user202729 Nov 24 at 13:44
  • Oh, we also can't index things, because ( is forbidden. – Misha Lavrov Nov 24 at 16:25
  • Is there conditional expression (if a then b else c) or floor or mod? Number precision is ~15 decimal digits right? – user202729 Nov 24 at 16:34
  • All of these exist. We just can't get at a matrix entry with [A](I,J), and from what I understand you want to do something like [A](int(I/99),I-99int(I/99)) to read out all the elements of the matrix [A] - we also can't do that. (By the way, ) is also forbidden. Fortunately, we don't have to close ending parentheses, but it limits how we can use many commands.) – Misha Lavrov Nov 24 at 16:38
  • I am thinking about using a number to encode an array, similar to a bitmask. Like (123456789>>X)&1 in Python. – user202729 Nov 24 at 16:41

Brain-Flak -r, 3894 bytes

(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())<((())((()())()))>)))(((((((()()()()()()()())(()()()()()()()()())(()()()()()()()()()())()()()()())))<((((((((()()()()()()()()()()()()()())((((((((((()()()()()()()()()()()()()()())((()()()()()()()()()()()()()()()())()))))<((((((((((((()()()()()()()()()()()()()()()()()()()()())())())())())()()()()()()())))<((((((((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()())())())()))))()()()())())())>)))()()()()()()()()()())>))))))()()())())())())())())<((((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))))))>()()()()()()())>)))())<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()()())<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()()())<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()()())<((((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))))))>()()()()()()())<((((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))))))>()()()()()()())<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()()())<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()()())<((((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))))))>()()()()()()())())<((((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))))))>()()()()()()())<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()()())<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()()())<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()()())<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()()())())())<((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))))>()()()()())<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()()())())<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()()())<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()()())<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()()())<((((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))))))>()()()()()()())())())())<((((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))))))>()()()()()()())<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()()())<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()()())<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()()())<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()()())<((((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))))))>()()()()()()())<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()()())<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()()())<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()()())<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()()())<((((((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))))))>()()()()()()())<(()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())>()())())())())<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()()())())())<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()()())())())())<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()()())())())())())<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()()())())())())<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()()())())())<(((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()())))>()()()())())())())())<((()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()))>()()())

Try it online!

I wrote a program to generate the optimal Brain-Flak program for any output. Assume that:

  • <> is not used
  • My program is correct

, then this solution is optimal.

However, I was a bit lazy and implement a solution that is not very hard to come up with, and it ends up running in 1m13s (takes time \$O(n^5)\$ or so). I may look for more efficient solution later.

Python 2, 162 157 bytes

Warning: Unprintable characters ahead!

print map(lambda(i,x):(x>'0'and i-0xe0/7)+0xe0/7,enumerate(bin(reduce(lambda x,y:(x<<0xd-7)-x+y,bytearray('7?QcZ;+BqiQJUS!?B0W![<LBU7X!frQd(SQdB\0')))))

Try it online!

Based on TFeld's existing answer, but with a few changes:

A bytearray is similar to a str that it's iterable, however, iterating it gives integers, not characters. We can use it to encode a base-N literal and reduce(lambda x,y: x*N+y, my_bytearray) to decode it.

Because Python 2 files don't have an encoding by default, only characters in ASCII (0..127) can be used. Null byte, newlines, backslashes and quotes take 1 more byte.

Also, it's not possible to use all bases.

I wrote a program to find the shortest representation of n, given those restrictions.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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