9
\$\begingroup\$

Input:

Any Brainfuck program. This includes brainfuck programs with comments such as +++COMMENT[>+++<-]..

Output:

A program in one of the below languages that produces the same output as the Brainfuck program on all inputs. It should produce the same output exactly as the interepreter on this website There are no or performance restrictions on the output program; the outputted program doesn't need to be optimized in any way. In other words, the quality of the outputted program does not affect score, only the translation program. To clarify: you may write your answer in any language that is normally valid for answers on PCG. The restriction on output languages is only for the outputted program.

The outputted program only receives the same input that would be received by the Brainfuck program. The outputted program does not receive the Brainfuck program as input.

Valid Output Languages

  • C#
  • C++
  • C
  • Java 8
  • Javascript ES6 (it is both okay to receive all of stdin in a single prompt, or multiple prompts per character)
  • Perl
  • Python 2.7
  • Python 3.4.2
  • Ruby

Fine Print

You may write a program or function which takes the Brainfuck program as a String argument or on STDIN or closest alternative, and which returns the output as a String or printing it to STDOUT (or closest alternative). You may optionally include a single trailing newline in the output.

Additionally, standard loopholes which are no longer funny are banned. You may not use external libraries or external data files, the code must be self contained.

This is , shortest program wins.

\$\endgroup\$
9
  • 4
    \$\begingroup\$ It's not a dup, as a compiler is not an interpreter \$\endgroup\$
    – edc65
    May 12, 2015 at 21:39
  • 3
    \$\begingroup\$ Can you clarify the behavior of the linked interpreter? What is the max number of memory cells? How is overflow of cell values handled? \$\endgroup\$
    – nderscore
    May 12, 2015 at 22:27
  • 3
    \$\begingroup\$ @nderscore The linked interpreter uses signed integers that wrap around from -128 to +127. However, the values are effectively cast to 2-byte unsigned ints before being output as characters; so -1 => chr(65535) (). Personally, I would prefer output in the form of 1-byte (ASCII) characters (in part because that's what my solution uses). The tape is circular, with 32768 cells. durron597, are these specs what you intended? \$\endgroup\$
    – DLosc
    May 13, 2015 at 6:25
  • 2
    \$\begingroup\$ Any reason not to open this up to all output languages? \$\endgroup\$
    – Adám
    Jul 2, 2019 at 13:34
  • 2
    \$\begingroup\$ I agree with Adám - there are tons of non-golfing languages out there that you're keeping from participating here. Also, why those very specific versions of Python and Java? \$\endgroup\$
    – user
    Aug 21, 2020 at 13:28

8 Answers 8

5
\$\begingroup\$

K, 143 129 113 bytes

1!"}int a[99];int*p=a;main(){",,/{("p++;";"p--;";"*p++;";"*p--;";"*p=getchar();if(*p<0)*p=0;";"putchar(*p);";"while(*p){";"}";"")"><+-,.[]"?x}'

This is an extremely straightforward approach which generates C source code by emitting a preamble, a C snippet for each BF command and then a postscript. Non-BF characters are translated into empty strings in the concatenated output.

The translation into C is as follows:

  • preamble: int a[99];int*p=a;main(){
  • >: p++;
  • <: p--;
  • +: *p++;
  • -: *p--;
  • ,: *p=getchar();if(*p<0)*p=0;
  • .: putchar(*p);
  • [: while(*p){
  • ]: }
  • postscript: }

I suspect that there is room for improvement here by using more mangled abuses of C or compressing the C fragments.

The K part of the program by itself would look like the following, where c is the C translations of each BF instruction and p is the preamble/postscript:

1!p,,/{c"><+-,.[]"?x}'

Using the venerable BF string reverser program >,[>,]<[.<] as my test case I generate code which looks like the following after a bit of whitespace for readability:

int a[99];
int*p=a;

main(){
    p++;
    *p=getchar();if(*p<0)*p=0;
    while(*p){
        p++;
        *p=getchar();if(*p<0)*p=0;
    }
    p--;
    while(*p){
        putchar(*p);
        p--;
    }
}

edit:

A few tweaks. Firstly, more compliant tape declaration as suggested by alexander-brett. The int part can be left off:

int a[99]; -> a[1<<15]; (-1 byte)

Also, it seems that EOF behavior in BF can return 0, -1 or cause no change as a result of ,. EOF=-1 seems to be what other solutions are going with, so for the sake of uniformity I will do the same:

*p=getchar();if(*p<0)*p=0; -> *p=getchar(); (-13 bytes)

Note that this means my string reverser program will choke if you simply cat it a file ending in EOF(!), but as above it seems to be fair.

The new complete 129 byte solution:

1!"}a[1<<15];int*p=a;main(){",,/{("p++;";"p--;";"*p++;";"*p--;";"*p=getchar();";"putchar(*p);";"while(*p){";"}";"")"><+-,.[]"?x}'

edit 2, much, much later:

I randomly stumbled upon this old answer and, being older and wiser, realized there are several ways to make this shorter:

  • exploit the fact that it's completely syntactically valid C to include semicolons after every fragment instead of just those who need them, and thus remove them from the lookup table entries.
  • use the k5/k6 or oK dialects, which have overloads for \ and / which split a string apart on a character or join a list of strings with a character, respectively, to use a more compact representation of the lookup table and accomplish the above.
  • take advantage of the fact that find (dyadic ?) in the above dialects naturally conforms to a listy right argument, and thus does not need an explicit lambda + each

The one downside is that in these dialects there is no "rotate" primitive, so we have to add the "}" suffix in a less elegant manner. The overall structure of our solution:

1!     p, ,/{c"><+-,.[]"?x}'   / old
,[;"}"]p,";"/c"><+-,.[]"?      / new

The complete (and now totally points-free!) solution:

,[;"}"]"a[1<<15];int*p=a;main(){",";"/("|"\"p++|p--|*p++|*p--|*p=getchar()|putchar(*p)|while(*p){|}|")"><+-,.[]"?

Which shaves us down to 113 bytes.

\$\endgroup\$
5
  • \$\begingroup\$ Shouldn't that be a[30000]? \$\endgroup\$
    – alyx-brett
    May 13, 2015 at 6:51
  • \$\begingroup\$ That would be more compliant. a[1<<15] is closer to the interpreter above, and I can leave off "int" as C variables are implicitly ints. It also looks like my "EOF=0" handling is more than is strictly necessary, even if it's a common assumption. \$\endgroup\$
    – JohnE
    May 13, 2015 at 14:02
  • 1
    \$\begingroup\$ DARN! You beat me to K. :) \$\endgroup\$ May 29, 2015 at 19:19
  • 1
    \$\begingroup\$ Unary postfix binds first over unary prefix, so *p++ increments p rather than *p. ++*p works as intended. \$\endgroup\$
    – Bubbler
    Aug 21, 2020 at 0:40
  • \$\begingroup\$ Suggest *p*=read(0,p,1); instead of *p=getchar();if(*p<0)*p=0; \$\endgroup\$
    – ceilingcat
    Aug 21, 2020 at 7:17
