Skip to main content
added 34 characters in body
Source Link
MickyT
  • 12.2k
  • 2
  • 26
  • 48

#Beam#Beam, 307 288 bytes

#Beam, 307 288 bytes

#Beam, 307 288 bytes

added 1210 characters in body
Source Link
MickyT
  • 12.2k
  • 2
  • 26
  • 48

#Beam, 307307 288 bytes

And now for the longest solution. I think I could compress this a bit more, but the brain is getting a little fried. I'm pretty happy I got it working though. Rearranged it slightly to gain a few.

'''''''''>`+++++++++++)+P'++P'++P'''''''>`++ \/+)@'''''>`+++++++)@@' \
v``P++'P++'P+L```P'''+ v```P'''----(+++++++++/+/+'L@@++P+++'L@@++(+++++`<'''+++++`<''/
>'p-`n'''''''>`+++++++++`n'''''''>`++++++++/\++Pv
 ^    >'P'p-``n'              >'p-``n'''''''''''>`++++++)@'''''''>`++ \
^       <    >p:L''p-``            >''P``v
 ^      Hu```P-p'''L@++++++++++LP+p       <``P+++++''L@@+++++@++(+++++/
var ITERS_PER_SEC = 100000;
var TIMEOUT_SECS = 50;
var ERROR_INTERRUPT = "Interrupted by user";
var ERROR_TIMEOUT = "Maximum iterations exceeded";
var ERROR_LOSTINSPACE = "Beam is lost in space";

var code, store, beam, ip_x, ip_y, dir, input_ptr, mem;
var input, timeout, width, iterations, running;

function clear_output() {
document.getElementById("output").value = "";
document.getElementById("stderr").innerHTML = "";
}

function stop() {
running = false;
document.getElementById("run").disabled = false;
document.getElementById("stop").disabled = true;
document.getElementById("clear").disabled = false;
document.getElementById("timeout").disabled = false;
}

function interrupt() {
error(ERROR_INTERRUPT);
}

function error(msg) {
document.getElementById("stderr").innerHTML = msg;
stop();
}

function run() {
clear_output();
document.getElementById("run").disabled = true;
document.getElementById("stop").disabled = false;
document.getElementById("clear").disabled = true;
document.getElementById("input").disabled = false;
document.getElementById("timeout").disabled = false;

code = document.getElementById("code").value;
input = document.getElementById("input").value;
timeout = document.getElementById("timeout").checked;
    
code = code.split("\n");
width = 0;
for (var i = 0; i < code.length; ++i){
    if (code[i].length > width){ 
        width = code[i].length;
    }
}
console.log(code);
console.log(width);
    
running = true;
dir = 0;
ip_x = 0;
ip_y = 0;
input_ptr = 0;
beam = 0;
store = 0;
mem = [];
    
input = input.split("").map(function (s) {
        return s.charCodeAt(0);
    });
    
iterations = 0;

beam_iter();
}

function beam_iter() {
while (running) {
    var inst; 
    try {
        inst = code[ip_y][ip_x];
    }
    catch(err) {
        inst = "";
    }
    switch (inst) {
        case ">":
            dir = 0;
            break;
        case "<":
            dir = 1;
            break;
        case "^":
            dir = 2;
            break;
        case "v":
            dir = 3;
            break;
        case "+":
            ++beam;
            break;
        case "-":
            --beam;
            break;
        case "@":
            document.getElementById("output").value += String.fromCharCode(beam);
            break;
        case ":":
            document.getElementById("output").value += beam;
            break;
        case "/":
            dir ^= 2;
            break;
        case "\\":
            dir ^= 3;
            break;
        case "!":
            if (beam != 0) {
                dir ^= 1;
            }
            break;
        case "?":
            if (beam == 0) {
                dir ^= 1;
            }
            break;
        case "|":
            switch (dir) {
            case 2:
                dir = 3;
                break;
            case 3:
                dir = 2;
                break;
            }
            break;
        case "_":
            switch (dir) {
            case 0:
                dir = 1;
                break;
            case 1:
                dir = 0;
                break;
            }
            break;
        case "H":
            stop();
            break;
        case "S":
            store = beam;
            break;
        case "L":
            beam = store;
            break;
        case "s":
            mem[beam] = store;
            break;
        case "g":
            store = mem[beam];
            break;
        case "P":
            mem[store] = beam;
            break;
        case "p":
            beam = mem[store];
            break;
        case "u":
            if (beam != store) {
                dir = 2;
            }
            break;
        case "n":
            if (beam != store) {
                dir = 3;
            }
            break;
        case "`":
            --store;
            break;
        case "'":
            ++store;
            break;
        case ")":
            if (store != 0) {
                dir = 1;
            }
            break;
        case "(":
            if (store != 0) {
                dir = 0;
            }
            break;
        case "r":
            if (input_ptr >= input.length) {
                beam = 0;
            } else {
                beam = input[input_ptr];
                ++input_ptr;
            }
            break;
        }
    // Move instruction pointer
    switch (dir) {
        case 0:
            ip_x++;
            break;
        case 1:
            ip_x--;
            break;
        case 2:
            ip_y--;
            break;
        case 3:
            ip_y++;
            break;
    }
    if (running && (ip_x < 0 || ip_y < 0 || ip_x >= width || ip_y >= code.length)) {
        error(ERROR_LOSTINSPACE);
    }
    ++iterations;
    if (iterations > ITERS_PER_SEC * TIMEOUT_SECS) {
        error(ERROR_TIMEOUT);
    }
}
}
<div style="font-size:12px;font-family:Verdana, Geneva, sans-serif;">Code:
    <br>
    <textarea id="code" rows="6" style="overflow:scroll;overflow-x:hidden;width:90%;">
'''''''''>`+++++++++++)90%;">+P'++P'++P'''''''>`++ \/+)@'''''>`+++++++)@@' \
v``P++'P++'P+L```P'''+ v```P'''----(+++++++++/+/+'L@@++P+++'L@@++(+++++`<'''+++++`<''/
>'p-`n'''''''>`+++++++++`n'''''''>`++++++++/\++Pv
^    >'P'p-``n'              >'p-``n'''''''''''>`++++++)@'''''''>`++ \
^       <    >p:L''p-``            >''P``v
^      Hu```P-p'''L@++++++++++LP+p       <``P+++++''L@@+++++@++(+++++/
    </textarea>
        <br>
        <input id="run" type="button" value="Run" onclick="run()">
        <input id="stop" type="button" value="Stop" onclick="interrupt()" disabled="disabled">
        <input id="clear" type="button" value="Clear" onclick="clear_output()">&nbsp; <span id="stderr" style="color:red"></span>
    </p>Output:
    <br>
    <textarea id="output" rows="6" style="overflow:scroll;width:90%;"></textarea>
    <br>Input:
    <br>
    <textarea id="input" rows="1" style="overflow:scroll;overflow-x:hidden;width:90%;"></textarea>
    <p>Timeout:
        <input id="timeout" type="checkbox" checked="checked">&nbsp;
        <br>    </div>

Explanation

+P'++P'++P'''''''>`++ \
v```P'''----(+++++++++/

Initializes the program, presetting values in memory
Memory 0, value 1, count incrementer
Memory 1, value 3, div 3 decrementer
Memory 2, value 5, div 5 decrementer
Memory 3, value 99, loop decrementer

>'p-`n
     >'P'p-``n        
             >p:L''p-`` 

Gets value from Memory 1, decrements it, sets Store to 0. If value <> 0 change direction down, otherwise pass though.
Do the same with Memory 2. Finally if it gets down there, print out the current counter from memory 0.

                       /+)@'''''>`+++++++)@' \
                       +/P+++'L@@++(+++++`<''/
      '''''''>`++++++++/

Prints Fizz and resets memory slot 1 to 3.

                    >'p-``n'''''''''''>`++++++)@'''''''>`++ \

                                 ``P+++++''L@@+++++@++(+++++/

Another div 5 checker to catch FizzBuzzs. Prints out Buzz and resets memory slot 2 to 5.

                              >''P``v
       Hu```P-p'''L@++++++++++LP+p  <

Increments the counter, prints a newline, decrements the loop counter and exits if required.

#Beam, 307 bytes

And now for the longest solution. I think I could compress this a bit more, but the brain is getting a little fried. I'm pretty happy I got it working though.

'''''''''>`+++++++++++)\/)@'''''>`+++++++)@ \
v``P++'P++'P+L```P'''+ /+/+'L@@++(+++++`<'''/
>'p-`n'''''''>`+++++++++/\++Pv
     >'P'p-``n'              >'p-``n'''''''''''>`++++++)@'''''''>`++ \
^       <    >p:L''p-``            >''P``v
       Hu```P-p'''L@++++++++++LP+p       <``P+++++''L@@+++++@++(+++++/
var ITERS_PER_SEC = 100000;
var TIMEOUT_SECS = 50;
var ERROR_INTERRUPT = "Interrupted by user";
var ERROR_TIMEOUT = "Maximum iterations exceeded";
var ERROR_LOSTINSPACE = "Beam is lost in space";

var code, store, beam, ip_x, ip_y, dir, input_ptr, mem;
var input, timeout, width, iterations, running;

function clear_output() {
document.getElementById("output").value = "";
document.getElementById("stderr").innerHTML = "";
}

function stop() {
running = false;
document.getElementById("run").disabled = false;
document.getElementById("stop").disabled = true;
document.getElementById("clear").disabled = false;
document.getElementById("timeout").disabled = false;
}

function interrupt() {
error(ERROR_INTERRUPT);
}

function error(msg) {
document.getElementById("stderr").innerHTML = msg;
stop();
}

function run() {
clear_output();
document.getElementById("run").disabled = true;
document.getElementById("stop").disabled = false;
document.getElementById("clear").disabled = true;
document.getElementById("input").disabled = false;
document.getElementById("timeout").disabled = false;

code = document.getElementById("code").value;
input = document.getElementById("input").value;
timeout = document.getElementById("timeout").checked;
    
code = code.split("\n");
width = 0;
for (var i = 0; i < code.length; ++i){
    if (code[i].length > width){ 
        width = code[i].length;
    }
}
console.log(code);
console.log(width);
    
running = true;
dir = 0;
ip_x = 0;
ip_y = 0;
input_ptr = 0;
beam = 0;
store = 0;
mem = [];
    
input = input.split("").map(function (s) {
        return s.charCodeAt(0);
    });
    
iterations = 0;

beam_iter();
}

function beam_iter() {
while (running) {
    var inst; 
    try {
        inst = code[ip_y][ip_x];
    }
    catch(err) {
        inst = "";
    }
    switch (inst) {
        case ">":
            dir = 0;
            break;
        case "<":
            dir = 1;
            break;
        case "^":
            dir = 2;
            break;
        case "v":
            dir = 3;
            break;
        case "+":
            ++beam;
            break;
        case "-":
            --beam;
            break;
        case "@":
            document.getElementById("output").value += String.fromCharCode(beam);
            break;
        case ":":
            document.getElementById("output").value += beam;
            break;
        case "/":
            dir ^= 2;
            break;
        case "\\":
            dir ^= 3;
            break;
        case "!":
            if (beam != 0) {
                dir ^= 1;
            }
            break;
        case "?":
            if (beam == 0) {
                dir ^= 1;
            }
            break;
        case "|":
            switch (dir) {
            case 2:
                dir = 3;
                break;
            case 3:
                dir = 2;
                break;
            }
            break;
        case "_":
            switch (dir) {
            case 0:
                dir = 1;
                break;
            case 1:
                dir = 0;
                break;
            }
            break;
        case "H":
            stop();
            break;
        case "S":
            store = beam;
            break;
        case "L":
            beam = store;
            break;
        case "s":
            mem[beam] = store;
            break;
        case "g":
            store = mem[beam];
            break;
        case "P":
            mem[store] = beam;
            break;
        case "p":
            beam = mem[store];
            break;
        case "u":
            if (beam != store) {
                dir = 2;
            }
            break;
        case "n":
            if (beam != store) {
                dir = 3;
            }
            break;
        case "`":
            --store;
            break;
        case "'":
            ++store;
            break;
        case ")":
            if (store != 0) {
                dir = 1;
            }
            break;
        case "(":
            if (store != 0) {
                dir = 0;
            }
            break;
        case "r":
            if (input_ptr >= input.length) {
                beam = 0;
            } else {
                beam = input[input_ptr];
                ++input_ptr;
            }
            break;
        }
    // Move instruction pointer
    switch (dir) {
        case 0:
            ip_x++;
            break;
        case 1:
            ip_x--;
            break;
        case 2:
            ip_y--;
            break;
        case 3:
            ip_y++;
            break;
    }
    if (running && (ip_x < 0 || ip_y < 0 || ip_x >= width || ip_y >= code.length)) {
        error(ERROR_LOSTINSPACE);
    }
    ++iterations;
    if (iterations > ITERS_PER_SEC * TIMEOUT_SECS) {
        error(ERROR_TIMEOUT);
    }
}
}
<div style="font-size:12px;font-family:Verdana, Geneva, sans-serif;">Code:
    <br>
    <textarea id="code" rows="6" style="overflow:scroll;overflow-x:hidden;width:90%;">
'''''''''>`+++++++++++)\/)@'''''>`+++++++)@ \
v``P++'P++'P+L```P'''+ /+/+'L@@++(+++++`<'''/
>'p-`n'''''''>`+++++++++/\++Pv
^    >'P'p-``n'              >'p-``n'''''''''''>`++++++)@'''''''>`++ \
^       <    >p:L''p-``            >''P``v
^      Hu```P-p'''L@++++++++++LP+p       <``P+++++''L@@+++++@++(+++++/
    </textarea>
        <br>
        <input id="run" type="button" value="Run" onclick="run()">
        <input id="stop" type="button" value="Stop" onclick="interrupt()" disabled="disabled">
        <input id="clear" type="button" value="Clear" onclick="clear_output()">&nbsp; <span id="stderr" style="color:red"></span>
    </p>Output:
    <br>
    <textarea id="output" rows="6" style="overflow:scroll;width:90%;"></textarea>
    <br>Input:
    <br>
    <textarea id="input" rows="1" style="overflow:scroll;overflow-x:hidden;width:90%;"></textarea>
    <p>Timeout:
        <input id="timeout" type="checkbox" checked="checked">&nbsp;
        <br>    </div>

#Beam, 307 288 bytes

And now for the longest solution. I think I could compress this a bit more, but the brain is getting a little fried. I'm pretty happy I got it working though. Rearranged it slightly to gain a few.

+P'++P'++P'''''''>`++ \/+)@'''''>`+++++++)@' \
v```P'''----(+++++++++/+/P+++'L@@++(+++++`<''/
>'p-`n'''''''>`++++++++/
^    >'P'p-``n'         >'p-``n'''''''''''>`++++++)@'''''''>`++ \
^       <    >p:L''p-``       >''P``v
^      Hu```P-p'''L@++++++++++LP+p  <``P+++++''L@@+++++@++(+++++/
var ITERS_PER_SEC = 100000;
var TIMEOUT_SECS = 50;
var ERROR_INTERRUPT = "Interrupted by user";
var ERROR_TIMEOUT = "Maximum iterations exceeded";
var ERROR_LOSTINSPACE = "Beam is lost in space";

var code, store, beam, ip_x, ip_y, dir, input_ptr, mem;
var input, timeout, width, iterations, running;

function clear_output() {
document.getElementById("output").value = "";
document.getElementById("stderr").innerHTML = "";
}

function stop() {
running = false;
document.getElementById("run").disabled = false;
document.getElementById("stop").disabled = true;
document.getElementById("clear").disabled = false;
document.getElementById("timeout").disabled = false;
}

function interrupt() {
error(ERROR_INTERRUPT);
}

function error(msg) {
document.getElementById("stderr").innerHTML = msg;
stop();
}

function run() {
clear_output();
document.getElementById("run").disabled = true;
document.getElementById("stop").disabled = false;
document.getElementById("clear").disabled = true;
document.getElementById("input").disabled = false;
document.getElementById("timeout").disabled = false;

code = document.getElementById("code").value;
input = document.getElementById("input").value;
timeout = document.getElementById("timeout").checked;
    
code = code.split("\n");
width = 0;
for (var i = 0; i < code.length; ++i){
    if (code[i].length > width){ 
        width = code[i].length;
    }
}
console.log(code);
console.log(width);
    
running = true;
dir = 0;
ip_x = 0;
ip_y = 0;
input_ptr = 0;
beam = 0;
store = 0;
mem = [];
    
input = input.split("").map(function (s) {
        return s.charCodeAt(0);
    });
    
iterations = 0;

beam_iter();
}

function beam_iter() {
while (running) {
    var inst; 
    try {
        inst = code[ip_y][ip_x];
    }
    catch(err) {
        inst = "";
    }
    switch (inst) {
        case ">":
            dir = 0;
            break;
        case "<":
            dir = 1;
            break;
        case "^":
            dir = 2;
            break;
        case "v":
            dir = 3;
            break;
        case "+":
            ++beam;
            break;
        case "-":
            --beam;
            break;
        case "@":
            document.getElementById("output").value += String.fromCharCode(beam);
            break;
        case ":":
            document.getElementById("output").value += beam;
            break;
        case "/":
            dir ^= 2;
            break;
        case "\\":
            dir ^= 3;
            break;
        case "!":
            if (beam != 0) {
                dir ^= 1;
            }
            break;
        case "?":
            if (beam == 0) {
                dir ^= 1;
            }
            break;
        case "|":
            switch (dir) {
            case 2:
                dir = 3;
                break;
            case 3:
                dir = 2;
                break;
            }
            break;
        case "_":
            switch (dir) {
            case 0:
                dir = 1;
                break;
            case 1:
                dir = 0;
                break;
            }
            break;
        case "H":
            stop();
            break;
        case "S":
            store = beam;
            break;
        case "L":
            beam = store;
            break;
        case "s":
            mem[beam] = store;
            break;
        case "g":
            store = mem[beam];
            break;
        case "P":
            mem[store] = beam;
            break;
        case "p":
            beam = mem[store];
            break;
        case "u":
            if (beam != store) {
                dir = 2;
            }
            break;
        case "n":
            if (beam != store) {
                dir = 3;
            }
            break;
        case "`":
            --store;
            break;
        case "'":
            ++store;
            break;
        case ")":
            if (store != 0) {
                dir = 1;
            }
            break;
        case "(":
            if (store != 0) {
                dir = 0;
            }
            break;
        case "r":
            if (input_ptr >= input.length) {
                beam = 0;
            } else {
                beam = input[input_ptr];
                ++input_ptr;
            }
            break;
        }
    // Move instruction pointer
    switch (dir) {
        case 0:
            ip_x++;
            break;
        case 1:
            ip_x--;
            break;
        case 2:
            ip_y--;
            break;
        case 3:
            ip_y++;
            break;
    }
    if (running && (ip_x < 0 || ip_y < 0 || ip_x >= width || ip_y >= code.length)) {
        error(ERROR_LOSTINSPACE);
    }
    ++iterations;
    if (iterations > ITERS_PER_SEC * TIMEOUT_SECS) {
        error(ERROR_TIMEOUT);
    }
}
}
<div style="font-size:12px;font-family:Verdana, Geneva, sans-serif;">Code:
    <br>
    <textarea id="code" rows="6" style="overflow:scroll;overflow-x:hidden;width:90%;">+P'++P'++P'''''''>`++ \/+)@'''''>`+++++++)@' \
v```P'''----(+++++++++/+/P+++'L@@++(+++++`<''/
>'p-`n'''''''>`++++++++/
^    >'P'p-``n'         >'p-``n'''''''''''>`++++++)@'''''''>`++ \
^       <    >p:L''p-``       >''P``v
^      Hu```P-p'''L@++++++++++LP+p  <``P+++++''L@@+++++@++(+++++/
    </textarea>
        <br>
        <input id="run" type="button" value="Run" onclick="run()">
        <input id="stop" type="button" value="Stop" onclick="interrupt()" disabled="disabled">
        <input id="clear" type="button" value="Clear" onclick="clear_output()">&nbsp; <span id="stderr" style="color:red"></span>
    </p>Output:
    <br>
    <textarea id="output" rows="6" style="overflow:scroll;width:90%;"></textarea>
    <br>Input:
    <br>
    <textarea id="input" rows="1" style="overflow:scroll;overflow-x:hidden;width:90%;"></textarea>
    <p>Timeout:
        <input id="timeout" type="checkbox" checked="checked">&nbsp;
        <br>    </div>

Explanation

+P'++P'++P'''''''>`++ \
v```P'''----(+++++++++/

Initializes the program, presetting values in memory
Memory 0, value 1, count incrementer
Memory 1, value 3, div 3 decrementer
Memory 2, value 5, div 5 decrementer
Memory 3, value 99, loop decrementer

>'p-`n
     >'P'p-``n        
             >p:L''p-`` 

