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.

User:Tommyaweosme/my brainfuck busy beaver

From Esolang
Jump to navigation Jump to search

once i clean this page up and add some more content, i plan to move this to the main namespace

this is the brainfuck busy beaver. nevermind, cells do wrap. the problem is to find the brainfuck program of length n that runs for the most steps before halting compared to all other brainfuck programs of length n.

number of possible programs per length

to find an upper bound, take 8^n

known champions

program lowerbound proven?
+ 1 PROVEN
++ 2 PROVEN
+++ 3 PROVEN
+[+] 766
?????
??????
???????
????????
?????????
??????????
???????????
????????????
?????????????
-[>>[>]+[<]<-] 196863

BB_BF(1) to BB_BF(3)

no brackets that do anything can fit here, and brackets are the only way to change the number of steps.

take BB_BF(3). if it had brackets, it would be one of these two forms:

?[]
[?]

the brackets in the first form run forever

the brackets in the second form dont ever run

BB_BF(4)

the best solution is probably +[+]

implementation i use

credit to user:none1 for the interpreter i use as the base of this.

<h1>brainfuck busy beaver</h1>
<input id="program">
<button onclick="run()">run</button>
<p id="steps">0</p>
<p id="output"></p>
<script>
function brainfuck(program,input){
    var stack=[];
    var matches={};
    var ip=0;
    var tape=[];
    var p=0;
    var output='';
	var steps=-1;
	document.getElementById("output").innerHTML = "";
    for(let i=0;i<1000000;i++){
        tape.push(0);
    }
    for(var i=0;i<program.length;i++){
        if(program[i]=='['){
            stack.push(i);
        }
        if(program[i]==']'){
            if(stack.length==0){
                throw new Error('Right bracket does not match left bracket');
            }
            var mt=stack.pop();
            matches[mt]=i;
            matches[i]=mt;
        }
    }
    if(stack.length!=0){
        throw new Error('Left bracket does not match right bracket');
    }
    while(ip<program.length){
					if(steps>100000000){
						return("100000000+");
					}
        if(program[ip]=='+'){
            tape[p]=tape[p]+1;
									if(tape[p]==256){
										tape[p]=0;
									}
            ip=ip+1;
									steps=steps+1;
        }
        if(program[ip]=='-'){
            tape[p]=tape[p]-1;
									if(tape[p]==-1){
										tape[p]=255;
									}
            ip=ip+1;
									steps=steps+1;
        }
        if(program[ip]=='>'){
            p=p+1;
            if(p>=1000000){
                throw new Error('Pointer overflow');
            }
            ip=ip+1;
									steps=steps+1;
        }
        if(program[ip]=='<'){
            p=p-1;
            if(p<0){
                throw new Error('Pointer underflow');
            }
            ip=ip+1;
									steps=steps+1;
        }
        if(program[ip]==','){
            if(input==''){
                tape[p]=0;
            }else{
                tape[p]=input.charCodeAt(0)%256;
                input=input.slice(1);
            }
            ip=ip+1;
									steps=steps+1;
        }
        if(program[ip]=='.'){
            output+=String.fromCharCode(tape[p]);
									document.getElementById("output").innerHTML += " "+tape[p];
            ip=ip+1;
									steps=steps+1;
        }
        if(program[ip]=='['){
            if(tape[p]==0){
                ip=matches[ip];
            }else{
                ip=ip+1;
            }
									steps=steps+1;
        }
        if(program[ip]==']'){
            if(tape[p]!=0){
                ip=matches[ip];
            }else{
                ip=ip+1;
            }
									steps=steps+1;
        }
        if(!('+-,.[]<>'.includes(program[ip]))){
            ip=ip+1;
									steps=steps+1;
        }
    }
    return steps;
}
	function run(){
		document.getElementById("steps").innerHTML = brainfuck(document.getElementById('program').value,"");
	}
</script>