4
\$\begingroup\$

Javascript (ES7 Draft), 170 bytes

Function which compiles BF source code into Javascript. The resulting code accepts input via prompt() and outputs via alert(), both one character at a time.

f=x=>'x=[i=0];'+[for(y of x)'z=x[i]|=0,x[i]'+'0++0--0,i++0,i--0,alert(String.fromCharCode(z))0=prompt().charCodeAt()0;for(;x[i];){x0}x'.split(0)['+-><.,[]'.indexOf(y)+1]]

The result is composed of:

Preamble: x=[i=0]; - Initializes x as an object to store memory cells and i as 0 for the initial index.

Each command is prefixed with: z=x[i]|=0,x[i] - Forces undefined memory cells to 0, starts all commands with x[i] to reduce repetition in the translation map. Stores value at current index in z.

Each command is also seperated by , commas due to implicit casting of the array to a string.

Command translation map:

  • (unknown) => empty string
  • + => ++ - increment value at x[i]
  • - => -- - decrement value at x[i]
  • > => ,i++ - increment index pointer i
  • < => ,i-- - decrement index pointer i
  • . => ,alert(String.fromCharCode(z)) - alert character from value at x[i]
  • , => =prompt().charCodeAt() - store converted character code from prompt at x[i]
  • [ => ;for(;x[i];){x - Loop while value at x[i] is truthy (non-zero).
  • ] => }x - End loop. Unused x appended to prevent errors from commas.
