123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <script src='https://cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js'></script>
<link rel="stylesheet" href="https://highlightjs.org/static/demo/styles/darcula.css">

<pre><code class="lang-javascript">const BrainFuck = (order) => {
    let Anum = []
    //     字符	含义 >	指针加一 <	指针减一 +	指针指向的字节的值加一
    // -	指针指向的字节的值减一 .	输出指针指向的单元内容(ASCII码) ,	输入内容到指针指向的单元(ASCII码)
    // [	如果指针指向的单元值为零,向后跳转到对应的]指令的次一指令处 ]	如果指针指向的单元值不为零,向前跳转到对应的[指令的次一指令处
    const LocalOrder = [
        '>', //
        '<',
        '+',
        '-',
        '.',
        ',',
        '[',
        ']'
    ]
    let Roundnum = []
    // while 范围
    let LRarray = []
    let NewLRarray = {}
    // goto ]
    let Goto = -1
    let Back = -1
    let LeftState = []
    //
    let RunStack = []
    let RunIndex = []

    let LeftNum = 0
    let RightNum = 0
    let Index = 0

    const SupOrder = {
        1: LocalOrder,

        3: ['[-]']
    }
    const RightMove = (i) => { Index+1?Index++:console.log('超内存啦');  }
    const LeftMove = (i) => { Index+1?Index--:Index = 0;}
    const AddNum = (i) => { 
        let whatindex = Anum[Index]
        if ( whatindex ){
           let AscII =  whatindex.charCodeAt()
           AscII++
           Anum[Index] = String.fromCharCode(AscII)
        }
        else{
            Anum[Index] = String.fromCharCode(1)
        }
    }
    const DownNum = (i) => {
        let whatindex = Anum[Index]
        if ( whatindex ){
           let AscII =  whatindex.charCodeAt()
           AscII--
           Anum[Index] = String.fromCharCode(AscII)
        }
        else{
            // - 
            Anum[Index] = String.fromCharCode(0)
        }
    }
    const PrintIndex = (i) => {
        if (Anum[Index].charCodeAt() >=33){
            console.log('Print:String--->>>',Anum[Index])
        }
        else{
        console.log('Print:ASCII-number--->>>',Anum[Index].charCodeAt());
        }
    }
    const InputStr = (i) => {
        // Input=prompt("请输入数据>>> ")
        // Anum[Index] = Input.charCodeAt()
    }
    const fnc7 = (i) => {

        let changeArray = LRarray.join(',').split(',')
        let Bottomi = parseInt(changeArray[changeArray.indexOf(i)+2])

        if(RunStack.length == 0){
            RunStack.push([ parseInt(i), Bottomi])
            RunIndex.push(Index)
        }
        else{
            if (RunStack.join(',').indexOf(i) > -1){
            }else{
                RunStack.push([ parseInt(i), Bottomi])
                RunIndex.push(Index)
            }
            Index = RunIndex[RunIndex.length-1]
        }

        Goto = -1
        Back = -1
        let isTrue = Anum[Index].charCodeAt()
        if (isTrue > 0)
        {
            Back = RunStack[RunStack.length-1][0]            
            
        }
        else{
            Goto = RunStack[RunStack.length-1][1]+1            
            RunStack.pop()
            RunIndex.pop()
        }

    }
    const fnc8 = (i) => {
        if (Back == -1 && Goto != -1){
            if(RunStack.length > 0)
            {
            Back = RunStack[RunStack.length-1][0]
            Goto = -1
            }
        }

    }
    const runFunc = {
        '>': RightMove, //
        '<': LeftMove,
        '+': AddNum,
        '-': DownNum,
        '.': PrintIndex,
        ',': InputStr,
        '[': fnc7,
        ']': fnc8
    }

    const OrderisOk = () => {
        const Border = order.split('')
        var selectNum = 0
        if (Border.every((x, i) => {
            let isOk = LocalOrder.indexOf(x)
            if ( x == '['){
                if(LRarray[LeftNum] )
                {
                    LRarray[LeftNum].push(i)
                }else{
                    LRarray[LeftNum] = []
                    LRarray[LeftNum].push(i)                    
                }
                LeftNum++
                if (LeftNum - RightNum == 1) {
                    Roundnum = []
                    Roundnum.push(LeftNum)
                } else if (LeftNum - RightNum > 1) {
                    Roundnum.push(LeftNum)
                }
                selectNum = i
            }
            else if( x == ']'){
                if(LRarray[RightNum])
                {
                    RightNum++
                    if( Roundnum && Roundnum.length == 1)
                    {
                        LRarray[Roundnum[0]-1].push(i)
                    }
                    else{
                        LRarray[Roundnum.pop()-1].push(i)
                    }
                }
                selectNum = i                
            }

            if (!+ (isOk + 1) || (LeftNum < RightNum)) {
                throw Error('无效命令-__->>>  ' + x + '  ::: 于' + i);
            }
            
            return + (isOk + 1)
        })) {
            if( LeftNum != RightNum){
                throw Error('无效命令-__->>>  []  ::: 于' + selectNum);                
            }
            console.log('true')
        }
    }
    OrderisOk()

    const changeOrder = (order) => {
        console.log(order);
    }
    console.log(LRarray)
    // const ParChild = (localArray) =>{
    //     let Big = localArray.join(',').split(',')[1]
    //     let TBig = Big
    //     for (let i = 2; i < localArray.length*2;i++)
    //     {
    //         if (Big < localArray.join(',').split(',')[i])
    //         {
    //             TBig = localArray.join(',').split(',')[i]
    //             ParChild(localArray.slice(0,i/2 >>> 0))
    //         }

    //     }
    //     if(localArray.length != 1 && TBig == Big){

    //         ParChild(localArray.slice[1])
    //     }
    //     if(localArray.length == 1){

    //     }
    // }
    // //ParChild()
    for (let i = 0; i < order.length; i++) {
        // goto ]
        if (RunStack.length > 0) {
            if (Back != -1 && Goto == -1 && RunStack[RunStack.length - 1][1] + 1 == i) {

                i = Back
            } else if (Goto != -1 && Back == -1 && RunStack[RunStack.length - 1][0] + 1 == i) {
                i = Goto
            }
        }
        if (RunStack.length == 0 && Goto != -1){
            i = Goto
            Goto = -1
        }
        runFunc[order[i]](i)
        if (i>44)
        console.log(Anum,'----',Index)
    }


}

BrainFuck('++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++' +
        '++++.>.+++.------.--------.>+.>.');
</code></pre> 
            
          
!
            
              $(document).ready(function() {
  $('pre code').each(function(i, block) {
    hljs.highlightBlock(block);
  });
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console