Search

lundi 20 mars 2017

Multiquine: final (4)

Context
Previous post  already presented the CS code template.
Now, here is the JS one
/*BOOTSTRAP*/
(function(language){
 var quote = String.fromCharCode(34), backslash = String.fromCharCode(92), newline = backslash + String.fromCharCode(114) + backslash + String.fromCharCode(110);
 var data =
 {
/*DATA*/
  cs: "CS_CODE_PLACEHOLDER",
  js: "JS_CODE_PLACEHOLDER",
  bf: "BF_CODE_PLACEHOLDER",
/*CODE*/
 };

 if(!language) language = 'js';
 var code = data[language];
 var bootstraps =
 {
   js: 'JS_BOOTSTRAP_PLACEHOLDER',
   cs: 'CS_BOOTSTRAP_PLACEHOLDER',
   bf: 'BF_BOOTSTRAP_PLACEHOLDER',
 }
 var res = bootstraps[language]
 switch(language)
 {
  case 'js':
   for(var i in data) res += ' ' + i + ': ' + quote + data[i].replace(new RegExp('\\\\', 'g'), backslash + backslash).replace(new RegExp(quote, 'g'), backslash + quote).replace(new RegExp(newline, 'g'), backslash + 'r' + backslash + 'n') + quote + ',\r\n';
   break;
  case 'cs':
   for(var i in data) res += ' data.Add(' + quote + i + quote + ', ' + quote + data[i].replace(new RegExp('\\\\', 'g'), backslash + backslash).replace(new RegExp(quote, 'g'), backslash + quote).replace(new RegExp(newline, 'g'), backslash + 'r' + backslash + 'n') + quote + ');\r\n';
   break;
  case 'bf':
   for(var i in data)
   {
     for (var j = 0; j < i.length; j++) { if (i.charCodeAt(j) == 13) continue; res += "+".repeat(i.charCodeAt(j)); res += '>'; }
res += '>';
for (var j = 0; j < data[i].length; j++) { if (data[i].charCodeAt(j) == 13) continue; res += "+".repeat(data[i].charCodeAt(j)); res += '>'; }
res += '>';
   }
   res += '\r\n';
 }
 res += code;
 console.log(res);
})()

Not really different from the C# version... Now, here is the BF one:
/*BOOTSTRAP*/
>>>>
/*DATA*/
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>CS_CODE_PLACEHOLDER>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>JS_CODE_PLACEHOLDER>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>BF_CODE_PLACEHOLDER>
/*CODE*/
,>+<[>+++++++++[-<---------->]+<+[[-]>-<JS_BOOTSTRAP_PLACEHOLDER<<<[[<]<]>>[<++++++++[-<++++>]<..>>[<+>----------[------------------------[<++++++++++++++[->----<]+>++[<++++++++++++[->+++++++<]>+.[-<<+>>]]<[++++++++++++[-<+++++++>]<+..>]>]<[++++++++++++[->+++++++<]>+.[-]<<++++++++++++++++++++++++++++++++++.>]>]<[->+++++[-<++++++++++++++++>]<++++++++++++.++++++++++++++++++++++.----------------------.++++++++++++++++++.[-]<++++++++++>]>>]+++[-<++++++++++++++++>]<++++++++++.--------------------------.++.[-]>>[<+>----------[------------------------[<++++++++++++++[->----<]+>++[<++++++++++++[->+++++++<]>+.[-<<+>>]]<[++++++++++++[-<+++++++>]<+..>]>]<[++++++++++++[->+++++++<]>+.[-]<<++++++++++++++++++++++++++++++++++.>]>]<[->+++++[-<++++++++++++++++>]<++++++++++++.++++++++++++++++++++++.----------------------.++++++++++++++++++.[-]<++++++++++>]>>]++[-<++++++++++++++++>]<++.++++++++++.[-]++++++++++.[-]>>]<<<<[[<]<]>>[>]>[>]>[>]>[.>]>[>]>[>]>>>]>[-CS_BOOTSTRAP_PLACEHOLDER<<<[[<]<]>>[<++[-<++++++++++++++++>]<............[-]>++++++[-<++++++++++++++++>]<++++.---.+++++++++++++++++++.-------------------.[-]>++[-<++++++++++++++++>]<++++++++++++++.+++++++++++++++++++.+++++++++++++++++++++++++++++++++++..[-]>++[-<++++++++++++++++>]<++++++++.------.[-]>>[<+>----------[------------------------[<++++++++++++++[->----<]+>++[<++++++++++++[->+++++++<]>+.[-<<+>>]]<[++++++++++++[-<+++++++>]<+..>]>]<[++++++++++++[->+++++++<]>+.[-]<<++++++++++++++++++++++++++++++++++.>]>]<[->+++++[-<++++++++++++++++>]<++++++++++++.++++++++++++++++++++++.----------------------.++++++++++++++++++.[-]<++++++++++>]>>]++[-<++++++++++++++++>]<++.++++++++++.------------.++.[-]>>[<+>----------[------------------------[<++++++++++++++[->----<]+>++[<++++++++++++[->+++++++<]>+.[-<<+>>]]<[++++++++++++[-<+++++++>]<+..>]>]<[++++++++++++[->+++++++<]>+.[-]<<++++++++++++++++++++++++++++++++++.>]>]<[->+++++[-<++++++++++++++++>]<++++++++++++.++++++++++++++++++++++.----------------------.++++++++++++++++++.[-]<++++++++++>]>>]++[-<++++++++++++++++>]<++.+++++++.++++++++++++++++++.[-]++++++++++.[-]>>]<<<<[[<]<]>>[>]>[.>]>[[>]>]>>>]<]>[-<<<[[<]<]+++[-<+++++++>]<[->++>+++<<]>+>-....<<++++++++++.[-]>>>[[[[-<<.<+>>>]<.[->+<]<[->+<]>>>]<.[->+<]<[->+<]>>>]]<<<<<[<]++++++++++.[-]>[.>]]
 