\$\endgroup\$
4
\$\begingroup\$

Python 2, 250 244 bytes

def B(b):
 I=0;print"from ctypes import*;R,p,c=[0]*9999,0,CDLL('libc.so.6')"
 for c in b:
     try:print' '*I+'p+=1|p-=1|R[p]+=1|R[p]-=1|c.putchar(R[p])|R[p]=c.getchar()|while R[p]!=0:|'.split('|')['><+-.,[]'.index(c)];I+=']&['.index(c)-1
     except:0

#first indentation level=space, 2nd indentation level=tab

(thks to @undergroundmonorail for helping me save 4 extra bytes)

The B function takes bf code as parameter and generates... a Python script.

Brainfuck's "tape" is seen a an array called R, which owns 32768 9999 items, and the pointer is stored in a variable called p.

The lack of a native equivalent to C's getchar function in python forced me to load it using ctypes at runtime, which makes the generated script unusable on Windows (untested, I guess that a Windows version should load mscvrt.dll instead of libc.so.6)

Example

The infamous 'hello world':

B('++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.')

Generates the following script:

from ctypes import*;R,p,c=[0]*9999,0,CDLL('libc.so.6')
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
while R[p]!=0:
 p+=1
 R[p]+=1
 R[p]+=1
 R[p]+=1
 R[p]+=1
 R[p]+=1
 R[p]+=1
 R[p]+=1
 p+=1
 R[p]+=1
 R[p]+=1
 R[p]+=1
 R[p]+=1
 R[p]+=1
 R[p]+=1
 R[p]+=1
 R[p]+=1
 R[p]+=1
 R[p]+=1
 p+=1
 R[p]+=1
 R[p]+=1
 R[p]+=1
 p+=1
 R[p]+=1
 p-=1
 p-=1
 p-=1
 p-=1
 R[p]-=1

p+=1
R[p]+=1
R[p]+=1
c.putchar(R[p])
p+=1
R[p]+=1
c.putchar(R[p])
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
c.putchar(R[p])
c.putchar(R[p])
R[p]+=1
R[p]+=1
R[p]+=1
c.putchar(R[p])
p+=1
R[p]+=1
R[p]+=1
c.putchar(R[p])
p-=1
p-=1
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
R[p]+=1
c.putchar(R[p])
p+=1
c.putchar(R[p])
R[p]+=1
R[p]+=1
R[p]+=1
c.putchar(R[p])
R[p]-=1
R[p]-=1
R[p]-=1
R[p]-=1
R[p]-=1
R[p]-=1
c.putchar(R[p])
R[p]-=1
R[p]-=1
R[p]-=1
R[p]-=1
R[p]-=1
R[p]-=1
R[p]-=1
R[p]-=1
c.putchar(R[p])
p+=1
R[p]+=1
c.putchar(R[p])
p+=1
c.putchar(R[p])
\$\endgroup\$
3
  • \$\begingroup\$ Unless I'm mistaken, the length of R is 0xfff=4095, not 32768. Also you can save some bytes by changing the last line to except:0. 0 is a no-op and 3 bytes shorter than pass. \$\endgroup\$ May 28, 2015 at 14:11
  • \$\begingroup\$ @undergroundmonorail en.wikipedia.org/wiki/Brainfuck#Array_size \$\endgroup\$
    – Kade
    May 29, 2015 at 1:49
  • \$\begingroup\$ You can save a few bytes by replacing from ctypes import* with from msvcrt import* and using just putchar instead of c.putchar. \$\endgroup\$ Jul 16, 2017 at 16:19
3
\$\begingroup\$

Common Lisp & JavaScript - 425 bytes

N.B. I am using the Parenscript library, so this is just for the fun.

