Cotwo
Jump to navigation
Jump to search
Cotwo
Cotwo is a turing complete made by User:Hajunsheng and it has 2 commands like Co(Commands)Two(Two) right? ok... also it's not made in scratch!
Instructions
[ has three possible states, normal state prints last in stack, " state will skip next command if last two of stack aren't the same and | state will set last of stack to second to last of stack plus third to last of stack. ] has three possible states, normal state gets first character of user input, " state will jump to second to last of list*10 plus last of list in code pointer only if last of list is equal to second to last of list and | state will rotate the last of list to the first.
Interpreter
javascript if you cannot read.
function ctw(p){ const s=[]; let c=0; console.log("--- Cotwo Interpreter Output ---"); let k=""; while(c<p.length){ const r=p[c]; if(r==='['){ if(s.length>0){ const l=s[s.length-1]; const sl=s.length>1?s[s.length-2]:undefined; if(l!=='"'){ if(l!='|'){ k+=l; console.log(k); }else { if(s.length>=3){ s[s.length-1]=Number(s[s.length-3])+Number(sl); }else { console.error("Error: Stack too small for addition operation."); }}} else { if(l!=sl){ c++; }}} c++; } else if(r===']'){ const currentLast=s.length>0?s[s.length-1]:undefined; const secondLast=s.length>1?s[s.length-2]:undefined; if(currentLast!=='"'){ if(currentLast==='|'){ s.pop(); s.splice(0,0,s.pop()); }else { let u=prompt("Cotwo: Enter input:"); u=u[0]; s.push(u); c++; }} else { if(currentLast===secondLast){ c=(Number(secondLast)*10)+Number(currentLast); }else { c++; }}} else { s.push(r); c++; }} console.log("--- Program Finished ---"); }