Esoteric Languages
Esoteric
Interpreters
Algorithms
Logic
This is a way to make Kata in Befunge-98. You can try a Befunge Kata here if you like. I put in an ASCII Mandelbrot set Befunge program in here
let befungeProgramCode=
`&&10p00p00g01p>00g11pv
v <
v\\*a\\< ;make a large number 30;
>15>1-:#^_$v
v p03< ;get the r and i values *a large number @ 31 32; ;f(z)=Z^2+C Z=[Z0*Z0+Z1*Z1+Cr,2*Z0*Z1+Ci];
>10g02p>00g11g-30g*00g/2*30g-2*32p>00g01g-30g*00g/2*30g-2*31p 041p042p 051p >02g1-02p 41g:*30g/42g:*30g/-31g+51p 41g42g2**30g/32g+42p 51g41p v
^ _v#g20 <
^ p10-1< v,,"##"< vw\\*g034+/g03*:g14/g03*:g24 <
^ ,ap11-1_@#:g11p10g00$w0:g10p20g01< ,,".."<<`;
function testAThing(code,thing){
let befungeProgram=new B98(code);
befungeProgram.input=thing;
let timer=0;
let timeOut=1000000;
while(!befungeProgram.terminated&&timer++<timeOut){
befungeProgram.step();
}
if(timer>=timeOut){
console.log('Befunge program timed out after '+timeOut+' steps.');
}
if(befungeProgram.exitCode){
console.log('Befunge Program exited with exit code: '+befungeProgram.exitCode);
}
return(befungeProgram.output);
}
let solutionCode=
`&&10p00p00g01p>00g11pv
v <
v\\*a\\< ;make a large number 30;
>15>1-:#^_$v
v p03< ;get the r and i values *a large number @ 31 32; ;f(z)=Z^2+C Z=[Z0*Z0+Z1*Z1+Cr,2*Z0*Z1+Ci];
>10g02p>00g11g-30g*00g/2*30g-2*32p>00g01g-30g*00g/2*30g-2*31p 041p042p 051p >02g1-02p 41g:*30g/42g:*30g/-31g+51p 41g42g2**30g/32g+42p 51g41p v
^ _v#g20 <
^ p10-1< v,,"##"< vw\\*g034+/g03*:g14/g03*:g24 <
^ ,ap11-1_@#:g11p10g00$w0:g10p20g01< ,,".."<<`;
describe("Test", function(){
let ans=testAThing(solutionCode,[10,10]);
it("Mandelbrot Set", function(){
Test.assertEquals(testAThing(befungeProgramCode,[10,10]), ans,'Expected:\n'+ans);
});
});
console.log(testAThing(solutionCode,[30,26]));