We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

Mobius brainfuck

From Esolang
Jump to navigation Jump to search

Mobius brainfuck is like brainfuck with finite unbounded cells. After one circle every number turns into its opposite. This allows to use only increment to decrease without wrap.

Instructions

Caption text
Char Equivalent C
+ arr[ptr]++;
> arr[ptr++]*=-1;ptr%=N;
[ while(arr[ptr]){
] }

IO can be added if necessary.

Turing complete

Should be TC for large enough N but I don't know how large need N be.

Interpreter

Written in JavaScript. Contains an optional output extension.

function mobius_brainfuck(program, N, useOutput=true) {
    let result = `const arr = Array(${+N}).fill(0); let ptr = 0;`;
    if(!useOutput)
        program = program.replace(/\./g, "");
    result += program.replace(/[^+>\[\].]/g, "")
                     .replace(/]/g, "}")
                     .replace(/\[/g, "while(arr[ptr]){")
                     .replace(/\+/g, "arr[ptr]++;")
                     .replace(/>/g, `arr[ptr++]*=-1;ptr%=${+N};`)
                     .replace(/\./g, "console.log(arr[ptr]);");
    eval(result);
}