Gets value from Memory 1, decrements it, sets Store to 0. If value <> 0 change direction down, otherwise pass though.
Do the same with Memory 2. Finally if it gets down there, print out the current counter from memory 0.

                       /+)@'''''>`+++++++)@' \
                       +/P+++'L@@++(+++++`<''/
      '''''''>`++++++++/

Prints Fizz and resets memory slot 1 to 3.

                    >'p-``n'''''''''''>`++++++)@'''''''>`++ \

                                 ``P+++++''L@@+++++@++(+++++/

Another div 5 checker to catch FizzBuzzs. Prints out Buzz and resets memory slot 2 to 5.

                              >''P``v
       Hu```P-p'''L@++++++++++LP+p  <

Increments the counter, prints a newline, decrements the loop counter and exits if required.

Source Link
MickyT
  • 12.2k
  • 2
  • 26
  • 48

#Beam, 307 bytes

And now for the longest solution. I think I could compress this a bit more, but the brain is getting a little fried. I'm pretty happy I got it working though.

'''''''''>`+++++++++++)\/)@'''''>`+++++++)@ \
v``P++'P++'P+L```P'''+ /+/+'L@@++(+++++`<'''/
>'p-`n'''''''>`+++++++++/\++Pv
     >'P'p-``n'              >'p-``n'''''''''''>`++++++)@'''''''>`++ \
^       <    >p:L''p-``            >''P``v
       Hu```P-p'''L@++++++++++LP+p       <``P+++++''L@@+++++@++(+++++/

var ITERS_PER_SEC = 100000;
var TIMEOUT_SECS = 50;
var ERROR_INTERRUPT = "Interrupted by user";
var ERROR_TIMEOUT = "Maximum iterations exceeded";
var ERROR_LOSTINSPACE = "Beam is lost in space";

var code, store, beam, ip_x, ip_y, dir, input_ptr, mem;
var input, timeout, width, iterations, running;

function clear_output() {
document.getElementById("output").value = "";
document.getElementById("stderr").innerHTML = "";
}

function stop() {
running = false;
document.getElementById("run").disabled = false;
document.getElementById("stop").disabled = true;
document.getElementById("clear").disabled = false;
document.getElementById("timeout").disabled = false;
}

function interrupt() {
error(ERROR_INTERRUPT);
}

function error(msg) {
document.getElementById("stderr").innerHTML = msg;
stop();
}

function run() {
clear_output();
document.getElementById("run").disabled = true;
document.getElementById("stop").disabled = false;
document.getElementById("clear").disabled = true;
document.getElementById("input").disabled = false;
document.getElementById("timeout").disabled = false;

code = document.getElementById("code").value;
input = document.getElementById("input").value;
timeout = document.getElementById("timeout").checked;
    
code = code.split("\n");
width = 0;
for (var i = 0; i < code.length; ++i){
    if (code[i].length > width){ 
        width = code[i].length;
    }
}
console.log(code);
console.log(width);
    
running = true;
dir = 0;
ip_x = 0;
ip_y = 0;
input_ptr = 0;
beam = 0;
store = 0;
mem = [];
    
input = input.split("").map(function (s) {
        return s.charCodeAt(0);
    });
    
iterations = 0;

beam_iter();
}

function beam_iter() {
while (running) {
    var inst; 
    try {
        inst = code[ip_y][ip_x];
    }
    catch(err) {
        inst = "";
    }
    switch (inst) {
        case ">":
            dir = 0;
            break;
        case "<":
            dir = 1;
            break;
        case "^":
            dir = 2;
            break;
        case "v":
            dir = 3;
            break;
        case "+":
            ++beam;
            break;
        case "-":
            --beam;
            break;
        case "@":
            document.getElementById("output").value += String.fromCharCode(beam);
            break;
        case ":":
            document.getElementById("output").value += beam;
            break;
        case "/":
            dir ^= 2;
            break;
        case "\\":
            dir ^= 3;
            break;
        case "!":
            if (beam != 0) {
                dir ^= 1;
            }
            break;
        case "?":
            if (beam == 0) {
                dir ^= 1;
            }
            break;
        case "|":
            switch (dir) {
            case 2:
                dir = 3;
                break;
            case 3:
                dir = 2;
                break;
            }
            break;
        case "_":
            switch (dir) {
            case 0:
                dir = 1;
                break;
            case 1:
                dir = 0;
                break;
            }
            break;
        case "H":
            stop();
            break;
        case "S":
            store = beam;
            break;
        case "L":
            beam = store;
            break;
        case "s":
            mem[beam] = store;
            break;
        case "g":
            store = mem[beam];
            break;
        case "P":
            mem[store] = beam;
            break;
        case "p":
            beam = mem[store];
            break;
        case "u":
            if (beam != store) {
                dir = 2;
            }
            break;
        case "n":
            if (beam != store) {
                dir = 3;
            }
            break;
        case "`":
            --store;
            break;
        case "'":
            ++store;
            break;
        case ")":
            if (store != 0) {
                dir = 1;
            }
            break;
        case "(":
            if (store != 0) {
                dir = 0;
            }
            break;
        case "r":
            if (input_ptr >= input.length) {
                beam = 0;
            } else {
                beam = input[input_ptr];
                ++input_ptr;
            }
            break;
        }
    // Move instruction pointer
    switch (dir) {
        case 0:
            ip_x++;
            break;
        case 1:
            ip_x--;
            break;
        case 2:
            ip_y--;
            break;
        case 3:
            ip_y++;
            break;
    }
    if (running && (ip_x < 0 || ip_y < 0 || ip_x >= width || ip_y >= code.length)) {
        error(ERROR_LOSTINSPACE);
    }
    ++iterations;
    if (iterations > ITERS_PER_SEC * TIMEOUT_SECS) {
        error(ERROR_TIMEOUT);
    }
}
}
<div style="font-size:12px;font-family:Verdana, Geneva, sans-serif;">Code:
    <br>
    <textarea id="code" rows="6" style="overflow:scroll;overflow-x:hidden;width:90%;">
'''''''''>`+++++++++++)\/)@'''''>`+++++++)@ \
v``P++'P++'P+L```P'''+ /+/+'L@@++(+++++`<'''/
>'p-`n'''''''>`+++++++++/\++Pv
^    >'P'p-``n'              >'p-``n'''''''''''>`++++++)@'''''''>`++ \
^       <    >p:L''p-``            >''P``v
^      Hu```P-p'''L@++++++++++LP+p       <``P+++++''L@@+++++@++(+++++/
    </textarea>
        <br>
        <input id="run" type="button" value="Run" onclick="run()">
        <input id="stop" type="button" value="Stop" onclick="interrupt()" disabled="disabled">
        <input id="clear" type="button" value="Clear" onclick="clear_output()">&nbsp; <span id="stderr" style="color:red"></span>
    </p>Output:
    <br>
    <textarea id="output" rows="6" style="overflow:scroll;width:90%;"></textarea>
    <br>Input:
    <br>
    <textarea id="input" rows="1" style="overflow:scroll;overflow-x:hidden;width:90%;"></textarea>
    <p>Timeout:
        <input id="timeout" type="checkbox" checked="checked">&nbsp;
        <br>    </div>