Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

I've created a new language called "EasyFlow." Your task is to simplify writing BrainFlowBrainFlow programs by compiling EasyFlow to BrainFlow. That is, you take an EasyFlow program and output a BrainFlow program which does the same thing. EasyFlow is defined as follows:

I've created a new language called "EasyFlow." Your task is to simplify writing BrainFlow programs by compiling EasyFlow to BrainFlow. That is, you take an EasyFlow program and output a BrainFlow program which does the same thing. EasyFlow is defined as follows:

I've created a new language called "EasyFlow." Your task is to simplify writing BrainFlow programs by compiling EasyFlow to BrainFlow. That is, you take an EasyFlow program and output a BrainFlow program which does the same thing. EasyFlow is defined as follows:

Notice removed Draw attention by soktinpk
Bounty Ended with COTO's answer chosen by soktinpk
Notice added Draw attention by soktinpk
Bounty Started worth 50 reputation by soktinpk
added 1718 characters in body
Source Link
soktinpk
  • 4.5k
  • 21
  • 47

Here is my attempt in ES6 javascript function at a whopping 561 characters if white space and comments are removed and with no bonuses:

compile=a=>// Defines a function called `compile`
compile = a => {h=a=>
    h = a => {
        for (;a;; a;) {
            // Create a copy of the input string
            var c=a;a=a[R]c = a;
            // Replace print statements with "."
            a = a[R](l, (a, d) => {
                e(d);b+=";
                b += ".";return""";
                return ""
            })[R](m, (a, d) => { // Replace input statements with ","
                e(d);b+=";
                b += ",";return""";
                return ""
            })[R](n, (a, d, c, g) => { // Replace equal to, increment, and decrements
                e(d);b+=;
                b += (c||"[c || "[-]+")+g;return"" + g;
                return ""
            })[R](p, (a, c, f, g) => { // Replace if and while loops
                e(f);b+="[";h;
                b += "[";
                h(g);"if"==c;
                "if" == c ?b+="[>]^" b += "[>]^" : e(f);b+="]";return"";
                b += "]";
                return ""
            });if;
            // If the copy is the same as the input string
            // i.e. no changes were made in replacing, we've reached the end, break
            if (c==ac == a) break
        }
    };e=a=>;
    // A function which moves to the variable location
    e = a => {b+="[>]^";b+=">"+f[a]
        // Go to zeroth position
        b += "[>]^";
        // f[a] is where the variable is located, move there
        b += ">" + f[a]
    };var;
 b=""   var b = "",R="replace";a=a[R]
        R = "replace";
    // Remove comments and whitespace
    a = a[R](/\/\/.*?\n/g, "")[R](/[\s\n\t]+|/g, "");var;
 l=   // Regexes
    var l = /^print\((.*?)\);/,m= // Print statements
        m = /^input\((.*?)\);/,n= // Input statements
        n = /^([a-zA-Z0-9]+)([\+\-]?)=(\d+);/,p= // Assignments
        p = // If and while statements
        /(if|while)\((.*?)\)\{(.*?)\};/,k=a
        k = a.split(";")[0].split(",");a=a; // Get the variables
    a = a.slice(a.indexOf(";")+1 + 1);for; // Strip variables from program
    // Assign each variable a unique index
    for (var f=f = {},c=0;c<k c = 0; c < k.length;++clength; ++c)f[k[c]]=c;h f[k[c]] = c;
    // Compile
    h(a);return;
    return b // Return
};

Here is my attempt in ES6 javascript function at a whopping 561 characters with no bonuses:

compile=a=>{h=a=>{for(;a;){var c=a;a=a[R](l,(a,d)=>{e(d);b+=".";return""})[R](m,(a,d)=>{e(d);b+=",";return""})[R](n,(a,d,c,g)=>{e(d);b+=(c||"[-]+")+g;return""})[R](p,(a,c,f,g)=>{e(f);b+="[";h(g);"if"==c?b+="[>]^":e(f);b+="]";return""});if(c==a)break}};e=a=>{b+="[>]^";b+=">"+f[a]};var b="",R="replace";a=a[R](/\/\/.*?\n/g,"")[R](/[\s\n\t]+|/g,"");var l=/^print\((.*?)\);/,m=/^input\((.*?)\);/,n=/^([a-zA-Z0-9]+)([\+\-]?)=(\d+);/,p=
/(if|while)\((.*?)\)\{(.*?)\};/,k=a.split(";")[0].split(",");a=a.slice(a.indexOf(";")+1);for(var f={},c=0;c<k.length;++c)f[k[c]]=c;h(a);return b};

Here is my attempt in ES6 javascript function at a whopping 561 characters if white space and comments are removed and with no bonuses:

// Defines a function called `compile`
compile = a => {
    h = a => {
        for (; a;) {
            // Create a copy of the input string
            var c = a;
            // Replace print statements with "."
            a = a[R](l, (a, d) => {
                e(d);
                b += ".";
                return ""
            })[R](m, (a, d) => { // Replace input statements with ","
                e(d);
                b += ",";
                return ""
            })[R](n, (a, d, c, g) => { // Replace equal to, increment, and decrements
                e(d);
                b += (c || "[-]+") + g;
                return ""
            })[R](p, (a, c, f, g) => { // Replace if and while loops
                e(f);
                b += "[";
                h(g);
                "if" == c ? b += "[>]^" : e(f);
                b += "]";
                return ""
            });
            // If the copy is the same as the input string
            // i.e. no changes were made in replacing, we've reached the end, break
            if (c == a) break
        }
    };
    // A function which moves to the variable location
    e = a => {
        // Go to zeroth position
        b += "[>]^";
        // f[a] is where the variable is located, move there
        b += ">" + f[a]
    };
    var b = "",
        R = "replace";
    // Remove comments and whitespace
    a = a[R](/\/\/.*?\n/g, "")[R](/[\s\n\t]+|/g, "");
    // Regexes
    var l = /^print\((.*?)\);/, // Print statements
        m = /^input\((.*?)\);/, // Input statements
        n = /^([a-zA-Z0-9]+)([\+\-]?)=(\d+);/, // Assignments
        p = // If and while statements
        /(if|while)\((.*?)\)\{(.*?)\};/,
        k = a.split(";")[0].split(","); // Get the variables
    a = a.slice(a.indexOf(";") + 1); // Strip variables from program
    // Assign each variable a unique index
    for (var f = {}, c = 0; c < k.length; ++c) f[k[c]] = c;
    // Compile
    h(a);
    return b // Return
};
Tweeted twitter.com/#!/StackCodeGolf/status/516386912932995072
added 725 characters in body
Source Link
soktinpk
  • 4.5k
  • 21
  • 47

Here is my attempt in ES6 javascript function at a whopping 561 characters with no bonuses:

compile=a=>{h=a=>{for(;a;){var c=a;a=a[R](l,(a,d)=>{e(d);b+=".";return""})[R](m,(a,d)=>{e(d);b+=",";return""})[R](n,(a,d,c,g)=>{e(d);b+=(c||"[-]+")+g;return""})[R](p,(a,c,f,g)=>{e(f);b+="[";h(g);"if"==c?b+="[>]^":e(f);b+="]";return""});if(c==a)break}};e=a=>{b+="[>]^";b+=">"+f[a]};var b="",R="replace";a=a[R](/\/\/.*?\n/g,"")[R](/[\s\n\t]+|/g,"");var l=/^print\((.*?)\);/,m=/^input\((.*?)\);/,n=/^([a-zA-Z0-9]+)([\+\-]?)=(\d+);/,p=
/(if|while)\((.*?)\)\{(.*?)\};/,k=a.split(";")[0].split(",");a=a.slice(a.indexOf(";")+1);for(var f={},c=0;c<k.length;++c)f[k[c]]=c;h(a);return b};

I'm sure many people can do better!

Here is my attempt in ES6 javascript function at a whopping 561 characters with no bonuses:

compile=a=>{h=a=>{for(;a;){var c=a;a=a[R](l,(a,d)=>{e(d);b+=".";return""})[R](m,(a,d)=>{e(d);b+=",";return""})[R](n,(a,d,c,g)=>{e(d);b+=(c||"[-]+")+g;return""})[R](p,(a,c,f,g)=>{e(f);b+="[";h(g);"if"==c?b+="[>]^":e(f);b+="]";return""});if(c==a)break}};e=a=>{b+="[>]^";b+=">"+f[a]};var b="",R="replace";a=a[R](/\/\/.*?\n/g,"")[R](/[\s\n\t]+|/g,"");var l=/^print\((.*?)\);/,m=/^input\((.*?)\);/,n=/^([a-zA-Z0-9]+)([\+\-]?)=(\d+);/,p=
/(if|while)\((.*?)\)\{(.*?)\};/,k=a.split(";")[0].split(",");a=a.slice(a.indexOf(";")+1);for(var f={},c=0;c<k.length;++c)f[k[c]]=c;h(a);return b};

I'm sure many people can do better!

deleted 6 characters in body
Source Link
soktinpk
  • 4.5k
  • 21
  • 47
Loading
edited tags
Link
Ypnypn
  • 10.9k
  • 2
  • 31
  • 80
Loading
Source Link
soktinpk
  • 4.5k
  • 21
  • 47
Loading