13
\$\begingroup\$

Goal

Do some action (like delete a file, connect to a server, …) that you can not do in standard Brainfuck.

What

As you know, all calculations you can do in almost any programming language you can also do in standard Brainfuck. However, since standard Brainfuck can't do most syscalls, there are many things that are impossible to do in Brainfuck. Your goal is to do anything that is impossible in Brainfuck.

Rules

Do something that is not possible with a valid program in standard Brainfuck. With standard Brainfuck i mean:

  • It only uses the 8 Brainfuck instructions ([]+-<>.,).
  • All cells start with the value 0.
  • The output/input is not interpreted/generated in a special way to do any other actions (except what standard Unix terminals may do).
  • There are no unexpected features in the Brainfuck implementation, accessible from the Brainfuck code.
  • Assume that there are no implementations Bugs.
  • The implementation may or may not request more memory from the OS when more cells / higher values are used.
  • The implementation could have any execution speed.
  • The implementation may or may not halt when a negative cell index or a cell index that is out of bounds (in case the implementation has a limited amount of cells) is reached and may or may not generates an error with a message and/or exit with a different exit code.
  • The implementation can have any number of bits peer cell (from 1 to virtually infinite).
  • The implementation may or may not run on a UNIX terminal, where you can set colours, bold or italic letter, clear the screen and jump with the cursor just by sending special sequences.