Hum. Hum. Sigh...
Ok. Let's analyze.

  • Bootstrap: leave some free space.
  • Data: write "cs", leave a cell, write CS DATA (placeholder), then write "js", leave a cell, write JS DATA (placeholder), and finally write "bf", leave a cell, write BF DATA (... ?)
  • Code: read input
      • No entry : that's BF. Write BF bootstrap (>>>>), then go the the first data cell, copy data declaration (leave a cell when needed), go to BF part of the data and print as text
      • Input = "c" : that's CS. Write CS bootstrap, then go the first data cell, write '      data.Add("', then language name, then '", "', then language code (from data), by replacing " by \", \ by \\ and line breaks by \r\n. Finally, go to CS part of the data and print as text (change line breaks to real line breaks)
      • Otherwise: that's JS (and globally same as CS...)
The final part to our quine implementation would be to create a generation tool (that read templates, and inject bootstraps / code into each template to create final codes).
That's what I did, but it's clearly out of scope for this post.

Code - CS

using System;
using System.Collections.Generic;
using System.Text;

namespace Multiquine
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<string, string> data = new Dictionary<string, string>();
            data.Add("cs", " string language = args.Length == 0 ? \"cs\" : args[0];\r\n string code = data[language];\r\n Dictionary<string, string> bootstraps = new Dictionary<string, string>();\r\n bootstraps.Add(\"cs\", \"using System;\\r\\nusing System.Collections.Generic;\\r\\nusing System.Text;\\r\\n\\r\\nnamespace Multiquine\\r\\n{\\r\\n class Program\\r\\n {\\r\\n static void Main(string[] args)\\r\\n {\\r\\n Dictionary<string, string> data = new Dictionary<string, string>();\\r\\n\");\r\n bootstraps.Add(\"js\", \"(function(language){\\r\\n var quote = String.fromCharCode(34), backslash = String.fromCharCode(92), newline = backslash + String.fromCharCode(114) + backslash + String.fromCharCode(110);\\r\\n var data = \\r\\n {\\r\\n\");\r\n bootstraps.Add(\"bf\", \">>>>\\r\\n\");\r\n Dictionary<string, string> dataAdd = new Dictionary<string, string>();\r\n dataAdd.Add(\"cs\", \" data.Add(\\\"{0}\\\", \\\"{1}\\\");\" + Environment.NewLine);\r\n dataAdd.Add(\"js\", \" {0}: \\\"{1}\\\",\" + Environment.NewLine);\r\n string res = bootstraps[language];\r\n if (language == \"bf\")\r\n {\r\n StringBuilder sb = new StringBuilder();\r\n foreach (string key in data.Keys)\r\n {\r\n foreach (char c in key)\r\n {\r\n if (c == '\\n') continue;\r\n if (c == '\\r')\r\n {\r\n sb.Append(\"++++++++++>\");\r\n continue;\r\n }\r\n sb.Append(new string('+', (int)c) + \">\");\r\n }\r\n sb.Append(\">\");\r\n foreach (char c in data[key])\r\n {\r\n if (c == '\\n') continue;\r\n if (c == '\\r')\r\n {\r\n sb.Append(\"++++++++++>\");\r\n continue;\r\n }\r\n sb.Append(new string('+', (int)c) + \">\");\r\n }\r\n sb.Append(\">\");\r\n }\r\n res += sb.ToString() + Environment.NewLine;\r\n }\r\n else\r\n {\r\n foreach (string key in data.Keys)\r\n res += String.Format(dataAdd[language], key, data[key].Replace(\"\\\\\", \"\\\\\\\\\").Replace(\"\\\"\", \"\\\\\\\"\").Replace(Environment.NewLine, @\"\\r\\n\"));\r\n }\r\n res += code;\r\n Console.Write(res);\r\n }\r\n }\r\n}");
            data.Add("js", " };\r\n\r\n if(!language) language = 'js';\r\n var code = data[language];\r\n var bootstraps = \r\n {\r\n js: '(function(language){\\r\\n var quote = String.fromCharCode(34), backslash = String.fromCharCode(92), newline = backslash + String.fromCharCode(114) + backslash + String.fromCharCode(110);\\r\\n var data = \\r\\n {\\r\\n',\r\n cs: 'using System;\\r\\nusing System.Collections.Generic;\\r\\nusing System.Text;\\r\\n\\r\\nnamespace Multiquine\\r\\n{\\r\\n class Program\\r\\n {\\r\\n static void Main(string[] args)\\r\\n {\\r\\n Dictionary<string, string> data = new Dictionary<string, string>();\\r\\n',\r\n bf: '>>>>\\r\\n',\r\n }\r\n var res = bootstraps[language]\r\n switch(language)\r\n {\r\n case 'js':\r\n for(var i in data) res += ' ' + i + ': ' + quote + data[i].replace(new RegExp('\\\\\\\\', 'g'), backslash + backslash).replace(new RegExp(quote, 'g'), backslash + quote).replace(new RegExp(newline, 'g'), backslash + 'r' + backslash + 'n') + quote + ',\\r\\n';\r\n break;\r\n case 'cs':\r\n for(var i in data) res += ' data.Add(' + quote + i + quote + ', ' + quote + data[i].replace(new RegExp('\\\\\\\\', 'g'), backslash + backslash).replace(new RegExp(quote, 'g'), backslash + quote).replace(new RegExp(newline, 'g'), backslash + 'r' + backslash + 'n') + quote + ');\\r\\n';\r\n break;\r\n case 'bf':\r\n for(var i in data)\r\n {\r\n for (var j = 0; j < i.length; j++) { if (i.charCodeAt(j) == 13) continue; res += \"+\".repeat(i.charCodeAt(j)); res += '>'; }\r\n res += '>';\r\n for (var j = 0; j < data[i].length; j++) { if (data[i].charCodeAt(j) == 13) continue; res += \"+\".repeat(data[i].charCodeAt(j)); res += '>'; }\r\n res += '>';\r\n }\r\n res += '\\r\\n';\r\n }\r\n res += code;\r\n console.log(res);\r\n})()");
            data.Add("bf", ",>+<[>+++++++++[-<---------->]+<+[[-]>-<[-]>++[-<++++++++++++++++>]<++++++++.[-]>++++++[-<++++++++++++++++>]<++++++.+++++++++++++++.-------.-----------.+++++++++++++++++.-----------.++++++.-.[-]>++[-<++++++++++++++++>]<++++++++.[-]>++++++[-<++++++++++++++++>]<++++++++++++.-----------.+++++++++++++.-------.++++++++++++++.--------------------.++++++.--.[-]>++[-<++++++++++++++++>]<+++++++++.[-]>+++++++[-<++++++++++++++++>]<+++++++++++.[-]++++++++++.++++++++++++++++++++++.[-]>+++++++[-<++++++++++++++++>]<++++++.---------------------.+++++++++++++++++.[-]>++[-<++++++++++++++++>]<.[-]>+++++++[-<++++++++++++++++>]<+.++++.------.+++++.---------------.[-]>++[-<++++++++++++++++>]<.+++++++++++++++++++++++++++++.[-]>++[-<++++++++++++++++>]<.[-]>+++++[-<++++++++++++++++>]<+++.+++++++++++++++++++++++++++++++++.--.---------.+++++.-------.[-]>++[-<++++++++++++++++>]<++++++++++++++.[-]>++++++[-<++++++++++++++++>]<++++++.++++++++++++.---.--.[-]>++++[-<++++++++++++++++>]<+++.+++++++++++++++++++++++++++++++++++++.-------.+++++++++++++++++.[-]>++++[-<++++++++++++++++>]<+++.++++++++++++++++++++++++++++++++++++++++++++.-----------.+.[-]>++[-<++++++++++++++++>]<++++++++.+++++++++++.+.-----------.+++.------------.[-]>++++++[-<++++++++++++++++>]<++.-.++.++++++++.++++++++.-------.-----------.++++++++++++++++++.-----------.[-]>++[-<++++++++++++++++>]<.+++++++++++++++++++++++++++++.[-]>++[-<++++++++++++++++>]<.[-]>+++++[-<++++++++++++++++>]<+++.+++++++++++++++++++++++++++++++++.--.---------.+++++.-------.[-]>++[-<++++++++++++++++>]<++++++++++++++.[-]>++++++[-<++++++++++++++++>]<++++++.++++++++++++.---.--.[-]>++++[-<++++++++++++++++>]<+++.+++++++++++++++++++++++++++++++++++++.-------.+++++++++++++++++.[-]>++++[-<++++++++++++++++>]<+++.++++++++++++++++++++++++++++++++++++++++++++.-----------.+.[-]>++[-<++++++++++++++++>]<++++++++.+++++++++++++++++.-------.---------.+++.------------.[-]>++++++[-<++++++++++++++++>]<++++++++++++++.---------.++++++++++++++++++.-----------.---.+++++.---------.[-]>++[-<++++++++++++++++>]<.+++++++++++++++++++++++++++++.[-]>++[-<++++++++++++++++>]<.[-]>++++++[-<++++++++++++++++>]<++.-.++.++++++++.++++++++.-------.-----------.++++++++++++++++++.-----------.[-]>++[-<++++++++++++++++>]<.+++++++++++.-----------.[-]>+++++[-<++++++++++++++++>]<+++.+++++++++++++++++++++++++++++++++.--.---------.+++++.-------.[-]>++[-<++++++++++++++++>]<++++++++++++++.[-]>++++++[-<++++++++++++++++>]<++++++.++++++++++++.---.--.[-]>++++[-<++++++++++++++++>]<+++.+++++++++++++++++++++++++++++++++++++.-------.+++++++++++++++++.[-]>++++[-<++++++++++++++++>]<+++.++++++++++++++++++++++++++++++++++++++++++++.-----------.+.[-]>++[-<++++++++++++++++>]<++++++++.+++++++++..+++.-----------.---------.+++++++++++.-----------.[-]>++++++[-<++++++++++++++++>]<++.-.++.++++++++.++++++++.-------.-----------.++++++++++++++++++.-----------.[-]>++[-<++++++++++++++++>]<.+++++++++++.-----------.[-]>+++++[-<++++++++++++++++>]<+++.+++++++++++++++++++++++++++++++++.--.---------.+++++.-------.[-]>++[-<++++++++++++++++>]<++++++++++++++.[-]>++++++[-<++++++++++++++++>]<++++++.++++++++++++.---.--.[-]>++++[-<++++++++++++++++>]<+++.+++++++++++++++++++++++++++++++++++++.-------.+++++++++++++++++.[-]>++++[-<++++++++++++++++>]<+++.++++++++++++++++++++++++++++++++++++++++++++.-----------.+.[-]>++[-<++++++++++++++++>]<++++++++.+++++++++..-.-------.++++++++++++++++++.[-]++++++++++.++++++++++++++++++++++.[-]>+++++++[-<++++++++++++++++>]<++++++.---------------------.+++++++++++++++++.[-]>++[-<++++++++++++++++>]<.[-]>++++++[-<++++++++++++++++>]<++++.---.+++++++++++++++++++.-------------------.[-]>++[-<++++++++++++++++>]<.+++++++++++++++++++++++++++++.[-]>++[-<++++++++++++++++>]<.[-]++++++++++.++++++++++++++++++++++.[-]>+++++++[-<++++++++++++++++>]<+++++++++++.[-]++++++++++.[-]<<<[[<]<]>>[<++++++++[-<++++>]<..>>[<+>----------[------------------------[<++++++++++++++[->----<]+>++[<++++++++++++[->+++++++<]>+.[-<<+>>]]<[++++++++++++[-<+++++++>]<+..>]>]<[++++++++++++[->+++++++<]>+.[-]<<++++++++++++++++++++++++++++++++++.>]>]<[->+++++[-<++++++++++++++++>]<++++++++++++.++++++++++++++++++++++.----------------------.++++++++++++++++++.[-]<++++++++++>]>>]+++[-<++++++++++++++++>]<++++++++++.--------------------------.++.[-]>>[<+>----------[------------------------[<++++++++++++++[->----<]+>++[<++++++++++++[->+++++++<]>+.[-<<+>>]]<[++++++++++++[-<+++++++>]<+..>]>]<[++++++++++++[->+++++++<]>+.[-]<<++++++++++++++++++++++++++++++++++.>]>]<[->+++++[-<++++++++++++++++>]<++++++++++++.++++++++++++++++++++++.----------------------.++++++++++++++++++.[-]<++++++++++>]>>]++[-<++++++++++++++++>]<++.++++++++++.[-]++++++++++.[-]>>]<<<<[[<]<]>>[>]>[>]>[>]>[.>]>[>]>[>]>>>]>[-[-]>+++++++[-<++++++++++++++++>]<+++++.--.----------.+++++.-------.[-]>++[-<++++++++++++++++>]<.[-]>+++++[-<++++++++++++++++>]<+++.++++++++++++++++++++++++++++++++++++++.------.+.---------------.++++++++.[-]>+++[-<++++++++++++++++>]<+++++++++++.[-]++++++++++.[-]>+++++++[-<++++++++++++++++>]<+++++.--.----------.+++++.-------.[-]>++[-<++++++++++++++++>]<.[-]>+++++[-<++++++++++++++++>]<+++.++++++++++++++++++++++++++++++++++++++.------.+.---------------.++++++++.[-]>++[-<++++++++++++++++>]<++++++++++++++.+++++++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++.---..-------.--.+++++++++++++++++.-----------.++++++.-.+++++.[-]>++[-<++++++++++++++++>]<++++++++++++++.+++++++++++++++++++++++++.++++++++++++++++++++++++++++++.+++++++++.---------.+++++++++++++.---------.------.[-]>+++[-<++++++++++++++++>]<+++++++++++.[-]++++++++++.[-]>+++++++[-<++++++++++++++++>]<+++++.--.----------.+++++.-------.[-]>++[-<++++++++++++++++>]<.[-]>+++++[-<++++++++++++++++>]<+++.++++++++++++++++++++++++++++++++++++++.------.+.---------------.++++++++.[-]>++[-<++++++++++++++++>]<++++++++++++++.[-]>+++++[-<++++++++++++++++>]<++++.+++++++++++++++++.+++++++++++++++++++.----.[-]>+++[-<++++++++++++++++>]<+++++++++++.[-]++++++++++.[-]++++++++++.[-]>++++++[-<++++++++++++++++>]<++++++++++++++.-------------.++++++++++++.--------.++++++++++++++.---.---------------.++.++.[-]>++[-<++++++++++++++++>]<.[-]>++++[-<++++++++++++++++>]<+++++++++++++.[-]>+++++++[-<++++++++++++++++>]<+++++.---------.++++++++.-----------.++++++++.++++.------------.+++++.---------.[-]++++++++++.[-]>+++++++[-<++++++++++++++++>]<+++++++++++.[-]++++++++++.++++++++++++++++++++++....[-]>++++++[-<++++++++++++++++>]<+++.+++++++++.-----------.++++++++++++++++++..[-]>++[-<++++++++++++++++>]<.[-]>+++++[-<++++++++++++++++>]<.++++++++++++++++++++++++++++++++++.---.--------.+++++++++++.-----------------.++++++++++++.[-]++++++++++.++++++++++++++++++++++....[-]>+++++++[-<++++++++++++++++>]<+++++++++++.[-]++++++++++.++++++++++++++++++++++........[-]>+++++++[-<++++++++++++++++>]<+++.+.-------------------.+++++++++++++++++++.-----------.------.[-]>++[-<++++++++++++++++>]<.[-]>+++++++[-<++++++++++++++++>]<++++++.-------.------.-----.[-]>++[-<++++++++++++++++>]<.[-]>++++[-<++++++++++++++++>]<+++++++++++++.++++++++++++++++++++.++++++++.+++++.[-]>++[-<++++++++++++++++>]<++++++++.[-]>+++++++[-<++++++++++++++++>]<+++.+.--.---------.+++++.-------.------------.++.[-]>++[-<++++++++++++++++>]<.[-]>++++++[-<++++++++++++++++>]<+.+++++++++++++++++.-----------.++++++++++++.[-]>++[-<++++++++++++++++>]<+++++++++.[-]++++++++++.++++++++++++++++++++++........[-]>+++++++[-<++++++++++++++++>]<+++++++++++.[-]++++++++++.++++++++++++++++++++++............[-]>++++[-<++++++++++++++++>]<++++.+++++++++++++++++++++++++++++++++++++.------.+++++++++++++++++.-----------.++++++.-.-------------.+++++++++++++++++.+++++++.[-]>+++[-<++++++++++++++++>]<++++++++++++.[-]>+++++++[-<++++++++++++++++>]<+++.+.--.---------.+++++.-------.[-]>++[-<++++++++++++++++>]<++++++++++++.------------.[-]>+++++++[-<++++++++++++++++>]<+++.+.--.---------.+++++.-------.-----------------------------------------.[-]>++[-<++++++++++++++++>]<.[-]>++++++[-<++++++++++++++++>]<++++.---.+++++++++++++++++++.-------------------.[-]>++[-<++++++++++++++++>]<.+++++++++++++++++++++++++++++.[-]>++[-<++++++++++++++++>]<.[-]>++++++[-<++++++++++++++++>]<++++++++++++++.---------.++++++++++++++++++.[-]>++[-<++++++++++++++++>]<.[-]>++++[-<++++++++++++++++>]<++++.+++++++++++++++++++++++++++++++++++++.------.+++++++++++++++++.-----------.++++++.-.-------------.+++++++++++++++++.+++++++.[-]>+++[-<++++++++++++++++>]<++++++++++++.[-]>+++++++[-<++++++++++++++++>]<+++.+.--.---------.+++++.-------.[-]>++[-<++++++++++++++++>]<++++++++++++.------------.[-]>+++++++[-<++++++++++++++++>]<+++.+.--.---------.+++++.-------.-----------------------------------------.----------------------.+.++++++++++++++++++.[-]++++++++++.[-]<<<[[<]<]>>[<++[-<++++++++++++++++>]<............[-]>++++++[-<++++++++++++++++>]<++++.---.+++++++++++++++++++.-------------------.[-]>++[-<++++++++++++++++>]<++++++++++++++.+++++++++++++++++++.+++++++++++++++++++++++++++++++++++..[-]>++[-<++++++++++++++++>]<++++++++.------.[-]>>[<+>----------[------------------------[<++++++++++++++[->----<]+>++[<++++++++++++[->+++++++<]>+.[-<<+>>]]<[++++++++++++[-<+++++++>]<+..>]>]<[++++++++++++[->+++++++<]>+.[-]<<++++++++++++++++++++++++++++++++++.>]>]<[->+++++[-<++++++++++++++++>]<++++++++++++.++++++++++++++++++++++.----------------------.++++++++++++++++++.[-]<++++++++++>]>>]++[-<++++++++++++++++>]<++.++++++++++.------------.++.[-]>>[<+>----------[------------------------[<++++++++++++++[->----<]+>++[<++++++++++++[->+++++++<]>+.[-<<+>>]]<[++++++++++++[-<+++++++>]<+..>]>]<[++++++++++++[->+++++++<]>+.[-]<<++++++++++++++++++++++++++++++++++.>]>]<[->+++++[-<++++++++++++++++>]<++++++++++++.++++++++++++++++++++++.----------------------.++++++++++++++++++.[-]<++++++++++>]>>]++[-<++++++++++++++++>]<++.+++++++.++++++++++++++++++.[-]++++++++++.[-]>>]<<<<[[<]<]>>[>]>[.>]>[[>]>]>>>]<]>[-<<<[[<]<]+++[-<+++++++>]<[->++>+++<<]>+>-....<<++++++++++.[-]>>>[[[[-<<.<+>>>]<.[->+<]<[->+<]>>>]<.[->+<]<[->+<]>>>]]<<<<<[<]++++++++++.[-]>[.>]]");
            string language = args.Length == 0 ? "cs" : args[0];
            string code = data[language];
            Dictionary<string, string> bootstraps = new Dictionary<string, string>();
            bootstraps.Add("cs", "using System;\r\nusing System.Collections.Generic;\r\nusing System.Text;\r\n\r\nnamespace Multiquine\r\n{\r\n class Program\r\n {\r\n static void Main(string[] args)\r\n {\r\n Dictionary<string, string> data = new Dictionary<string, string>();\r\n");
            bootstraps.Add("js", "(function(language){\r\n var quote = String.fromCharCode(34), backslash = String.fromCharCode(92), newline = backslash + String.fromCharCode(114) + backslash + String.fromCharCode(110);\r\n var data = \r\n {\r\n");
            bootstraps.Add("bf", ">>>>\r\n");
            Dictionary<string, string> dataAdd = new Dictionary<string, string>();
            dataAdd.Add("cs", " data.Add(\"{0}\", \"{1}\");" + Environment.NewLine);
            dataAdd.Add("js", " {0}: \"{1}\"," + Environment.NewLine);
            string res = bootstraps[language];
            if (language == "bf")
            {
                StringBuilder sb = new StringBuilder();
                foreach (string key in data.Keys)
                {
                    foreach (char c in key)
                    {
                        if (c == '\n') continue;
                        if (c == '\r')
                        {
                            sb.Append("++++++++++>");
                            continue;
                        }
                        sb.Append(new string('+', (int)c) + ">");
                    }
                    sb.Append(">");
                    foreach (char c in data[key])
                    {
                        if (c == '\n') continue;
                        if (c == '\r')
                        {
                            sb.Append("++++++++++>");
                            continue;
                        }
                        sb.Append(new string('+', (int)c) + ">");
                    }
                    sb.Append(">");
                }
                res += sb.ToString() + Environment.NewLine;
            }
            else
            {
                foreach (string key in data.Keys)
                    res += String.Format(dataAdd[language], key, data[key].Replace("\\", "\\\\").Replace("\"", "\\\"").Replace(Environment.NewLine, @"\r\n"));
            }
            res += code;
            Console.Write(res);
        }
    }
}

