Skip to main content
added 856 characters in body
Source Link
Οurous
  • 8.1k
  • 1
  • 16
  • 38

SQF, 160 bytes

Using the function-as-a-file format:

x=0;y=0;a=[];{switch(_x){case"v":{y=y-1};case"^":{y=y+1};case"<":{x=x-1};case">":{x=x+1};};if([x,y]in a)then{a=a-[[x,y]]}else{a=a+[[x,y]]}}forEach _this;count a

Call as: "STRING" call NAME_OF_COMPILED_FUNCTION

Ungolfed:

//position tracker variables
x = 0; y = 0;
//`a` keeps track of which coords are switched on
a = [];
{
    //switch based on the magic variable `_x`
    //which is the current element of the forEach
    //and adjust coord tracker variables
    switch(_x) {
        case "v": {
            y = y - 1
        };
        case "^": {
            y = y + 1
        };
        case "<": {
            x = x - 1
        };
        case ">": {
            x = x + 1
        };
    };
    //check if the coord is already turned on
    if ([x, y] in a) then {
        //remove it from `a` using array exclusion
        a = a - [[x, y]]
    } else {
        //append it to `a`
        a = a + [[x, y]]
    }
//do this for each character in _this (the argument)
} forEach _this;
//return the length of `a`
count a

SQF, 160 bytes

Using the function-as-a-file format:

x=0;y=0;a=[];{switch(_x){case"v":{y=y-1};case"^":{y=y+1};case"<":{x=x-1};case">":{x=x+1};};if([x,y]in a)then{a=a-[[x,y]]}else{a=a+[[x,y]]}}forEach _this;count a

Call as: "STRING" call NAME_OF_COMPILED_FUNCTION

SQF, 160 bytes

Using the function-as-a-file format:

x=0;y=0;a=[];{switch(_x){case"v":{y=y-1};case"^":{y=y+1};case"<":{x=x-1};case">":{x=x+1};};if([x,y]in a)then{a=a-[[x,y]]}else{a=a+[[x,y]]}}forEach _this;count a

Call as: "STRING" call NAME_OF_COMPILED_FUNCTION

Ungolfed:

//position tracker variables
x = 0; y = 0;
//`a` keeps track of which coords are switched on
a = [];
{
    //switch based on the magic variable `_x`
    //which is the current element of the forEach
    //and adjust coord tracker variables
    switch(_x) {
        case "v": {
            y = y - 1
        };
        case "^": {
            y = y + 1
        };
        case "<": {
            x = x - 1
        };
        case ">": {
            x = x + 1
        };
    };
    //check if the coord is already turned on
    if ([x, y] in a) then {
        //remove it from `a` using array exclusion
        a = a - [[x, y]]
    } else {
        //append it to `a`
        a = a + [[x, y]]
    }
//do this for each character in _this (the argument)
} forEach _this;
//return the length of `a`
count a
Source Link
Οurous
  • 8.1k
  • 1
  • 16
  • 38

SQF, 160 bytes

Using the function-as-a-file format:

x=0;y=0;a=[];{switch(_x){case"v":{y=y-1};case"^":{y=y+1};case"<":{x=x-1};case">":{x=x+1};};if([x,y]in a)then{a=a-[[x,y]]}else{a=a+[[x,y]]}}forEach _this;count a

Call as: "STRING" call NAME_OF_COMPILED_FUNCTION