Anything on this list counts as impossible with any standard Brainfuck implementation. Write a program that does at least one from the following this list or something else that is impossible in standard Brainfuck:

  • Create, delete or move a File**.
  • Open a file that wasn't opened before (i.e. not stdout, stderr nor stdin).
  • Get/display the current time.
  • Shutdown, restart, … the system (when your program isn't the only program).
  • Change the current working directory.
  • Get/display command-line arguments.
  • Do anything that requires the internet.
  • Fork/start or kill a process (other than the program's own process).
  • Get random numbers from a external (i.e. not from a PRNG with a fixed seed nor a seed from the input) source.
  • Wait on user input with a timeout.
  • Send a signal to a different process.
  • Change its own command line.
  • Write a specific message to stdout AND a specific message to stderr. (By specific, i mean a message that is completely controlled by the code and not the implementation).
  • Change the baud rate on a serial port.
  • Mount, unmount, format, defragment, eject … a drive/partition.
  • Enable/disable a network connection.
  • Catch and react to a signal (other than the standard action).
  • Play a sound other than the \a/Bell-Character.
  • Open or close a Windows (Except closing the own terminal).
  • Getting / display info about the underlining OS or Hardware (except for the size of a Byte)

**It is theoretically possible to write a Brainfuck program that emulates a shell where you can create and delete files within, but that file would only exist in RAM inside the Brainfuck program, so it is not the same.

Things that are, at least theoretically, possible in Brainfuck and don't count:

What Explanation Example
Do calculations Brainfuck is turing complete -
Show graphics A Brainfuck program can use coloured text or different Letter to display the pixels of an image. Mandelbrot, Coloroutput
Show animations Outputing multiple images can create an animation BadApple
Delay/Wait a short time Some interpreters have a fixed clock rate and you can calculate a delay based on the number of executed instructions. -
Exit with EXIT_SUCCESS or EXIT_FAILURE Some interpreters will exit with EXIT_FAILURE when a negative cell is reached. Codegolf Answer
Write to stdout and a generic error message to stderr. Brainfuck can write to stdout. Accessing a negative cell index may cause some interpreter do display an error message
Use a certain amount of RAM or request more memory from the OS Some implementations request more RAM when more cells are used -
Read or write from a single already opened file. On Unix, stdin and stdout can be almost any file, which can be set before the Process starts. This is standard and an expected feature of the OS/shell.
Display the size of a Byte A Brainfuck program could detect the size of a single cell (which i count as a Byte) and display it -
Write to stdout and a standard error message to stderr Some implementations write to stdout normally but display a error message when they reach a error condition, such as reaching a cell with negative index Online interpreter with separate error Output.

Shortest code wins.

Example

An ungolfed example in Python:

import datetime
now = datetime.datetime.now()
print(now.strftime("%Y-%m-%d %H:%M:%S"))
\$\endgroup\$
11
  • 1
    \$\begingroup\$ @Tbw It means a real random number generator, not a PRNG, which is just an algorithm and can be implemented in BF. \$\endgroup\$
    – mbomb007
    Commented Aug 7 at 18:13
  • 1
    \$\begingroup\$ @mbomb007 ...unless the PRNG implementation uses the system time (or something else unavailable to BF) as a seed perhaps? \$\endgroup\$ Commented Aug 7 at 18:20
  • 2
    \$\begingroup\$ Does writing to stderr count (e.g. Python, 1 byte - / - Try it online)? \$\endgroup\$ Commented Aug 7 at 19:27
  • 12
    \$\begingroup\$ This seems very broad. I'm holding off on closing this due to my mod hammer, but currently the distinction between what brainfuck can and can't do depends on the implementation, due to the fact it's Turing complete. I'd suggest choosing a specific implementation that is representative enough of brainfuck so that people can objectively compare between their answers and brainfuck \$\endgroup\$ Commented Aug 7 at 20:00
  • 1
    \$\begingroup\$ @Jonathan Allan I updated the question. The rule of the question was: Writing to a single file (doesn't matter if it is stdout, stderr or something else) doesn't count. Why: Brainfuck writtes to an output stream, and in most interpreter it is very easy to set what that output is writing to, it is an expected feature of many implementations. However, writing to 2 files (for example, stdout and stderr) counts. If you can create better rules, you can make a new and better challenge/question (especially since this question is closed). \$\endgroup\$ Commented Aug 12 at 14:41

15 Answers 15

8
\$\begingroup\$

Bash, 2 bytes

>_

Try it online!

Create a file named '_' in the current directory.

\$\endgroup\$
1
  • \$\begingroup\$ How about w? Shorter but it needs the binary w, >_ is builtin. \$\endgroup\$ Commented Aug 13 at 16:18
7
\$\begingroup\$

Jelly, 0 bytes

A full program that prints 0 unless provided an argument in which case it prints* the Jellification** of that argument evaluated as Python code if possible or the raw argument as a string if not. (Satisfies the requirements since Brainfuck can only read from stdin, not from command line arguments).

Try it online!

* an empty lists prints as nothing; a mixed list (characters and numbers) smashes its element's representations together, a singleton list prints its element.

** None becomes an empty list; complex numbers with no imaginary part become floats; dictionaries become a list of their keys if all keys are strings; probably other things may happen in other exceptional cases

\$\endgroup\$
3
\$\begingroup\$

Javascript, 7 bytes

alert()

Window is the point

\$\endgroup\$
3
\$\begingroup\$

Ruby, 3 bytes

Prints the command-line arguments.

p$*

Attempt This Online!

\$\endgroup\$
3
\$\begingroup\$

Funge-98, 4 bytes

6y,@

Try it online!

Outputs the operating system's path separator (/ for POSIX, \ for Windows).

\$\endgroup\$
3
\$\begingroup\$

Python 3, 11 bytes

open(*'ww')

Create a file called w in the current directory.

\$\endgroup\$
3
\$\begingroup\$

PARI/GP, 2 bytes

\s

Attempt This Online!

\s prints the state of the PARI stack and heap, which is non-deterministic.

Example output:

 Top : 7fadf82bd000   Bottom : 7fadf7b1be00   Current stack : 7fadf82bcfb8
 Used :                         9  long words  (0 K)
 Available :                    999991  long words  (7808 K)
 Occupation of the PARI stack :   0.00 percent
 1 objects on heap occupy 9 long words

 10 variable names used (10 user + 0 private) out of 65535

Copied from my answer to another challenge.

\$\endgroup\$
3
\$\begingroup\$

Batch, 2 bytes

hh

Launches HTML help (which displays its own window).

\$\endgroup\$
4
  • 2
    \$\begingroup\$ @JonathanAllan Can BF print to stderr? \$\endgroup\$
    – Neil
    Commented Aug 7 at 19:00
  • 1
    \$\begingroup\$ @JonathanAllan Actually of the three, only fc prints to stderr, so the other two aren't acceptable. (hh opens a separate window, which BF definitely can't do.) \$\endgroup\$
    – Neil
    Commented Aug 7 at 20:01
  • \$\begingroup\$ Apparently, "Read or write from a single file." in the "don't count" list rules this out for reasons I don't fully comprehend \$\endgroup\$ Commented Aug 8 at 10:42
  • 1
    \$\begingroup\$ @JonathanAllan Looks like I'll have to stick with hh then... \$\endgroup\$
    – Neil
    Commented Aug 8 at 11:34
2
\$\begingroup\$

Python 2, 11 bytes

print id(0)

This program outputs the address of the object 0 in memory.

Run it here

\$\endgroup\$
6
  • 1
    \$\begingroup\$ Hmm, what would BF be expected to output? (Python instantiates that memory, so I think it may be a bit of a -chicken- python and egg; perhaps the empty output is "correct" for a BF program?) \$\endgroup\$ Commented Aug 7 at 18:47
  • 1
    \$\begingroup\$ @JonathanAllan This is effectively an rng. \$\endgroup\$
    – Wheat Wizard
    Commented Aug 7 at 19:17
  • \$\begingroup\$ Outputting to stderr isn't possible in BF, so 1/0 for three? \$\endgroup\$ Commented Aug 7 at 19:17
  • \$\begingroup\$ @WheatWizard ah yes, that would help in the description :) (EDIT: and I've used this property myself before! >.<) \$\endgroup\$ Commented Aug 7 at 19:18
  • \$\begingroup\$ ...or maybe just / as that raises a SyntaxError and pipes its message to stderr. \$\endgroup\$ Commented Aug 7 at 19:25
2
\$\begingroup\$

Trivial answers that output command-line arguments

Many languages can easily read command-line args:

Pip, 1 byte

a

Outputs the first command-line argument. Attempt This Online!

\$\endgroup\$
1
  • \$\begingroup\$ I think this CW should be broadened to include obvious RNG/system time answers \$\endgroup\$ Commented Aug 8 at 2:45
2
\$\begingroup\$

APL+WIN, 3 bytes

Outputs the current time to the nearest msec.

⎕ts

Try it online! Thang to Dyalog Classic

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

QBasic, 6 3 bytes

CLS

Clears the screen.

Try it at Archive.org!

If it turns out there is technically some way to do this in BF (e.g. by outputting a bunch of newlines), then here's a 5-byte solution:

FILES

Outputs the contents of the current working directory.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Nice idea. However, in many terminals there is \033c or \033[2J which clears the screen. Is this something different? \$\endgroup\$ Commented Aug 12 at 15:11
  • \$\begingroup\$ Truthfully, I don't know enough about DOS to answer that question. :P That's why I included the alternate solution. \$\endgroup\$
    – DLosc
    Commented Aug 12 at 18:53
1
\$\begingroup\$

JavaScript (Node.js), 9 bytes

_=>Date()

Try it online!

\$\endgroup\$
2
  • 4
    \$\begingroup\$ Wrong. Run this Python program, paste the output at this BF interpreter, select the Cell size of "32", and click run. That was for your 8-byte program. Still it can output any Unicode character. \$\endgroup\$
    – mbomb007
    Commented Aug 7 at 18:37
  • 2
    \$\begingroup\$ For BF interpreters where the output is automatically decoded as UTF-8, such as TIO, we can make use of the fact that ā is encoded as 0xC4 0x81, and write those two numbers separately: Try it online! \$\endgroup\$ Commented Aug 7 at 19:49
1
\$\begingroup\$

C++, 46 bytes

#include<ios>
main(){freopen("x","w",stdout);}

Creates a file called 'x' in the current directory (if x does not exist). I think this still counts.

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You don't need the #include for fopen(). How about system("w");? \$\endgroup\$ Commented Aug 12 at 15:20
  • \$\begingroup\$ @12431234123412341234123 Thanks! I'll have a look into how to do that. \$\endgroup\$
    – Redz
    Commented Aug 12 at 22:34
1
\$\begingroup\$

Google Sheets / Excel, 6 bytes

=NOW()

Returns the current date and time.

\$\endgroup\$

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