Code - JS

(function(language){
 var quote = String.fromCharCode(34), backslash = String.fromCharCode(92), newline = backslash + String.fromCharCode(114) + backslash + String.fromCharCode(110);
 var data =
 {
 cs: " string language = args.Length == 0 ? \"cs\" : args[0];\r\n string code = data[language];\r\n Dictionary<string, string> bootstraps = new Dictionary<string, string>();\r\n bootstraps.Add(\"cs\", \"using System;\\r\\nusing System.Collections.Generic;\\r\\nusing System.Text;\\r\\n\\r\\nnamespace Multiquine\\r\\n{\\r\\n class Program\\r\\n {\\r\\n static void Main(string[] args)\\r\\n {\\r\\n Dictionary<string, string> data = new Dictionary<string, string>();\\r\\n\");\r\n bootstraps.Add(\"js\", \"(function(language){\\r\\n var quote = String.fromCharCode(34), backslash = String.fromCharCode(92), newline = backslash + String.fromCharCode(114) + backslash + String.fromCharCode(110);\\r\\n var data = \\r\\n {\\r\\n\");\r\n bootstraps.Add(\"bf\", \">>>>\\r\\n\");\r\n Dictionary<string, string> dataAdd = new Dictionary<string, string>();\r\n dataAdd.Add(\"cs\", \" data.Add(\\\"{0}\\\", \\\"{1}\\\");\" + Environment.NewLine);\r\n dataAdd.Add(\"js\", \" {0}: \\\"{1}\\\",\" + Environment.NewLine);\r\n string res = bootstraps[language];\r\n if (language == \"bf\")\r\n {\r\n StringBuilder sb = new StringBuilder();\r\n foreach (string key in data.Keys)\r\n {\r\n foreach (char c in key)\r\n {\r\n if (c == '\\n') continue;\r\n if (c == '\\r')\r\n {\r\n sb.Append(\"++++++++++>\");\r\n continue;\r\n }\r\n sb.Append(new string('+', (int)c) + \">\");\r\n }\r\n sb.Append(\">\");\r\n foreach (char c in data[key])\r\n {\r\n if (c == '\\n') continue;\r\n if (c == '\\r')\r\n {\r\n sb.Append(\"++++++++++>\");\r\n continue;\r\n }\r\n sb.Append(new string('+', (int)c) + \">\");\r\n }\r\n sb.Append(\">\");\r\n }\r\n res += sb.ToString() + Environment.NewLine;\r\n }\r\n else\r\n {\r\n foreach (string key in data.Keys)\r\n res += String.Format(dataAdd[language], key, data[key].Replace(\"\\\\\", \"\\\\\\\\\").Replace(\"\\\"\", \"\\\\\\\"\").Replace(Environment.NewLine, @\"\\r\\n\"));\r\n }\r\n res += code;\r\n Console.Write(res);\r\n }\r\n }\r\n}",
 js: " };\r\n\r\n if(!language) language = 'js';\r\n var code = data[language];\r\n var bootstraps = \r\n {\r\n js: '(function(language){\\r\\n var quote = String.fromCharCode(34), backslash = String.fromCharCode(92), newline = backslash + String.fromCharCode(114) + backslash + String.fromCharCode(110);\\r\\n var data = \\r\\n {\\r\\n',\r\n cs: 'using System;\\r\\nusing System.Collections.Generic;\\r\\nusing System.Text;\\r\\n\\r\\nnamespace Multiquine\\r\\n{\\r\\n class Program\\r\\n {\\r\\n static void Main(string[] args)\\r\\n {\\r\\n Dictionary<string, string> data = new Dictionary<string, string>();\\r\\n',\r\n bf: '>>>>\\r\\n',\r\n }\r\n var res = bootstraps[language]\r\n switch(language)\r\n {\r\n case 'js':\r\n for(var i in data) res += ' ' + i + ': ' + quote + data[i].replace(new RegExp('\\\\\\\\', 'g'), backslash + backslash).replace(new RegExp(quote, 'g'), backslash + quote).replace(new RegExp(newline, 'g'), backslash + 'r' + backslash + 'n') + quote + ',\\r\\n';\r\n break;\r\n case 'cs':\r\n for(var i in data) res += ' data.Add(' + quote + i + quote + ', ' + quote + data[i].replace(new RegExp('\\\\\\\\', 'g'), backslash + backslash).replace(new RegExp(quote, 'g'), backslash + quote).replace(new RegExp(newline, 'g'), backslash + 'r' + backslash + 'n') + quote + ');\\r\\n';\r\n break;\r\n case 'bf':\r\n for(var i in data)\r\n {\r\n for (var j = 0; j < i.length; j++) { if (i.charCodeAt(j) == 13) continue; res += \"+\".repeat(i.charCodeAt(j)); res += '>'; }\r\n res += '>';\r\n for (var j = 0; j < data[i].length; j++) { if (data[i].charCodeAt(j) == 13) continue; res += \"+\".repeat(data[i].charCodeAt(j)); res += '>'; }\r\n res += '>';\r\n }\r\n res += '\\r\\n';\r\n }\r\n res += code;\r\n console.log(res);\r\n})()",
 bf: ",>+<[>+++++++++[-<---------->]+<+[[-]>-<[-]>++[-<++++++++++++++++>]<++++++++.[-]>++++++[-<++++++++++++++++>]<++++++.+++++++++++++++.-------.-----------.+++++++++++++++++.-----------.++++++.-.[-]>++[-<++++++++++++++++>]<++++++++.[-]>++++++[-<++++++++++++++++>]<++++++++++++.-----------.+++++++++++++.-------.++++++++++++++.--------------------.++++++.--.[-]>++[-<++++++++++++++++>]<+++++++++.[-]>+++++++[-<++++++++++++++++>]<+++++++++++.[-]++++++++++.++++++++++++++++++++++.[-]>+++++++[-<++++++++++++++++>]<++++++.---------------------.+++++++++++++++++.[-]>++[-<++++++++++++++++>]<.[-]>+++++++[-<++++++++++++++++>]<+.++++.------.+++++.---------------.[-]>++[-<++++++++++++++++>]<.+++++++++++++++++++++++++++++.[-]>++[-<++++++++++++++++>]<.[-]>+++++[-<++++++++++++++++>]<+++.+++++++++++++++++++++++++++++++++.--.---------.+++++.-------.[-]>++[-<++++++++++++++++>]<++++++++++++++.[-]>++++++[-<++++++++++++++++>]<++++++.++++++++++++.---.--.[-]>++++[-<++++++++++++++++>]<+++.+++++++++++++++++++++++++++++++++++++.-------.+++++++++++++++++.[-]>++++[-<++++++++++++++++>]<+++.++++++++++++++++++++++++++++++++++++++++++++.-----------.+.[-]>++[-<++++++++++++++++>]<++++++++.+++++++++++.+.-----------.+++.------------.[-]>++++++[-<++++++++++++++++>]<++.-.++.++++++++.++++++++.-------.-----------.++++++++++++++++++.-----------.[-]>++[-<++++++++++++++++>]<.+++++++++++++++++++++++++++++.[-]>++[-<++++++++++++++++>]<.[-]>+++++[-<++++++++++++++++>]<+++.+++++++++++++++++++++++++++++++++.--.---------.+++++.-------.[-]>++[-<++++++++++++++++>]<++++++++++++++.[-]>++++++[-<++++++++++++++++>]<++++++.++++++++++++.---.--.[-]>++++[-<++++++++++++++++>]<+++.+++++++++++++++++++++++++++++++++++++.-------.+++++++++++++++++.[-]>++++[-<++++++++++++++++>]<+++.++++++++++++++++++++++++++++++++++++++++++++.-----------.+.[-]>++[-<++++++++++++++++>]<++++++++.+++++++++++++++++.-------.---------.+++.------------.[-]>++++++[-<++++++++++++++++>]<++++++++++++++.---------.++++++++++++++++++.-----------.---.+++++.---------.[-]>++[-<++++++++++++++++>]<.+++++++++++++++++++++++++++++.[-]>++[-<++++++++++++++++>]<.[-]>++++++[-<++++++++++++++++>]<++.-.++.++++++++.++++++++.-------.-----------.++++++++++++++++++.-----------.[-]>++[-<++++++++++++++++>]<.+++++++++++.-----------.[-]>+++++[-<++++++++++++++++>]<+++.+++++++++++++++++++++++++++++++++.--.---------.+++++.-------.[-]>++[-<++++++++++++++++>]<++++++++++++++.[-]>++++++[-<++++++++++++++++>]<++++++.++++++++++++.---.--.[-]>++++[-<++++++++++++++++>]<+++.+++++++++++++++++++++++++++++++++++++.-------.+++++++++++++++++.[-]>++++[-<++++++++++++++++>]<+++.++++++++++++++++++++++++++++++++++++++++++++.-----------.+.[-]>++[-<++++++++++++++++>]<++++++++.+++++++++..+++.-----------.---------.+++++++++++.-----------.[-]>++++++[-<++++++++++++++++>]<++.-.++.++++++++.++++++++.-------.-----------.++++++++++++++++++.-----------.[-]>++[-<++++++++++++++++>]<.+++++++++++.-----------.[-]>+++++[-<++++++++++++++++>]<+++.+++++++++++++++++++++++++++++++++.--.---------.+++++.-------.[-]>++[-<++++++++++++++++>]<++++++++++++++.[-]>++++++[-<++++++++++++++++>]<++++++.++++++++++++.---.--.[-]>++++[-<++++++++++++++++>]<+++.+++++++++++++++++++++++++++++++++++++.-------.+++++++++++++++++.[-]>++++[-<++++++++++++++++>]<+++.++++++++++++++++++++++++++++++++++++++++++++.-----------.+.[-]>++[-<++++++++++++++++>]<++++++++.+++++++++..-.-------.++++++++++++++++++.[-]++++++++++.++++++++++++++++++++++.[-]>+++++++[-<++++++++++++++++>]<++++++.---------------------.+++++++++++++++++.[-]>++[-<++++++++++++++++>]<.[-]>++++++[-<++++++++++++++++>]<++++.---.+++++++++++++++++++.-------------------.[-]>++[-<++++++++++++++++>]<.+++++++++++++++++++++++++++++.[-]>++[-<++++++++++++++++>]<.[-]++++++++++.++++++++++++++++++++++.[-]>+++++++[-<++++++++++++++++>]<+++++++++++.[-]++++++++++.[-]<<<[[<]<]>>[<++++++++[-<++++>]<..>>[<+>----------[------------------------[<++++++++++++++[->----<]+>++[<++++++++++++[->+++++++<]>+.[-<<+>>]]<[++++++++++++[-<+++++++>]<+..>]>]<[++++++++++++[->+++++++<]>+.[-]<<++++++++++++++++++++++++++++++++++.>]>]<[->+++++[-<++++++++++++++++>]<++++++++++++.++++++++++++++++++++++.----------------------.++++++++++++++++++.[-]<++++++++++>]>>]+++[-<++++++++++++++++>]<++++++++++.--------------------------.++.[-]>>[<+>----------[------------------------[<++++++++++++++[->----<]+>++[<++++++++++++[->+++++++<]>+.[-<<+>>]]<[++++++++++++[-<+++++++>]<+..>]>]<[++++++++++++[->+++++++<]>+.[-]<<++++++++++++++++++++++++++++++++++.>]>]<[->+++++[-<++++++++++++++++>]<++++++++++++.++++++++++++++++++++++.----------------------.++++++++++++++++++.[-]<++++++++++>]>>]++[-<++++++++++++++++>]<++.++++++++++.[-]++++++++++.[-]>>]<<<<[[<]<]>>[>]>[>]>[>]>[.>]>[>]>[>]>>>]>[-[-]>+++++++[-<++++++++++++++++>]<+++++.--.----------.+++++.-------.[-]>++[-<++++++++++++++++>]<.[-]>+++++[-<++++++++++++++++>]<+++.++++++++++++++++++++++++++++++++++++++.------.+.---------------.++++++++.[-]>+++[-<++++++++++++++++>]<+++++++++++.[-]++++++++++.[-]>+++++++[-<++++++++++++++++>]<+++++.--.----------.+++++.-------.[-]>++[-<++++++++++++++++>]<.[-]>+++++[-<++++++++++++++++>]<+++.++++++++++++++++++++++++++++++++++++++.------.+.---------------.++++++++.[-]>++[-<++++++++++++++++>]<++++++++++++++.+++++++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++.---..-------.--.+++++++++++++++++.-----------.++++++.-.+++++.[-]>++[-<++++++++++++++++>]<++++++++++++++.+++++++++++++++++++++++++.++++++++++++++++++++++++++++++.+++++++++.---------.+++++++++++++.---------.------.[-]>+++[-<++++++++++++++++>]<+++++++++++.[-]++++++++++.[-]>+++++++[-<++++++++++++++++>]<+++++.--.----------.+++++.-------.[-]>++[-<++++++++++++++++>]<.[-]>+++++[-<++++++++++++++++>]<+++.++++++++++++++++++++++++++++++++++++++.------.+.---------------.++++++++.[-]>++[-<++++++++++++++++>]<++++++++++++++.[-]>+++++[-<++++++++++++++++>]<++++.+++++++++++++++++.+++++++++++++++++++.----.[-]>+++[-<++++++++++++++++>]<+++++++++++.[-]++++++++++.[-]++++++++++.[-]>++++++[-<++++++++++++++++>]<++++++++++++++.-------------.++++++++++++.--------.++++++++++++++.---.---------------.++.++.[-]>++[-<++++++++++++++++>]<.[-]>++++[-<++++++++++++++++>]<+++++++++++++.[-]>+++++++[-<++++++++++++++++>]<+++++.---------.++++++++.-----------.++++++++.++++.------------.+++++.---------.[-]++++++++++.[-]>+++++++[-<++++++++++++++++>]<+++++++++++.[-]++++++++++.++++++++++++++++++++++....[-]>++++++[-<++++++++++++++++>]<+++.+++++++++.-----------.++++++++++++++++++..[-]>++[-<++++++++++++++++>]<.[-]>+++++[-<++++++++++++++++>]<.++++++++++++++++++++++++++++++++++.---.--------.+++++++++++.-----------------.++++++++++++.[-]++++++++++.++++++++++++++++++++++....[-]>+++++++[-<++++++++++++++++>]<+++++++++++.[-]++++++++++.++++++++++++++++++++++........[-]>+++++++[-<++++++++++++++++>]<+++.+.-------------------.+++++++++++++++++++.-----------.------.[-]>++[-<++++++++++++++++>]<.[-]>+++++++[-<++++++++++++++++>]<++++++.-------.------.-----.[-]>++[-<++++++++++++++++>]<.[-]>++++[-<++++++++++++++++>]<+++++++++++++.++++++++++++++++++++.++++++++.+++++.[-]>++[-<++++++++++++++++>]<++++++++.[-]>+++++++[-<++++++++++++++++>]<+++.+.--.---------.+++++.-------.------------.++.[-]>++[-<++++++++++++++++>]<.[-]>++++++[-<++++++++++++++++>]<+.+++++++++++++++++.-----------.++++++++++++.[-]>++[-<++++++++++++++++>]<+++++++++.[-]++++++++++.++++++++++++++++++++++........[-]>+++++++[-<++++++++++++++++>]<+++++++++++.[-]++++++++++.++++++++++++++++++++++............[-]>++++[-<++++++++++++++++>]<++++.+++++++++++++++++++++++++++++++++++++.------.+++++++++++++++++.-----------.++++++.-.-------------.+++++++++++++++++.+++++++.[-]>+++[-<++++++++++++++++>]<++++++++++++.[-]>+++++++[-<++++++++++++++++>]<+++.+.--.---------.+++++.-------.[-]>++[-<++++++++++++++++>]<++++++++++++.------------.[-]>+++++++[-<++++++++++++++++>]<+++.+.--.---------.+++++.-------.-----------------------------------------.[-]>++[-<++++++++++++++++>]<.[-]>++++++[-<++++++++++++++++>]<++++.---.+++++++++++++++++++.-------------------.[-]>++[-<++++++++++++++++>]<.+++++++++++++++++++++++++++++.[-]>++[-<++++++++++++++++>]<.[-]>++++++[-<++++++++++++++++>]<++++++++++++++.---------.++++++++++++++++++.[-]>++[-<++++++++++++++++>]<.[-]>++++[-<++++++++++++++++>]<++++.+++++++++++++++++++++++++++++++++++++.------.+++++++++++++++++.-----------.++++++.-.-------------.+++++++++++++++++.+++++++.[-]>+++[-<++++++++++++++++>]<++++++++++++.[-]>+++++++[-<++++++++++++++++>]<+++.+.--.---------.+++++.-------.[-]>++[-<++++++++++++++++>]<++++++++++++.------------.[-]>+++++++[-<++++++++++++++++>]<+++.+.--.---------.+++++.-------.-----------------------------------------.----------------------.+.++++++++++++++++++.[-]++++++++++.[-]<<<[[<]<]>>[<++[-<++++++++++++++++>]<............[-]>++++++[-<++++++++++++++++>]<++++.---.+++++++++++++++++++.-------------------.[-]>++[-<++++++++++++++++>]<++++++++++++++.+++++++++++++++++++.+++++++++++++++++++++++++++++++++++..[-]>++[-<++++++++++++++++>]<++++++++.------.[-]>>[<+>----------[------------------------[<++++++++++++++[->----<]+>++[<++++++++++++[->+++++++<]>+.[-<<+>>]]<[++++++++++++[-<+++++++>]<+..>]>]<[++++++++++++[->+++++++<]>+.[-]<<++++++++++++++++++++++++++++++++++.>]>]<[->+++++[-<++++++++++++++++>]<++++++++++++.++++++++++++++++++++++.----------------------.++++++++++++++++++.[-]<++++++++++>]>>]++[-<++++++++++++++++>]<++.++++++++++.------------.++.[-]>>[<+>----------[------------------------[<++++++++++++++[->----<]+>++[<++++++++++++[->+++++++<]>+.[-<<+>>]]<[++++++++++++[-<+++++++>]<+..>]>]<[++++++++++++[->+++++++<]>+.[-]<<++++++++++++++++++++++++++++++++++.>]>]<[->+++++[-<++++++++++++++++>]<++++++++++++.++++++++++++++++++++++.----------------------.++++++++++++++++++.[-]<++++++++++>]>>]++[-<++++++++++++++++>]<++.+++++++.++++++++++++++++++.[-]++++++++++.[-]>>]<<<<[[<]<]>>[>]>[.>]>[[>]>]>>>]<]>[-<<<[[<]<]+++[-<+++++++>]<[->++>+++<<]>+>-....<<++++++++++.[-]>>>[[[[-<<.<+>>>]<.[->+<]<[->+<]>>>]<.[->+<]<[->+<]>>>]]<<<<<[<]++++++++++.[-]>[.>]]",
 };

 if(!language) language = 'js';
 var code = data[language];
 var bootstraps =
 {
 js: '(function(language){\r\n var quote = String.fromCharCode(34), backslash = String.fromCharCode(92), newline = backslash + String.fromCharCode(114) + backslash + String.fromCharCode(110);\r\n var data = \r\n {\r\n',
 cs: 'using System;\r\nusing System.Collections.Generic;\r\nusing System.Text;\r\n\r\nnamespace Multiquine\r\n{\r\n class Program\r\n {\r\n static void Main(string[] args)\r\n {\r\n Dictionary<string, string> data = new Dictionary<string, string>();\r\n',
 bf: '>>>>\r\n',
 }
 var res = bootstraps[language]
 switch(language)
 {
 case 'js':
 for(var i in data) res += ' ' + i + ': ' + quote + data[i].replace(new RegExp('\\\\', 'g'), backslash + backslash).replace(new RegExp(quote, 'g'), backslash + quote).replace(new RegExp(newline, 'g'), backslash + 'r' + backslash + 'n') + quote + ',\r\n';
 break;
 case 'cs':
 for(var i in data) res += ' data.Add(' + quote + i + quote + ', ' + quote + data[i].replace(new RegExp('\\\\', 'g'), backslash + backslash).replace(new RegExp(quote, 'g'), backslash + quote).replace(new RegExp(newline, 'g'), backslash + 'r' + backslash + 'n') + quote + ');\r\n';
 break;
 case 'bf':
 for(var i in data)
 {
 for (var j = 0; j < i.length; j++) { if (i.charCodeAt(j) == 13) continue; res += "+".repeat(i.charCodeAt(j)); res += '>'; }
res += '>';
for (var j = 0; j < data[i].length; j++) { if (data[i].charCodeAt(j) == 13) continue; res += "+".repeat(data[i].charCodeAt(j)); res += '>'; }
res += '>';
 }
 res += '\r\n';
 }
 res += code;
 console.log(res);
})()

Code - BF

This one is really long... So, please generate it from either JS or CS code :)

Note

I strongly suggest NOT TO USE the online interpreter (nor any interpreter actually) to try the BF code. I yo're using Ubuntu, you can use the BF package (if you're on any other Linux distribution, you can use the same package by building the source - it even works on Mac OSX).

And if you're using Windows, then you can download Cydia, and compile the BF sources as well 

Aucun commentaire:

Enregistrer un commentaire