(defun b(i &aux(s(coerce i'list)))(labels((c()(do(r x)((or x(not s))(reverse r))(push(case(pop s)(#\>`(incf p))(#\<`(decf p))(#\+`(setf(aref a p)(1+#1=(or(aref a p)0))))(#\-`(setf(aref a p)(1- #1#)))(#\.`((ps:@ console log)((ps:@ *String from-char-code)#1#)))(#\,`(setf(aref a p)((ps:@(prompt)char-code-at)0)))(#\[`(loop until(= 0 #1#)do ,@(c))))(#\](setf x t)(go /))(t(go /)))r)/)))(ps:ps*`(let((a(make-array))(p 0)),@(c)))))

Ungolfed

(defun bf(i)
  (let ((s (coerce i'list)))
    (labels((lbf ()
              (do(r x)((or x(not s))(reverse r))
                      (push (case (pop s)
                              (#\> `(incf p))
                              (#\< `(decf p))
                              (#\+ `(setf(aref a p)(1+(or (aref a p)0))))
                              (#\- `(setf(aref a p)(1-(or (aref a p)0))))
                              (#\. `((ps:@ console log)((ps:@ *String from-char-code) (or(aref a p)0))))
                              (#\, `(setf(aref a p) ((ps:@ (prompt) char-code-at) 0)))
                              (#\[ `(loop until(= 0(or(aref a p)0))do ,@(lbf)))
                              (#\] (setf x t) (go /))
                              (t (go /)))
                            r)/)))
      `(let ((a (make-array))
             (p 0))
         ,@(lbf)))))

Explanations

  • Convert input string as list of characters s
  • The recursive function lbf pop elements from s and build a local list of expressions r
  • Whenever we encounter a [ character, the function recurse in order to create a nested block of instructions
  • Whenever we encounter a ] character, the function exits, returning to one higher level of invocation. Note that when returning from the function, the variable s has been modified to hold the rest of the characters to be processed, thanks to pop.
  • The whole S-expr being built is expressed in a sub-language of Common Lisp that can be converted to Javascript thanks to Parenscript.

Optimized version

I made a slightly optimized version that is too long to post here, with the following changes:

  • Parsing only produces an AST containing the following symbols: print, read, left, right, inc, dec, bracketed (nested tree) and brainfuck (root tree).

  • The AST is analyzed to group all increment and decrement operations, as well as move operations, in order to build (add x) and (move y) terms.

  • Finally, the AST is converted into Parenscript code.

  • That code is emitted as a Javascript string

The resulting Javascript for Hello World is:

(function () {
   var a = new Array();
   var p = 0;
   a[p] = (a[p] || 0) + 10;
   while (0 !== (a[p] || 0)) {
       ++p;
       a[p] = (a[p] || 0) + 7;
       ++p;
       a[p] = (a[p] || 0) + 10;
       ++p;
       a[p] = (a[p] || 0) + 3;
       ++p;
       a[p] = (a[p] || 0) + 1;
       p += -4;
       a[p] = (a[p] || 0) + -1;
   };
   ++p;
   a[p] = (a[p] || 0) + 2;
   console.log(String.fromCharCode(a[p] || 0));
   ++p;
   a[p] = (a[p] || 0) + 1;
   console.log(String.fromCharCode(a[p] || 0));
   a[p] = (a[p] || 0) + 7;
   console.log(String.fromCharCode(a[p] || 0));
   console.log(String.fromCharCode(a[p] || 0));
   a[p] = (a[p] || 0) + 3;
   console.log(String.fromCharCode(a[p] || 0));
   ++p;
   a[p] = (a[p] || 0) + 2;
   console.log(String.fromCharCode(a[p] || 0));
   p += -2;
   a[p] = (a[p] || 0) + 15;
   console.log(String.fromCharCode(a[p] || 0));
   ++p;
   console.log(String.fromCharCode(a[p] || 0));
   a[p] = (a[p] || 0) + 3;
   console.log(String.fromCharCode(a[p] || 0));
   a[p] = (a[p] || 0) + -6;
   console.log(String.fromCharCode(a[p] || 0));
   a[p] = (a[p] || 0) + -8;
   console.log(String.fromCharCode(a[p] || 0));
   ++p;
   a[p] = (a[p] || 0) + 1;
   console.log(String.fromCharCode(a[p] || 0));
   ++p;
   return console.log(String.fromCharCode(a[p] || 0));
})();
\$\endgroup\$
3
\$\begingroup\$

QuadR, 106 100 99 bytes

Edit: finally below 100 bytes! -1 thanks to ceilingcat (⌈,)

Creates C code.

^
>
<
[+-]
\.
,
\[
]|$
a[1<<15];*p=a;main(){
p++;
p--;
&&*p;
putchar(*p);
read(0,p,1);
while(*p){
}

Try it online!

The first nine lines are PCRE regexes. Matches throughout the input are replaced with the corresponding string from the last 9 lines. The only noteworthy "hacks" are transpiling [+-] to &&*p; where & means the matched plus/minus symbol, and combining end-of-loop with end-of-main through mapping ]|$ to }

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

Perl, 127 120B + 2

%h=qw#> ++p;
< --p;
+ ++*p;
- --*p;
. putchar(*p);
, *p=getchar();
[ while(*p){
] }#;say"a[1<<15],*p=a;main(){@h{/./g}}"

The magic happens in @h{/./g}: /./g splits the input into characters, @h{} is a hash slice, and the "" interpolation joins hash elements using a space (by default). The target is C using exactly the spec on the Brainfuck website. 2 point penalty for -0n: run with

perl -M5.10.0 -0n scratch.pl > test.c < input.bf && gcc -ansi test.c && ./a.out

7B saving thanks to CL- and the prevailing opinion on variable declarations.

\$\endgroup\$
3
  • \$\begingroup\$ It looks like you can shorten the C preamble from main(){int a[1<<15];int*p=a; to a[1<<15],*p=a;main(){ for a 7 byte saving. This also guarantees that each element of a will be initialised to 0. \$\endgroup\$
    – CL-
    May 14, 2015 at 16:58
  • \$\begingroup\$ @CL- how do I compile that? gcc on OSX errors if I don't put a type in \$\endgroup\$
    – alyx-brett
    May 14, 2015 at 17:11
  • \$\begingroup\$ You'll see a warning, but it should still compile fine. \$\endgroup\$
    – JohnE
    May 15, 2015 at 13:48
2
\$\begingroup\$

rs, 214 bytes

Outputs Ruby 1.9 code.

[^+\-[\]<>.,]/
\[/while tape[i
\]/end;
\[i/[i] != 0 do 
\./print tape[i].chr;
if !defined?tape then require "io\x2Fconsole";tape=[0]*9999;i=0;end;
\+/tape[i]+=1;
-/tape[i]-=1;
</i+=1;
>/i-=1;
,/tape[i]=STDIN.getch;

Try it here!

Sample runs

Hello, world!

Input:

++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.

Output:

if !defined?tape then require "io\x2Fconsole";tape=[0]*9999;i=0;end;tape[i]+=1;tape[i]+=1;tape[i]+=1;tape[i]+=1;tape[i]+=1;tape[i]+=1;tape[i]+=1;tape[i]+=1;while tape[i] != 0 do i-=1;tape[i]+=1;tape[i]+=1;tape[i]+=1;tape[i]+=1;while tape[i] != 0 do i-=1;tape[i]+=1;tape[i]+=1;i-=1;tape[i]+=1;tape[i]+=1;tape[i]+=1;i-=1;tape[i]+=1;tape[i]+=1;tape[i]+=1;i-=1;tape[i]+=1;i+=1;i+=1;i+=1;i+=1;tape[i]-=1;end;i-=1;tape[i]+=1;i-=1;tape[i]+=1;i-=1;tape[i]-=1;i-=1;i-=1;tape[i]+=1;while tape[i] != 0 do i+=1;end;i+=1;tape[i]-=1;end;i-=1;i-=1;print tape[i].chr;i-=1;tape[i]-=1;tape[i]-=1;tape[i]-=1;print tape[i].chr;tape[i]+=1;tape[i]+=1;tape[i]+=1;tape[i]+=1;tape[i]+=1;tape[i]+=1;tape[i]+=1;print tape[i].chr;print tape[i].chr;tape[i]+=1;tape[i]+=1;tape[i]+=1;print tape[i].chr;i-=1;i-=1;print tape[i].chr;i+=1;tape[i]-=1;print tape[i].chr;i+=1;print tape[i].chr;tape[i]+=1;tape[i]+=1;tape[i]+=1;print tape[i].chr;tape[i]-=1;tape[i]-=1;tape[i]-=1;tape[i]-=1;tape[i]-=1;tape[i]-=1;print tape[i].chr;tape[i]-=1;tape[i]-=1;tape[i]-=1;tape[i]-=1;tape[i]-=1;tape[i]-=1;tape[i]-=1;tape[i]-=1;print tape[i].chr;i-=1;i-=1;tape[i]+=1;print tape[i].chr;i-=1;tape[i]+=1;tape[i]+=1;print tape[i].chr;

Mandelbrot

Input:

      A mandelbrot set fractal viewer in brainf*** written by Erik Bosman
+++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[[
>>>>>>>>>]+[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-]>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+
<<<<<<<+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>>+>>>>>>>>>>>>>>>>>>>>>>>>>>
>+<<<<<<<<<<<<<<<<<[<<<<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<<<<<<]<+<<<<<<
<<<]>>>>>>>>-<<<<<[-]+<<<]+>>>>>>>>[-<<<<<<<<->>>>>>>>]+<<<<<<<<[->>>>>>>>->[>>>
>>>[->>+<<]>>>]<<<<<<<<<[>[-]<->>>>>>>>[-<<<<<<<<+>[<->-<<+>>]<[->+<]>>>>>>>>]<<
<<<<<[->>>>>>>+<<<<<<<]<+<<<<<<<<<]>+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>
+>>>>>>>>>>>>>>>>>>>>>>>>>>>+<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>>[-<<<<<<->>>>>>]+<
<<<<<[->>>>>>->>[-<<<<<<<<+>>>>>>>>]<<<<<<<<[->>>>>>>>+<<<<<<<<<<<<<<<<<[<<<<<<<
<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>>>>>[-<<<<<<<<->>>>>>>>]+<<<<<<<<[->>>>>>>>
-<<[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>
>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>[-]<<<++++
+[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<<
<<<<<]]>>>]

Output (I'm glad it isn't scored!) is available on Pastebin because it was too long to put here!

\$\endgroup\$
1
  • \$\begingroup\$ Yes! A ruby transpiler! \$\endgroup\$
    – Razetime
    Aug 21, 2020 at 2:29
2
\$\begingroup\$

Javascript (ES6), 202 196 192 bytes

Outputs C code. Tested with Node.js 14.7.0 and GCC 10.1.0.

Try it online

f=i=>"a[99];main(){int*p=a;"+Array.prototype.map.call(i,x=>({">":"p++","<":"p--","+":"++*p","-":"--*p","[":"while(*p){","]":"}",",":"read(0,p,1)||(*p=0)",".":"putchar(*p)"})[x]).join(";")+"}";

The only clever thing here is using Array.map on a string rather than an array. I expected this to be golfier than it was; the 24 characters for Array.prototype.map.call were brutal.

I copied some of the C code from nderscore's answer. As far as I can tell, the C is as golfed as it can be, other than perhaps the preamble. Potentially I could tease out some undefined behaviour to point p to somewhere lower down on the stack for fewer bytes than defining an array outright.

-6 bytes: replace *p=getchar();if(*p<0)*p=0 with read(0,p,1)||(*p=0). Thanks to ceilingcat -4 bytes: replace (*p)++ and (*p)-- with ++*p and --*p. Thanks to Bubbler

\$\endgroup\$
4
  • 1
    \$\begingroup\$ (*p)++; and (*p)--; can be written as ++*p; and --*p;. \$\endgroup\$
    – Bubbler
    Aug 21, 2020 at 0:41
  • \$\begingroup\$ Nice first answer. \$\endgroup\$
    – Razetime
    Aug 21, 2020 at 5:29
  • \$\begingroup\$ Suggest *p*=read(0,p,1) instead of read(0,p,1)||(*p=0) \$\endgroup\$
    – ceilingcat
    Aug 21, 2020 at 7:16
  • \$\begingroup\$ Also, forgot to welcome you to CGCC! \$\endgroup\$
    – ceilingcat
    Aug 21, 2020 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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