The Stack Overflow podcast is back! Listen to an interview with our new CEO.

This challenge is related to the Brain-flak esoteric language and languages based on Brain-Flak. Note that challenges that require the answers to be in a specific language are generally discouraged.

Brain-flak is a stack-based esoteric language written by DJMcMayhem, and heavily inspired by brainfuck. The most notable feature is how the only valid characters are brackets, and the brackets must be fully matched for the program to be valid.

There are four zero-arg commands, that add when placed next to each other:

  • (), which evaluates to +1
  • [], which evaluates to the current height of the stack
  • {}, which pops the stack and evaluates to the popped value and
  • <>, which toggles the active stack between one of two stacks, and evaluates to 0.

If a pair of brackets has brain-flak code between them, the inner code is evaluated and supplied to the outer pair as the argument. Here are the four one-arg commands:

  • (foo), push foo on the active stack, and evaluates to foo
  • [foo], evaluates to negative foo
  • <foo>, executes foo, but evaluates it to 0, and
  • {foo}, loops until the value on top of the active stack is no longer 0.

More information:


Other Languages Based on this language might be tagged with include:

history | excerpt history