问:
A cube of text ݀
Last time you made a square of text, but now, can you make a cube of text?

The Challenge

Given a string, output the string in the form of a cube.

You can assume the string will always have 2 chars or more, and will only have printable ascii characters.

How to Make a Text Cube

Test Cases

```<code>Input:
Test

Output:
   Test
  e  ss
 s  e e
tseT  T
s  e e
e  ss
Test

Input:
Hello, world!

Output:
            Hello, world!
           e           dd
          l           l l
         l           r  r
        o           o   o
       ,           w    w

     w           ,      ,
    o           o       o
   r           l        l
  l           l         l
 d           e          e
!dlrow ,olleH           H
d           e          e
l           l         l
r           l        l
o           o       o
w           ,      ,

,           w    w
o           o   o
l           r  r
l           l l
e           dd
Hello, world!

Input:
Hi

Output:
 Hi
iHH
Hi
</code>```

Reference Implementation in Python

text = raw_input("Enter a string: ")

print " " * (len(text) - 1) + text

spaces = len(text) - 2
_spaces = spaces

for i in range(1, len(text) - 2 + 1):
    print " " * spaces + text[i] + " " * _spaces + text[(i + 1) * -1] + " " * (_spaces - spaces) + text[(i + 1) * -1]
    spaces -= 1

print text[::-1] + " " * _spaces + text[0]

spaces = _spaces - 1

for i in range(1, len(text) - 2 + 1):
    print text[(i + 1) * -1] + " " * _spaces + text[i] + " " * spaces + text[i]
    spaces -= 1

print text
```

<h2>Rules</h2>

<ul>
<li>This is code-golf, so shortest answer in bytes wins! Tiebreaker is most upvoted.</li>
<li>Standard loopholes are disallowed.</li>
<li>Trailing newline and trailing spaces are allowed.</li>
</ul>

<h2>Leaderboard</h2>

<p>Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.</p>

<p><div class="snippet" data-lang="js" data-hide="true" data-console="false" data-babel="false">
<div class="snippet-code snippet-currently-hidden">
<pre class="snippet-code-js lang-js prettyprint-override"><code>/* Configuration */

var QUESTION_ID = 92410; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 48934; // This should be the user ID of the challenge author.

/* App */

var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;

function answersUrl(index) {
  return "https://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}

function commentUrl(index, answers) {
  return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}

function getAnswers() {
  jQuery.ajax({
    url: answersUrl(answer_page++),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      answers.push.apply(answers, data.items);
      answers_hash = [];
      answer_ids = [];
      data.items.forEach(function(a) {
        a.comments = [];
        var id = +a.share_link.match(/\d+/);
        answer_ids.push(id);
        answers_hash[id] = a;
      });
      if (!data.has_more) more_answers = false;
      comment_page = 1;
      getComments();
    }
  });
}

function getComments() {
  jQuery.ajax({
    url: commentUrl(comment_page++, answer_ids),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      data.items.forEach(function(c) {
        if (c.owner.user_id === OVERRIDE_USER)
          answers_hash[c.post_id].comments.push(c);
      });
      if (data.has_more) getComments();
      else if (more_answers) getAnswers();
      else process();
    }
  });
}

getAnswers();

var SCORE_REG = /<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;

var OVERRIDE_REG = /^Override\s*header:\s*/i;

function getAuthorName(a) {
  return a.owner.display_name;
}

function process() {
  var valid = [];

  answers.forEach(function(a) {
    var body = a.body;
    a.comments.forEach(function(c) {
      if(OVERRIDE_REG.test(c.body))
        body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';
    });

    var match = body.match(SCORE_REG);
    if (match)
      valid.push({
        user: getAuthorName(a),
        size: +match[2],
        language: match[1],
        link: a.share_link,
      });

  });

  valid.sort(function (a, b) {
    var aB = a.size,
        bB = b.size;
    return aB - bB
  });

  var languages = {};
  var place = 1;
  var lastSize = null;
  var lastPlace = 1;
  valid.forEach(function (a) {
    if (a.size != lastSize)
      lastPlace = place;
    lastSize = a.size;
    ++place;

    var answer = jQuery("#answer-template").html();
    answer = answer.replace("{{PLACE}}", lastPlace + ".")
                   .replace("{{NAME}}", a.user)
                   .replace("{{LANGUAGE}}", a.language)
                   .replace("{{SIZE}}", a.size)
                   .replace("{{LINK}}", a.link);
    answer = jQuery(answer);
    jQuery("#answers").append(answer);

    var lang = a.language;
    if (/<a/.test(lang)) lang = jQuery(lang).text();

    languages[lang] = languages[lang] || {lang: a.language, user: a.user, size: a.size, link: a.link};
  });

  var langs = [];
  for (var lang in languages)
    if (languages.hasOwnProperty(lang))
      langs.push(languages[lang]);

  langs.sort(function (a, b) {
    if (a.lang > b.lang) return 1;
    if (a.lang < b.lang) return -1;
    return 0;
  });

  for (var i = 0; i < langs.length; ++i)
  {
    var language = jQuery("#language-template").html();
    var lang = langs[i];
    language = language.replace("{{LANGUAGE}}", lang.lang)
                       .replace("{{NAME}}", lang.user)
                       .replace("{{SIZE}}", lang.size)
                       .replace("{{LINK}}", lang.link);
    language = jQuery(language);
    jQuery("#languages").append(language);
  }

}</code>```

body { text-align: left !important}

#answer-list {
  padding: 10px;
  width: 290px;
  float: left;
}

#language-list {
  padding: 10px;
  width: 290px;
  float: left;
}

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">
<div id="answer-list">
  <h2>Leaderboard</h2>
  <table class="answer-list">
    <thead>
      <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr>
    </thead>
    <tbody id="answers">

    </tbody>
  </table>
</div>
<div id="language-list">
  <h2>Winners by Language</h2>
  <table class="language-list">
    <thead>
      <tr><td>Language</td><td>User</td><td>Score</td></tr>
    </thead>
    <tbody id="languages">

    </tbody>
  </table>
</div>
<table style="display: none">
  <tbody id="answer-template">
    <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td>Link</td></tr>
  </tbody>
</table>
<table style="display: none">
  <tbody id="language-template">
    <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td>Link</td></tr>
  </tbody>
</table></code>```

答:
x86 (IA-32) machine code, 126 bytes

Hexdump:

```<code>60 8b f9 57 33 c0 f2 ae 5e 2b fe 4f 87 fa 8d 1c
12 8b c3 48 f6 e3 c6 04 07 00 48 c6 04 07 20 75
f9 8b ea 4d 53 8d 04 2a 50 53 8b c5 f6 e3 8d 44
68 01 50 53 2b c2 8b c8 50 4b 53 55 53 03 c5 50
f7 d3 53 50 53 95 f6 e2 6b c0 04 50 43 53 51 6a
01 4a 52 6a 01 50 6a ff 51 b0 0a 6a 0b 8b dc 59
8b 6c cb fc 88 04 2f 03 2c cb 89 6c cb fc 83 f9
0a 75 01 ac e2 ea 4a 79 e0 83 c4 58 61 c3
</code>```

This is a bit long, so to explain it I'll give C code first:

```<code>void doit(const char* s, char out[])
{
    int n = strlen(s);
    int w = 2 * n;
    int h = w - 1;
    int m = n - 1;

    memset(out, ' ', h * w);
    out[h * w] = 0;

    int offset1 = n + m;
    int offset2 = w * m + 2 * m + 1; // 2 * n * n - 1
    int offset3 = offset2 - n; // 2 * n * n - n - 1
    int offset4 = 4 * n * m; // 4 * n * n - 4 * n

    int offsets[] = {
        offset3, -1,
        offset4, 1,
        m, 1,
        offset3, 1 - w,
        offset4, -w,
        offset2 - 1, -w,
        offset2 - 1, w - 1,
        m, w - 1,
        offset3, w,
        offset2, w,
        offset1, w,
    };

    do
    {
        char c = *s++;
        for (int i = 0; i < 11; ++i)
        {
            if (i == 9)
                c = '\n';
            int offset = offsets[i * 2];
            assert(offset > 0 && offset < w * h);
            out[offset] = c;
            offsets[i * 2] += offsets[i * 2 + 1];
        }
    } while (--n);
}
</code>```

Here n is the length of the input string.

The dimensions of the output area are 2n (width) by 2n-1 (height). First, it fills everything with spaces (and adds a terminating null byte). Then, it travels along 11 straight lines in the output area, and fills them with text:

2 lines are filled with end-of-line bytes (=10)

9 lines are filled with the consecutive bytes of the input string

Each line is represented by two numbers, a start offset and a stride. I stuffed them both into the array offsets, to make access "easy".

The interesting part is filling the array. There is little importance for the order of the entries in the array; I tried to rearrange them to minimize the number of register conflicts. In addition, quadratic formulas have some freedom in choosing the way of calculation; I tried to minimize the number of subtractions (because additions can be implemented by the flexible LEA instruction).

Assembly source:

```<code>    pushad;

    ; // Calculate the length of the input string
    mov edi, ecx;
    push edi;
    xor eax, eax;
    repne scasb;
    pop esi; // esi = input string
    sub edi, esi;
    dec edi;

    ; // Calculate the size of the output area
    xchg edi, edx;  // edx = n
                    // edi = output string
    lea ebx, [edx + edx]; // ebx = w
    mov eax, ebx;
    dec eax; // eax = h
    mul bl; // eax = w * h

    ; // Fill the output string with spaces and zero terminate it
    mov byte ptr [edi + eax], 0;
myfill:
    dec eax;
    mov byte ptr [edi + eax], ' ';
    jnz myfill;

    mov ebp, edx;
    dec ebp; // ebp = m

    ; // Fill the array of offsets
    push ebx; // w
    lea eax, [edx + ebp];
    push eax; // offset1
    push ebx; // w
    mov eax, ebp;
    mul bl;
    lea eax, [eax + 2 * ebp + 1];
    push eax; // offset2
    push ebx; // w
    sub eax, edx;
    mov ecx, eax; // ecx = offset3
    push eax; // offset3
    dec ebx;
    push ebx; // w - 1
    push ebp; // m
    push ebx; // w - 1
    add eax, ebp;
    push eax; // offset2 - 1
    not ebx;
    push ebx; // -w
    push eax; // offset2 - 1
    push ebx; // -w
    xchg eax, ebp; // eax = m
    mul dl;
    imul eax, eax, 4;
    push eax; // offset4
    inc ebx;
    push ebx; // 1 - w
    push ecx; // offset3
    push 1;
    dec edx; // edx = n - 1
    push edx;
    push 1;
    push eax;
    push -1;
    push ecx;

    ; // Use the array of offsets to write stuff to output
myout:
    mov al, '\n';
    push 11;
    mov ebx, esp;
    pop ecx;
myloop:
    mov ebp, [ebx + ecx * 8 - 4];
    mov [edi + ebp], al;
    add ebp, [ebx + ecx * 8];
    mov [ebx + ecx * 8 - 4], ebp;
    cmp ecx, 10;
    jne skip_read;
    lodsb;
skip_read:
    loop myloop;
    dec edx;
    jns myout;

    add esp, 11 * 8;

    popad;
    ret;
</code>```

I used byte multiplications here, limiting the length of the input string to 127. This avoids clobbering the register edx - the product is calculated in ax instead.

A minor glitch: when filling the array, the length of the string gets decreased by 1. So I adjusted the loop exit condition:

```<code>    jns myout
</code>```

It counts down to -1.

Title: A cube of text ݀

Body:
x86 (IA-32) machine code, 126 bytes

Hexdump:

60 8b f9 57 33 c0 f2 ae 5e 2b fe 4f 87 fa 8d 1c
12 8b c3 48 f6 e3 c6 04 07 00 48 c6 04 07 20 75
f9 8b ea 4d 53 8d 04 2a 50 53 8b c5 f6 e3 8d 44
68 01 50 53 2b c2 8b c8 50 4b 53 55 53 03 c5 50
f7 d3 53 50 53 95 f6 e2 6b c0 04 50 43 53 51 6a
01 4a 52 6a 01 50 6a ff 51 b0 0a 6a 0b 8b dc 59
8b 6c cb fc 88 04 2f 03 2c cb 89 6c cb fc 83 f9
0a 75 01 ac e2 ea 4a 79 e0 83 c4 58 61 c3

This is a bit long, so to explain it I'll give C code first:

void doit(const char* s, char out[])
{
    int n = strlen(s);
    int w = 2 * n;
    int h = w - 1;
    int m = n - 1;

    memset(out, ' ', h * w);
    out[h * w] = 0;

    int offset1 = n + m;
    int offset2 = w * m + 2 * m + 1; // 2 * n * n - 1
    int offset3 = offset2 - n; // 2 * n * n - n - 1
    int offset4 = 4 * n * m; // 4 * n * n - 4 * n

    int offsets[] = {
        offset3, -1,
        offset4, 1,
        m, 1,
        offset3, 1 - w,
        offset4, -w,
        offset2 - 1, -w,
        offset2 - 1, w - 1,
        m, w - 1,
        offset3, w,
        offset2, w,
        offset1, w,
    };

    do
    {
        char c = *s++;
        for (int i = 0; i < 11; ++i)
        {
            if (i == 9)
                c = '\n';
            int offset = offsets[i * 2];
            assert(offset > 0 && offset < w * h);
            out[offset] = c;
            offsets[i * 2] += offsets[i * 2 + 1];
        }
    } while (--n);
}

Here n is the length of the input string.

The dimensions of the output area are 2n (width) by 2n-1 (height). First, it fills everything with spaces (and adds a terminating null byte). Then, it travels along 11 straight lines in the output area, and fills them with text:

2 lines are filled with end-of-line bytes (=10)

9 lines are filled with the consecutive bytes of the input string

Each line is represented by two numbers, a start offset and a stride. I stuffed them both into the array offsets, to make access "easy".

The interesting part is filling the array. There is little importance for the order of the entries in the array; I tried to rearrange them to minimize the number of register conflicts. In addition, quadratic formulas have some freedom in choosing the way of calculation; I tried to minimize the number of subtractions (because additions can be implemented by the flexible LEA instruction).

Assembly source:

    pushad;

    ; // Calculate the length of the input string
    mov edi, ecx;
    push edi;
    xor eax, eax;
    repne scasb;
    pop esi; // esi = input string
    sub edi, esi;
    dec edi;

    ; // Calculate the size of the output area
    xchg edi, edx;  // edx = n
                    // edi = output string
    lea ebx, [edx + edx]; // ebx = w
    mov eax, ebx;
    dec eax; // eax = h
    mul bl; // eax = w * h

    ; // Fill the output string with spaces and zero terminate it
    mov byte ptr [edi + eax], 0;
myfill:
    dec eax;
    mov byte ptr [edi + eax], ' ';
    jnz myfill;

    mov ebp, edx;
    dec ebp; // ebp = m

    ; // Fill the array of offsets
    push ebx; // w
    lea eax, [edx + ebp];
    push eax; // offset1
    push ebx; // w
    mov eax, ebp;
    mul bl;
    lea eax, [eax + 2 * ebp + 1];
    push eax; // offset2
    push ebx; // w
    sub eax, edx;
    mov ecx, eax; // ecx = offset3
    push eax; // offset3
    dec ebx;
    push ebx; // w - 1
    push ebp; // m
    push ebx; // w - 1
    add eax, ebp;
    push eax; // offset2 - 1
    not ebx;
    push ebx; // -w
    push eax; // offset2 - 1
    push ebx; // -w
    xchg eax, ebp; // eax = m
    mul dl;
    imul eax, eax, 4;
    push eax; // offset4
    inc ebx;
    push ebx; // 1 - w
    push ecx; // offset3
    push 1;
    dec edx; // edx = n - 1
    push edx;
    push 1;
    push eax;
    push -1;
    push ecx;

    ; // Use the array of offsets to write stuff to output
myout:
    mov al, '\n';
    push 11;
    mov ebx, esp;
    pop ecx;
myloop:
    mov ebp, [ebx + ecx * 8 - 4];
    mov [edi + ebp], al;
    add ebp, [ebx + ecx * 8];
    mov [ebx + ecx * 8 - 4], ebp;
    cmp ecx, 10;
    jne skip_read;
    lodsb;
skip_read:
    loop myloop;
    dec edx;
    jns myout;

    add esp, 11 * 8;

    popad;
    ret;

I used byte multiplications here, limiting the length of the input string to 127. This avoids clobbering the register edx - the product is calculated in ax instead.

A minor glitch: when filling the array, the length of the string gets decreased by 1. So I adjusted the loop exit condition:

    jns myout

It counts down to -1.


问:
Shortest 8-bit xor cipher
8-bit XOR encryption takes a single byte and XORs every byte in the file by that byte. Here is a reference program in C++:

```<code>/*xorcipher.cpp
 *Encrypts a file using 8-bit xor encrytpion
 */

#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;

int main(int argc, char** argv){
   ifstream* in = NULL;
   ofstream* out = NULL;

   if(argc < 3){
      cerr << "Usage: xor <key> <filename...>" << endl;
      exit(1);
   }

   int key = atoi(argv[1]);

   for(int x = 2; x < argc; x++){
      in = new ifstream(argv[x], ios::binary);
      if(!in->good()){
         cerr << "Error reading from " << argv[x] << endl;
         exit(1);
      }

      //Get file size
      in->seekg(0, ios::end);
      int size = in->tellg();
      in->seekg(0, ios::beg);

      //Allocate memory
      int* data = new int[size];

      int c = 0;
      for(int y = 0; (c = in->get()) != EOF; y++)
         data[y] = c ^ key;

      in->close();
      delete in;
      in = NULL;

      out = new ofstream(argv[x], ios::binary);
      if(!out->good()){
         cerr << "Error writing to " << argv[x] << endl;
         exit(1);
      }

      for(int y = 0; y < size; y++)
         out->put(data[y]);

      out->flush();
      out->close();
      delete out;
      out = NULL;

      delete[] data;
      data = NULL;
   }
   cout << "Operation complete" << endl;

   return 0;
}
</code>```

The shortest answer (whitespace doesn't count) that produces the same end result will be selected. It does not have to store everything in memory at once or open and close every file multiple times. It can do anything as long as a file encrypted with the reference program can be decrypted with the answer, and vice versa.

Edit: The above program is not a specification. The only requirement is that answers should be able to decrypt a file encrypted with the above program, and the above program should be able to decrypt a file encrypted with the answer. I'm sorry if that was unclear.

The above program can be compiled with:

```<code>g++ xorcipher.cpp -o ~/bin/xor
</code>```

It can be run like this:

```<code>xor <key> <filename...>
</code>```

For example, if the key is 42 and the file is alpha.txt, you would use:

```<code>xor 42 alpha.txt
</code>```

答:
C, 61 59 bytes

Quite simple, and very similar to primo's solution.

First parameter is the key, in decimal, reads stdin, writes stdout.

The only tricky part is using ~getchar, so EOF becomes 0 and terminates the loop, then printing c^~key, where the additional ~ undoes the previous one.

```<code>main(c,v)int*v;{
    while(c=~getchar())putchar(c^~atoi(v[1]));
}
</code>```

ContentLicense: CC BY-SA 3.0

Title: Shortest 8-bit xor cipher

Body:
C, 61 59 bytes

Quite simple, and very similar to primo's solution.

First parameter is the key, in decimal, reads stdin, writes stdout.

The only tricky part is using ~getchar, so EOF becomes 0 and terminates the loop, then printing c^~key, where the additional ~ undoes the previous one.

main(c,v)int*v;{
    while(c=~getchar())putchar(c^~atoi(v[1]));
}


问:
Print multiplication tables by input
In this challenge you've to print multiplication tables by input, Here are some examples:

```<code>Input: 2

Output:
0 2  4 6 8  10  12  14  16  18  20

Input: 20

Output: 20 40 60 80 100 120 140 160 180 200
</code>```

Rules

The shortest code in bytes wins.

This challenge is a code-golf, It follows code-golf general rules (code-golf)

If, just if, your code can't print number, you can use letters, Here is an example:

Input: B

Output: B D F H J L N P R T

You can choose to start from 0 or your number (like 20). You can choose if put spaces or don't. The challenge is free, just take an input and print multiplication tables.

Your output must list the first 10 members of the times table for the given number. You may leave out 0*n.

答:
Mathematica, 10 bytes

```<code>#Range@10&
</code>```

Range@10 is the list {1,2,...,10}, which is then multiplied by the input #.

Title: Print multiplication tables by input

Body:
Mathematica, 10 bytes

#Range@10&

Range@10 is the list {1,2,...,10}, which is then multiplied by the input #.


问:
Stringsplode the String!
The challenge is relatively simple, but will hopefully lead to some wonderfully creative answers. The task is to take a string as an input (via command line, function parameter etc.) and output/return a stringsploded version of it.

A stringsploded version of a string is its first letter followed by its first 2 letters, followed by its first 3 letters,... until you finally output the complete word.

You are guaranteed that the input will consist of printable ASCII characters and that the input will all be on one line (no new line characters).

Here are examples to clarify what stringsplosions are:

```<code>Input                 Output
==================================================================
"Code"       ---->   "CCoCodCode"
"name"       ---->   "nnanamname"
"harambe"    ---->   "hhaharharaharamharambharambe"
"sp aces?"   ---->   "sspsp sp asp acsp acesp acessp aces?"
"1234"       ---->   "1121231234"
"ss"         ---->   "sss"
</code>```

This is code golf so shortest code wins + up votes for interesting uses of your respective language.

Good luck!

答:
GNU sed, 30 bytes

```<code>:;G;h;s/.\n.*//;/./t;g;s/\n//g
</code>```

Run:

echo -n "name" | sed -f stringsplode.sed
```

Title: Stringsplode the String!

Body:
GNU sed, 30 bytes

:;G;h;s/.\n.*//;/./t;g;s/\n//g

Run:

echo -n "name" | sed -f stringsplode.sed


问:
Noah's (upgraded) ark
As preparation for the nth Exodus, Noah decides to write a program that will decide If he will let animals on his ark.  However, Noah wants to go back to grass roots. Thus he decides that the program should be as small and as simple as possible.

GOAL:

Recreate the Contrabulous Choosematron, in a way that follows evangelical stories.

INPUT:

The program is simple, and elegant, and takes in 2 inputs:

The species of animal [String]

and The animal's gender [boolean]

OUTPUT:

The program then puts out Either 'Y' or 'N', Which determines whether or not the given  animal is allowed onto the ark.

RULES:

Only one Animal of each species and gender is allowed on the ark. No more.

Your output can be any set of boolean values (true false, yes no, y n, yin yang) so long as they're easily distinguishable.

If your program should want to accept a list of input, rather than use STDIN, that's fine. However, each output has to be in corresponding order of the input (FIFO), as well as be in the exact same format as the input.

This is a golf, so the lowest byte count wins, good luck!!!!

EXAMPLE:

"Monkey" true<

y

"Monkey" false<

y

"Monkey" false<

n

"Monkey with symbols" false<

y

"monkey" true<

n

This is valid, as your program doesn't need to distinguish that Monkey, and monkey with symbols are the same thing species, however, Monkey and monkey are very much the same thing, and so the last critter would be denied.

答:
Java, <s>246</s> 218 bytes

Lowered byte count thanks to Kevin!.

Takes STDIN as input, outputs weather or not the animal is allowed to board.

```<code>import java.util.*;class B{public static void main(String[]a){List l=new ArrayList();Scanner s=new Scanner(System.in);for(;;){String b=s.nextLine().toLowerCase();l.add(b);System.out.println(l.contains(b)?"n":"y");}}}
</code>```

Title: Noah's (upgraded) ark

Body:
Java, <s>246</s> 218 bytes

Lowered byte count thanks to Kevin!.

Takes STDIN as input, outputs weather or not the animal is allowed to board.

import java.util.*;class B{public static void main(String[]a){List l=new ArrayList();Scanner s=new Scanner(System.in);for(;;){String b=s.nextLine().toLowerCase();l.add(b);System.out.println(l.contains(b)?"n":"y");}}}


答:
Groovy 43 Bytes

```<code>{s->y=[];s.collect{!y.contains(it)&&y.add(it)}}
</code>```

Try it here: https://groovyconsole.appspot.com/edit/5147446497771520

It uses a list of tuples as the input:

```<code>z = [new Tuple('Monkey',true), new Tuple('Monkey',false), new Tuple('Monkey',true), new Tuple('Bee',true)]
</code>```

Which results in:

```<code>[true, true, false, true]
</code>```

The add function in groovy always returns true, and in groovy tuples have inherent comparison ability for primitive objects, so the contains actually works well for strings and integers without changing it.

So, basically just check if the list contains it and add it to the list.

If the list already contains it we get (false && N/A)

If it does not we get (True && True) and it is added to the running list.

This is all you really need to accomplish this, if you want to tell me to turn it into a closure or something as well it would probably cap out at approximately 45-50 bytes in Groovy.

Title: Noah's (upgraded) ark

Body:
As preparation for the nth Exodus, Noah decides to write a program that will decide If he will let animals on his ark.  However, Noah wants to go back to grass roots. Thus he decides that the program should be as small and as simple as possible.

GOAL:

Recreate the Contrabulous Choosematron, in a way that follows evangelical stories.

INPUT:

The program is simple, and elegant, and takes in 2 inputs:

The species of animal [String]

and The animal's gender [boolean]

OUTPUT:

The program then puts out Either 'Y' or 'N', Which determines whether or not the given  animal is allowed onto the ark.

RULES:

Only one Animal of each species and gender is allowed on the ark. No more.

Your output can be any set of boolean values (true false, yes no, y n, yin yang) so long as they're easily distinguishable.

If your program should want to accept a list of input, rather than use STDIN, that's fine. However, each output has to be in corresponding order of the input (FIFO), as well as be in the exact same format as the input.

This is a golf, so the lowest byte count wins, good luck!!!!

EXAMPLE:

"Monkey" true<

y

"Monkey" false<

y

"Monkey" false<

n

"Monkey with symbols" false<

y

"monkey" true<

n

This is valid, as your program doesn't need to distinguish that Monkey, and monkey with symbols are the same thing species, however, Monkey and monkey are very much the same thing, and so the last critter would be denied.

Body:
Groovy 43 Bytes

{s->y=[];s.collect{!y.contains(it)&&y.add(it)}}

Try it here: https://groovyconsole.appspot.com/edit/5147446497771520

It uses a list of tuples as the input:

z = [new Tuple('Monkey',true), new Tuple('Monkey',false), new Tuple('Monkey',true), new Tuple('Bee',true)]

Which results in:

[true, true, false, true]

The add function in groovy always returns true, and in groovy tuples have inherent comparison ability for primitive objects, so the contains actually works well for strings and integers without changing it.

So, basically just check if the list contains it and add it to the list.

If the list already contains it we get (false && N/A)

If it does not we get (True && True) and it is added to the running list.

This is all you really need to accomplish this, if you want to tell me to turn it into a closure or something as well it would probably cap out at approximately 45-50 bytes in Groovy.


Title: Print multiplication tables by input

Body:
In this challenge you've to print multiplication tables by input, Here are some examples:

```<code>Input: 2

Output:
0 2  4 6 8  10  12  14  16  18  20

Input: 20

Output: 20 40 60 80 100 120 140 160 180 200
</code>```

Rules

The shortest code in bytes wins.

This challenge is a code-golf, It follows code-golf general rules (code-golf)

If, just if, your code can't print number, you can use letters, Here is an example:

Input: B

Output: B D F H J L N P R T

You can choose to start from 0 or your number (like 20). You can choose if put spaces or don't. The challenge is free, just take an input and print multiplication tables.

Your output must list the first 10 members of the times table for the given number. You may leave out 0*n.

Body:
Pyth, 5 Bytes

Try It Online

VhT*N

explanation

V    for unary_range(
hT   Ten+1)
*N   Print (N *Input)

Example

===================== Input ======================
20
==================================================

0
20
40
60
80
100
120
140
160
180
200


答:
Perl (35 + 1 for -p) 36

Takes input from STDIN, one animal per line in the form animal T. Where T is anything you want to be used for the gender (e.g. T/F, M/F). You could even have multi-character genders, or more than 2 genders (e.g. male/female/apache helicopter).

Includes all character on the line, so if you're inputting from a file you need a newline after the last animal.

```<code>$\=($a{lc()}?N:Y);$a{lc()}=1;$_='';
</code>```

Title: Noah's (upgraded) ark

Body:
Perl (35 + 1 for -p) 36

Takes input from STDIN, one animal per line in the form animal T. Where T is anything you want to be used for the gender (e.g. T/F, M/F). You could even have multi-character genders, or more than 2 genders (e.g. male/female/apache helicopter).

Includes all character on the line, so if you're inputting from a file you need a newline after the last animal.

$\=($a{lc()}?N:Y);$a{lc()}=1;$_='';


答:
JavaScript (ES6), 25 bytes

```<code>s=>s.replace(/./g,'$`$&')
</code>```

Title: Stringsplode the String!

Body:
The challenge is relatively simple, but will hopefully lead to some wonderfully creative answers. The task is to take a string as an input (via command line, function parameter etc.) and output/return a stringsploded version of it.

A stringsploded version of a string is its first letter followed by its first 2 letters, followed by its first 3 letters,... until you finally output the complete word.

You are guaranteed that the input will consist of printable ASCII characters and that the input will all be on one line (no new line characters).

Here are examples to clarify what stringsplosions are:

```<code>Input                 Output
==================================================================
"Code"       ---->   "CCoCodCode"
"name"       ---->   "nnanamname"
"harambe"    ---->   "hhaharharaharamharambharambe"
"sp aces?"   ---->   "sspsp sp asp acsp acesp acessp aces?"
"1234"       ---->   "1121231234"
"ss"         ---->   "sss"
</code>```

This is code golf so shortest code wins + up votes for interesting uses of your respective language.

Good luck!

Body:
JavaScript (ES6), 25 bytes

s=>s.replace(/./g,'$`$&')


问:
All Binary Combinations to Decimal
Disclaimer

This question is not a duplicate of this question. I'm not counting specific digits, as we already have those set in the initial parameters. This question is focusing on the decimal numbers that can be constructed from the binary strings based on the digits provided.

Challenge

Given two integers X and Y, representing the number of zeroes (0) and ones (1) respectively, calculate all the possible decimal equivalents that can be determined from creating binary strings using only the zeroes and ones provided, and display them as output.

Example 1:

Input: 0 1

Output: 1

Explanation: Only one 1 to account for, which can only be converted one way.

Example 2:

Input: 1 1

Output: 1,2

Explanation: 01 converts to 1, 10 converts to 2.

Example 3:

Input: 3 2

Output: 3,5,6,9,10,12,17,18,20,24

Explanation: Three 0s and two 1s make 00011 (3), 00101 (5), 00110 (6), 01001 (9), 01010 (10), 01100 (12), 10001 (17), 10010 (18), 10100 (20), 11000 (24)

Limitations and Rules

I will only expect your code to work where 0 < X + Y <= 16 so the maximum number in the output could only occur from 16 1s, i.e. parameters 0 and 16.

As a result of the above limitation, the range of numbers we'd expect in the output are from 0 and 65535.

I will accept functions or code, so long as the resulting output is provided, whether this be a comma separated list, an array, list outputted to STDOUT, etc. The only criteria I must stress about the output is that it must be sorted.

This is code golf, minimum bytes will receive maximum glory.

We will not tolerate silly loopholes

答:
MATL, 9 bytes

```<code>y+:<Y@XBu
</code>```

Try it online!

Explanation

The approach is similar to that in Dennis' Jelly answer.

```<code>y     % Implicitly take two inputs (say 3, 2). Duplicate the first.
      %   STACK: 3, 2, 3
+     % Add
      %   STACK: 3, 5
:     % Range
      %   STACK: 3, [1 2 3 4 5]
<     % Less  than
      %   STACK: [0 0 0 1 1]
Y@    % All permutations
      %   STACK: [0 0 0 1 1; 0 0 0 1 1; ...; 0 0 1 0 1; ...; 1 1 0 0 0]
XB    % Binary to decimal
      %   STACK: [3 3 ... 5 ... 24]
u     % Unique
      %   STACK: [3 5 ... 24]
      % Implicitly display
</code>```

Title: All Binary Combinations to Decimal

Body:
MATL, 9 bytes

y+:<Y@XBu

Try it online!

Explanation

The approach is similar to that in Dennis' Jelly answer.

y     % Implicitly take two inputs (say 3, 2). Duplicate the first.
      %   STACK: 3, 2, 3
+     % Add
      %   STACK: 3, 5
:     % Range
      %   STACK: 3, [1 2 3 4 5]
<     % Less  than
      %   STACK: [0 0 0 1 1]
Y@    % All permutations
      %   STACK: [0 0 0 1 1; 0 0 0 1 1; ...; 0 0 1 0 1; ...; 1 1 0 0 0]
XB    % Binary to decimal
      %   STACK: [3 3 ... 5 ... 24]
u     % Unique
      %   STACK: [3 5 ... 24]
      % Implicitly display


答:
Python 75

```<code>import sys
for j in sys.stdin:print''.join(chr(int(sys.argv[1])^ord(i))for i in j),
</code>```

The hardest requirement was not to keep the whole file in memory.

Usage:

```<code>python xor.py 123 <file.in >file.out
</code>```

Title: Shortest 8-bit xor cipher

Body:
8-bit XOR encryption takes a single byte and XORs every byte in the file by that byte. Here is a reference program in C++:

```<code>/*xorcipher.cpp
 *Encrypts a file using 8-bit xor encrytpion
 */

#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;

int main(int argc, char** argv){
   ifstream* in = NULL;
   ofstream* out = NULL;

   if(argc < 3){
      cerr << "Usage: xor <key> <filename...>" << endl;
      exit(1);
   }

   int key = atoi(argv[1]);

   for(int x = 2; x < argc; x++){
      in = new ifstream(argv[x], ios::binary);
      if(!in->good()){
         cerr << "Error reading from " << argv[x] << endl;
         exit(1);
      }

      //Get file size
      in->seekg(0, ios::end);
      int size = in->tellg();
      in->seekg(0, ios::beg);

      //Allocate memory
      int* data = new int[size];

      int c = 0;
      for(int y = 0; (c = in->get()) != EOF; y++)
         data[y] = c ^ key;

      in->close();
      delete in;
      in = NULL;

      out = new ofstream(argv[x], ios::binary);
      if(!out->good()){
         cerr << "Error writing to " << argv[x] << endl;
         exit(1);
      }

      for(int y = 0; y < size; y++)
         out->put(data[y]);

      out->flush();
      out->close();
      delete out;
      out = NULL;

      delete[] data;
      data = NULL;
   }
   cout << "Operation complete" << endl;

   return 0;
}
</code>```

The shortest answer (whitespace doesn't count) that produces the same end result will be selected. It does not have to store everything in memory at once or open and close every file multiple times. It can do anything as long as a file encrypted with the reference program can be decrypted with the answer, and vice versa.

Edit: The above program is not a specification. The only requirement is that answers should be able to decrypt a file encrypted with the above program, and the above program should be able to decrypt a file encrypted with the answer. I'm sorry if that was unclear.

The above program can be compiled with:

```<code>g++ xorcipher.cpp -o ~/bin/xor
</code>```

It can be run like this:

```<code>xor <key> <filename...>
</code>```

For example, if the key is 42 and the file is alpha.txt, you would use:

```<code>xor 42 alpha.txt
</code>```

Body:
Python 75

import sys
for j in sys.stdin:print''.join(chr(int(sys.argv[1])^ord(i))for i in j),

The hardest requirement was not to keep the whole file in memory.

Usage:

python xor.py 123 <file.in >file.out


问:
Bitflip and negate
Given an integer, make an expression that produces it from 0 using unary negation - and bitwise complement ~ (~n = -n-1), with the operators applied right to left.

```<code>...
-3  = ~-~-~0
-2  = ~-~0
-1  = ~0
 0  = 0
 1  = -~0
 2  = -~-~0
 3  = -~-~-~0
...
</code>```

Your expression must be as short as possible, which means no redundant parts of ~~, --, -0, or 00. Output or print the expression as a string or a sequence of characters.

var QUESTION_ID=92598,OVERRIDE_USER=20260;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/92598/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

 <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

```

答:
05AB1E, <s>14</s> 13 bytes

```<code>Ä„-~×¹0‹i¦}0J
</code>```

Explanation

```<code> „-~           # the string "-~"
Ä   ×          # repeated abs(input) times
     ¹0‹i¦}    # if input is negative, remove the first char
           0J  # join with 0
</code>```

Try it online!

Title: Bitflip and negate

Body:
05AB1E, <s>14</s> 13 bytes

Ä„-~×¹0‹i¦}0J

Explanation

 „-~           # the string "-~"
Ä   ×          # repeated abs(input) times
     ¹0‹i¦}    # if input is negative, remove the first char
           0J  # join with 0

Try it online!


答:
PowerShell v3+, 33 bytes

```<code>$a=@();$args|%{$_-notin$a;$a+=$_}
</code>```

Takes input as command-line arguments of strings of the form Animal Gender where Gender is (pretty much) any identifier you want. Sets an empty array $a, then loops through the input arguments. Places the Boolean result of the -notin operator on the pipeline, and adds the current element into the $a array. PowerShell by default is case-insensitive when comparing strings, so Monkey f, monkey f, mOnKeY F and other variations will all evaluate as the same.

The resulting Booleans are left on the pipeline, and output via implicit Write-Output happens at program completion.

Example

```<code>PS C:\Tools\Scripts\golfing> .\noahs-upgraded-ark.ps1 'Monkey m' 'Monkey f' 'Monkey f' 'Monkey with symbols m' 'monkey m'
True
True
False
True
False
</code>```

Title: Noah's (upgraded) ark

Body:
PowerShell v3+, 33 bytes

$a=@();$args|%{$_-notin$a;$a+=$_}

Takes input as command-line arguments of strings of the form Animal Gender where Gender is (pretty much) any identifier you want. Sets an empty array $a, then loops through the input arguments. Places the Boolean result of the -notin operator on the pipeline, and adds the current element into the $a array. PowerShell by default is case-insensitive when comparing strings, so Monkey f, monkey f, mOnKeY F and other variations will all evaluate as the same.

The resulting Booleans are left on the pipeline, and output via implicit Write-Output happens at program completion.

Example

PS C:\Tools\Scripts\golfing> .\noahs-upgraded-ark.ps1 'Monkey m' 'Monkey f' 'Monkey f' 'Monkey with symbols m' 'monkey m'
True
True
False
True
False


答:
V, 21 bytes

```<code>/ä
é
D@"ña-~ñá0kgJó--
</code>```

Try it online!

V has very limited number support, and it actually has no concept of negative numbers. This means in order to support negatives (or even 0), we have to use some hacky workarounds.

Explanation:

```<code>/ä                  "Move forward to the first digit
é                   "And enter a newline
D                   "Delete this number, into register '"'
 @"                 "That number times:
   ñ   ñ            "Repeat the following:
    a               "  Append the string:
     -~             "  '-~'
        á0          "Append a 0
          k         "Move up a line
           gJ       "And join these two lines together
             ó--    "Remove the text '--', if it exists
</code>```

Title: Bitflip and negate

Body:
Given an integer, make an expression that produces it from 0 using unary negation - and bitwise complement ~ (~n = -n-1), with the operators applied right to left.

```<code>...
-3  = ~-~-~0
-2  = ~-~0
-1  = ~0
 0  = 0
 1  = -~0
 2  = -~-~0
 3  = -~-~-~0
...
</code>```

Your expression must be as short as possible, which means no redundant parts of ~~, --, -0, or 00. Output or print the expression as a string or a sequence of characters.

var QUESTION_ID=92598,OVERRIDE_USER=20260;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/92598/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

 <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

```

Body:
V, 21 bytes

/ä
é
D@"ña-~ñá0kgJó--

Try it online!

V has very limited number support, and it actually has no concept of negative numbers. This means in order to support negatives (or even 0), we have to use some hacky workarounds.

Explanation:

/ä                  "Move forward to the first digit
é                   "And enter a newline
D                   "Delete this number, into register '"'
 @"                 "That number times:
   ñ   ñ            "Repeat the following:
    a               "  Append the string:
     -~             "  '-~'
        á0          "Append a 0
          k         "Move up a line
           gJ       "And join these two lines together
             ó--    "Remove the text '--', if it exists


Title: Print multiplication tables by input

Body:
Stata, 46 bytes

args i
set obs `i'
gen x=_n
gen y=x*`i'
list y

Output

For i=15

    +-----+
    |   y |
    |-----|
 1. |  15 |
 2. |  30 |
 3. |  45 |
 4. |  60 |
 5. |  75 |
    |-----|
 6. |  90 |
 7. | 105 |
 8. | 120 |
 9. | 135 |
 10.| 150 |
    |-----|
 11.| 165 |
 12.| 180 |
 13.| 195 |
 14.| 210 |
 15.| 225 |


答:
Groovy 74 Bytes, 93 Bytes or 123 Bytes

I don't know which one you consider more fully answers the question but...

74 Byte Solution

```<code>{a,b->((1..a).collect{0}+(1..b).collect{1}).permutations().unique()}(1,2)
</code>```

For an input of 1,2 you get:

```<code>[[1,0,1], [0,1,1], [1,1,0]]
</code>```

93 Byte Solution

```<code>{a,b->((1..a).collect{0}+(1..b).collect{1}).permutations().collect{it.join()}.unique()}(1,2)
</code>```

For an input of 1,2 you get:

```<code>[101, 011, 110]
</code>```

123 Byte Solution

```<code>{a,b->((1..a).collect{0}+(1..b).collect{1}).permutations().collect{it.join()}.unique().collect{Integer.parseInt(it,2)}}(1,2)
</code>```

For an input of 1,2 you get:

```<code>[5, 3, 6]
</code>```

Try it out here:

https://groovyconsole.appspot.com/edit/5143619413475328

Title: All Binary Combinations to Decimal

Body:
Disclaimer

This question is not a duplicate of this question. I'm not counting specific digits, as we already have those set in the initial parameters. This question is focusing on the decimal numbers that can be constructed from the binary strings based on the digits provided.

Challenge

Given two integers X and Y, representing the number of zeroes (0) and ones (1) respectively, calculate all the possible decimal equivalents that can be determined from creating binary strings using only the zeroes and ones provided, and display them as output.

Example 1:

Input: 0 1

Output: 1

Explanation: Only one 1 to account for, which can only be converted one way.

Example 2:

Input: 1 1

Output: 1,2

Explanation: 01 converts to 1, 10 converts to 2.

Example 3:

Input: 3 2

Output: 3,5,6,9,10,12,17,18,20,24

Explanation: Three 0s and two 1s make 00011 (3), 00101 (5), 00110 (6), 01001 (9), 01010 (10), 01100 (12), 10001 (17), 10010 (18), 10100 (20), 11000 (24)

Limitations and Rules

I will only expect your code to work where 0 < X + Y <= 16 so the maximum number in the output could only occur from 16 1s, i.e. parameters 0 and 16.

As a result of the above limitation, the range of numbers we'd expect in the output are from 0 and 65535.

I will accept functions or code, so long as the resulting output is provided, whether this be a comma separated list, an array, list outputted to STDOUT, etc. The only criteria I must stress about the output is that it must be sorted.

This is code golf, minimum bytes will receive maximum glory.

We will not tolerate silly loopholes

Body:
Groovy 74 Bytes, 93 Bytes or 123 Bytes

I don't know which one you consider more fully answers the question but...

74 Byte Solution

{a,b->((1..a).collect{0}+(1..b).collect{1}).permutations().unique()}(1,2)

For an input of 1,2 you get:

[[1,0,1], [0,1,1], [1,1,0]]

93 Byte Solution

{a,b->((1..a).collect{0}+(1..b).collect{1}).permutations().collect{it.join()}.unique()}(1,2)

For an input of 1,2 you get:

[101, 011, 110]

123 Byte Solution

{a,b->((1..a).collect{0}+(1..b).collect{1}).permutations().collect{it.join()}.unique().collect{Integer.parseInt(it,2)}}(1,2)

For an input of 1,2 you get:

[5, 3, 6]

Try it out here:

https://groovyconsole.appspot.com/edit/5143619413475328


答:
Python, 32 bytes

lambda x:("-~"*abs(x))[x<0:]+"0"
```

Anonymous lambda function. Given an integer x writes "-~" abs(x) times and  removes the first char if x is negative, then a zero is added to the end.

Title: Bitflip and negate

Body:
Python, 32 bytes

lambda x:("-~"*abs(x))[x<0:]+"0"

Anonymous lambda function. Given an integer x writes "-~" abs(x) times and  removes the first char if x is negative, then a zero is added to the end.


答:
EXCEL: <s>55</s> 33 bytes

```<code>=REPT("-~",IF(A1>0,A1,ABS(A1)-1))&"0"
</code>```

Input is in the form of putting a number in the A1 cell. Formula can go anywhere except A1.

Title: Bitflip and negate

Body:
EXCEL: <s>55</s> 33 bytes

=REPT("-~",IF(A1>0,A1,ABS(A1)-1))&"0"

Input is in the form of putting a number in the A1 cell. Formula can go anywhere except A1.


问:
Simulate a Rubik's cube
A Rubik's cube has 6 colors: red, orange, yellow, white, blue, and green. Red and orange, yellow and white, and blue and green faces are on opposite sides.

Net of a solved Rubik's cube looks like this:

```<code> Y
BRGO
 W
</code>```

And the tiles look like this:

```<code>      Y Y Y
      Y Y Y
      Y Y Y
B B B R R R G G G O O O
B B B R R R G G G O O O
B B B R R R G G G O O O
      W W W
      W W W
      W W W
</code>```

Challenge

Given rotations, reversed rotations, or double rotations output what a solved cube will transform to, as ASCII art or as an image (whitespaces aren't necessary, may or may not exist, trailing whitespaces are allowed.).

Input will be rotation (and optional modifier). Rotation notation goes like: U(p), L(eft), F(ront), R(ight), B(ack), D(own); 2 (double), ' or i (inverse).

All normal rotations will be 90° clockwise, inverse ones will be counterclockwise.

Explanation about clockwiseness: Imagine the cube as you're looking at the red face, and the yellow face is at the top. Then rotate the cube so that the face that the program will rotate will face you. This is the way clockwiseness will work. (Except back face, you will rotate the cube horizontally in that case.)

Input

Input will be a list of moves.

Output

An ASCII art that represents the cube or an image of the net of the cube.

Examples

Input:  (empty)

Output:

```<code>      Y Y Y
      Y Y Y
      Y Y Y
B B B R R R G G G O O O
B B B R R R G G G O O O
B B B R R R G G G O O O
      W W W
      W W W
      W W W
</code>```

Input: U (up)

Output:

```<code>      Y Y Y
      Y Y Y
      Y Y Y
R R R G G G O O O B B B
B B B R R R G G G O O O
B B B R R R G G G O O O
      W W W
      W W W
      W W W
</code>```

Input: U' or Ui (inverse up)

Output:

```<code>      Y Y Y
      Y Y Y
      Y Y Y
O O O B B B R R R G G G
B B B R R R G G G O O O
B B B R R R G G G O O O
      W W W
      W W W
      W W W
</code>```

Input: U2 (double up)

Output:

```<code>      Y Y Y
      Y Y Y
      Y Y Y
G G G O O O B B B R R R
B B B R R R G G G O O O
B B B R R R G G G O O O
      W W W
      W W W
      W W W
</code>```

Input: L' (inversed left)

Output:

```<code>      R Y Y
      R Y Y
      R Y Y
B B B W R R G G G O O Y
B B B W R R G G G O O Y
B B B W R R G G G O O Y
      O W W
      O W W
      O W W
</code>```

Input: R (right)

Output:

```<code>      Y Y R
      Y Y R
      Y Y R
B B B R R W G G G Y O O
B B B R R W G G G Y O O
B B B R R W G G G Y O O
      W W O
      W W O
      W W O
</code>```

Input: U2 L' D (double up, inverse left, down)

Output:

```<code>      O Y Y
      R Y Y
      R Y Y
G B B W O O B B B R R Y
G B B W R R G G G O O Y
O O Y G B B W R R G G G
      R O O
      W W W
      W W W
</code>```

Rules

No loopholes allowed.

This is code-golf, so shortest code in bytes solving the problem wins.

Title: Simulate a Rubik's cube

Body:
Python 760 750 649 Bytes

shamelessly stole the idea of using only 3 rotations from @Paul Schmitz :D

new version:

from numpy import*
c=kron([[32,89,32,32],[66,82,71,79],[32,87,32,32]],ones([3,3])).astype(int)
def x():t=copy(c);c[:3,3:6],c[3:6,3:6],c[6:,3:6],c[3:6,9:],c[3:6,:3],c[3:6,6:9]=t[3:6,3:6],t[6:,3:6],rot90(t[3:6,9:],2),rot90(t[:3,3:6],2),rot90(t[3:6,:3]),rot90(t[3:6,6:9],3)
def y():c[3:6],c[:3,3:6],c[6:,3:6]=roll(c[3:6],3,1),rot90(c[:3,3:6]),rot90(c[6:,3:6],3)
def F():c[2:7,2:7]=rot90(c[2:7,2:7],3)
s=raw_input()
for p in"':i,Fi:FFF,F2:FF,Bi:BBB,B2:BB,Ri:RRR,R2:RR,Li:LLL,L2:LL,Ui:UUU,U2:UU,Di:DDD,D2:DD,B:xxFxx,R:yyyFy,L:yFyyy,U:xxxFx,D:xFxxx".split(','):s=s.replace(*p.split(':'))
for S in s:eval(S+'()')
for r in c:print(''.join(chr(x)for x in r))

I mostly just did lots of numpy list slicing and used its built in rotate and roll functions. Input is handled by calling the functions directly with eval()

from numpy import*
l=[0];c=kron([[32,89,32,32],[66,82,71,79],[32,87,32,32]],ones([3,3])).astype(int)
def i():l[0]();l[0]()
def d():l[0]()
def U():c[:3,3:6]=rot90(c[:3,3:6],3);c[3]=roll(c[3],9);l[0]=U
def D():c[6:,3:6]=rot90(c[6:,3:6],3);c[5]=roll(c[5],3);l[0]=D
def F():c[2:7,2:7]=rot90(c[2:7,2:7],3);l[0]=F
def B():c[3:6,9:]=rot90(c[3:6,9:],3);t=copy(c);c[:,:9],c[1:-1,1:8]=rot90(t[:,:9]),t[1:-1,1:8];l[0]=B
def R():c[3:6,6:9]=rot90(c[3:6,6:9],3);t=copy(c);c[:6,5],c[3:6,9],c[6:,5]=t[3:,5],t[2::-1,5],t[5:2:-1,9];l[0]=R
def L():c[3:6,:3]=rot90(c[3:6,:3],3);t=copy(c);c[3:,3],c[3:6,-1],c[:3,3]=t[:6,3],t[:5:-1,3],t[5:2:-1,-1];l[0]=L
for s in raw_input().replace("'",'i').replace('2','d').replace(' ',''):eval(s+'()')
for r in c:print(''.join(chr(x)for x in r))

ungolfed..

import numpy as np
last = [0] #store last move to repeat for inverse or double
           #list is shorter syntax than global var

cube = np.array([
[' ',' ',' ','Y','Y','Y',' ',' ',' ',' ',' ',' '],
[' ',' ',' ','Y','Y','Y',' ',' ',' ',' ',' ',' '],
[' ',' ',' ','Y','Y','Y',' ',' ',' ',' ',' ',' '],
['B','B','B','R','R','R','G','G','G','O','O','O'],
['B','B','B','R','R','R','G','G','G','O','O','O'],
['B','B','B','R','R','R','G','G','G','O','O','O'],
[' ',' ',' ','W','W','W',' ',' ',' ',' ',' ',' '],
[' ',' ',' ','W','W','W',' ',' ',' ',' ',' ',' '],
[' ',' ',' ','W','W','W',' ',' ',' ',' ',' ',' ']
]) #ascii ascii codes in golfed version

def i(): #triple move (inverse)
    last[0]()
    last[0]()

def d(): #double move
    last[0]()

def U(): #clockwise upface (yellow)
    cube[:3,3:6] = np.rot90(cube[:3,3:6],3)
    cube[3] = np.roll(cube[3],9)
    last[0] = U

def D(): #clockwise downface (white)
    cube[6:,3:6] = np.rot90(cube[6:,3:6],3)
    cube[5] = np.roll(cube[5],3)
    last[0] = D

def F(): #clockwise frontface (red)
    cube[2:7,2:7] = np.rot90(cube[2:7,2:7],3)
    last[0] = F

def B(): #clockwise backface (orange)
    cube[3:6,9:] = np.rot90(cube[3:6,9:],3)
    tempCube = np.copy(cube)
    cube[:,:9],cube[1:-1,1:8] = np.rot90(tempCube[:,:9]),tempCube[1:-1,1:8]
    last[0] = B

def R(): #clockwise rightface (green)
    cube[3:6,6:9] = np.rot90(cube[3:6,6:9],3)
    tempCube = np.copy(cube)
    cube[:6,5],cube[3:6,9],cube[6:,5] = tempCube[3:,5],tempCube[2::-1,5],tempCube[5:2:-1,9]
    last[0] = R

def L(): #clockwise leftface (blue)
    cube[3:6,:3] = np.rot90(cube[3:6,:3],3)
    tempCube = np.copy(cube)
    cube[3:,3],cube[3:6,-1],cube[:3,3] = tempCube[:6,3],tempCube[:5:-1,3],tempCube[5:2:-1,-1]
    last[0] = L

for character in raw_input('type a move sequence: ').replace("'",'i').replace('2','d').replace(' ',''):
    eval(character+'()')

print("-"*12)

for row in cube:
    print(''.join(character for character in row)) #uses ascii codes in golfed version

test input:

>>> runfile('C:~/rubiks cube.py', wdir='C:~/python/golf')
U2 L' D
   OYY
   RYY
   RYY
GBBWOOBBBRRY
GBBWRRGGGOOY
OOYGBBWRRGGG
   ROO
   WWW
   WWW

Comments or suggestions are greatly appreciated :)


问:
RGB Gradients Generation
The Challenge

Given the two uppercase hexadecimal strings (both 6 characters long, XXXXXX and YYYYYY) representing RGB values (ranging from 000000 to FFFFFF inclusive), and a positive non-zero integer N, display a linear transition of the N+2 colors generated from XXXXXX to YYYYYY that would result in a color gradient.

Example

Input

```<code>FF3762
F08800
9
</code>```

Output

Please note in our example, I've requested 9 interim steps between the two colors, therefore 11 lines will be displayed from initial color to the final color

```<code>FF3762
FD3F58
FC474E
FA4F44
F9573A
F75F31
F66727
F46F1D
F37713
F17F09
F08800
</code>```

Caveats

While I've gone with a simple linear process of deriving the integer values for the interim colors before converting them back into hexadecimal, your methods may vary. Please consider the various ways one could round up/down your numbers accordingly.

Testing

To make this interesting, I've provided a snippet to allow testing of your code, inclusive of a button to provide you with two random colors to test your code against. Displaying your results is optional, but it's encouraged!

c1=()=>('00000'+(Math.random()*(1<<24)|0).toString(16)).slice(-6);

$("#col").click(function(){
  alert("Your two colors are: "+c1()+" and "+c1()+".");
});

$("#colors").blur(function(){
  $("#test").empty();
 var colArr = $("#colors").val().split("\n");
 for(c in colArr){
   $("#test").append('
'+colArr[c]+'
')
  }

});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>.tester{height: 20px;
width: 60px;padding: 4px;border: 1px solid black;}</code>```

<button id="col">Your two colors</button>

<textarea id="colors"></textarea>

```

1) You can access two random colors for your test by clicking on the "Your two colors" button.
2) The number of interim steps will be the same as the number of characters in your PPCG username inclusive of spaces, in the case of "WallyWest" it would be 9 (as per my example above).
3) Run your code with the two colors and the number and once you have your generated list, you have the option of pasting your output into the textarea and tabbing away from it to get your generated color gradient.

My example is shown here:

I must admit, that looks pretty awesome!

Please note: As I mentioned, showing your testing of your output using the snippet is optional, but it's encouraged! :)

Output

The list output must be in the form of N+2 sets of 6 digit hex numbers separated by line feeds (\n) as shown in my example above. Output can be in the form of separate lines, space/comma separated list, an array or whatever is best suited for your language... (Thanks @nimi for the heads up) Please remember, that if you plan on testing your code with the snippet, however you separate each "color" is up to you.

Rules

This is code-golf, so the shortest solution in bytes will be crowned the winner. No loopholes, naturally. Input must accept the two strings and a number (which as I said will be equivalent to the number of letters in your username on PPCG, thus your resulting output will always be a minimum of three lines long.

答:
Python 2, 189 bytes

w='[int(%s[i:i+2],16)for i in range(0,6,2)]'
def f(a,b,n):
 l=lambda x,y:'%02x'%int((x*(n-i)+y*i)/n);c,d,e=eval(w%'a');f,g,h=eval(w%'b');n+=1
 for i in range(n+1):print l(c,f)+l(d,g)+l(e,h)
```

Title: RGB Gradients Generation


答:
3d, 35 bytes

Code:

```<code>>#a…:>×=$v
   ;, !a#—v
     ^ ! '<
</code>```

Explanation:

```<code>#a push 10
…  push every number in the range top..1 (=> 10..1)
:  input number
×  push product of top two of the stack
=  output as number
$  invert top two of the stack
—  pops stack and check if null
if is null:
    #a! print newline
    ,;  pops silently and exits
if not:
    ' ! print a space
... and loops back to ×
</code>```

Title: Print multiplication tables by input

Body:
In this challenge you've to print multiplication tables by input, Here are some examples:

```<code>Input: 2

Output:
0 2  4 6 8  10  12  14  16  18  20

Input: 20

Output: 20 40 60 80 100 120 140 160 180 200
</code>```

Rules

The shortest code in bytes wins.

This challenge is a code-golf, It follows code-golf general rules (code-golf)

If, just if, your code can't print number, you can use letters, Here is an example:

Input: B

Output: B D F H J L N P R T

You can choose to start from 0 or your number (like 20). You can choose if put spaces or don't. The challenge is free, just take an input and print multiplication tables.

Your output must list the first 10 members of the times table for the given number. You may leave out 0*n.

Body:
3d, 35 bytes

Code:

>#a…:>×=$v
   ;, !a#—v
     ^ ! '<

Explanation:

#a push 10
…  push every number in the range top..1 (=> 10..1)
:  input number
×  push product of top two of the stack
=  output as number
$  invert top two of the stack
—  pops stack and check if null
if is null:
    #a! print newline
    ,;  pops silently and exits
if not:
    ' ! print a space
... and loops back to ×


答:
JavaScript (ES6), <s>39</s> 37 bytes

x=>"-~".repeat(x<0?-x:x).slice(x<0)+0
```

Saved 2 bytes thanks to @Neil

Title: Bitflip and negate

Body:
JavaScript (ES6), <s>39</s> 37 bytes

x=>"-~".repeat(x<0?-x:x).slice(x<0)+0

Saved 2 bytes thanks to @Neil


Title: Bitflip and negate

Body:
Ruby, 34 bytes

->x{("-~"*x.abs+?0)[2[0<=>x]..-1]}


答:
Retina, <s>19</s> 17 bytes

Replace the number with unary, with a zero on the end. Replace each 1 with -~. Remove double negative if there is one.

```<code>\d+
$*10
1
-~
--

</code>```

Try it online

All test cases at once (slightly modified program to support multiple test cases)

Title: Bitflip and negate

Body:
Retina, <s>19</s> 17 bytes

Replace the number with unary, with a zero on the end. Replace each 1 with -~. Remove double negative if there is one.

\d+
$*10
1
-~
--

Try it online

All test cases at once (slightly modified program to support multiple test cases)


Title: Bitflip and negate

Body:
PHP, 61 bytes

if(0>$n=$argv[1]){echo"~";$n=~$n;}echo str_repeat("-~",$n),0;


Title: Bitflip and negate

Body:
Perl 38 35 33 (23 + 1 for -p) 24

s/\d+/"-~"x$&.0/e;s;--;

-13 thanks to Dada


Title: Bitflip and negate

Body:
Matlab, 61 bytes

x=input('');A=repmat('-~',1,abs(x));disp([A((x<0)+1:end) 48])


答:
Pyth, <s>14</s> <s>13</s> 12 Bytes

```<code>_<>0Q+0sm"~-
</code>```

-2 Bytes thanks to @StevenH.

test suite

Decided to try out Pyth, so i translated my python answer to it. Any help welcome!

Explanation:

```<code>_<>0Q+0sm"~-
        m"~-     # Map "~-" onto the input (= a list of n times "~-").
       s         # Join the list to a string.
     +0          # Add "0" in front.
 <>0Q            # Slice off the last char if the input is negative.
_                # Reverse the whole thing.
</code>```

Title: Bitflip and negate

Body:
Pyth, <s>14</s> <s>13</s> 12 Bytes

_<>0Q+0sm"~-

-2 Bytes thanks to @StevenH.

test suite

Decided to try out Pyth, so i translated my python answer to it. Any help welcome!

Explanation:

_<>0Q+0sm"~-
        m"~-     # Map "~-" onto the input (= a list of n times "~-").
       s         # Join the list to a string.
     +0          # Add "0" in front.
 <>0Q            # Slice off the last char if the input is negative.
_                # Reverse the whole thing.


答:
Dyalog APL, 44 bytes

Prompts for N, then Beginning-color, then Ending-color. Needs ⎕IO←0 which is default on many systems.

h[↑⌊B∘+¨(⍳2+N)×(-/E B←(h←⎕D,⎕A)∘⍳¨⍞⍞)÷1+N←⎕]
```
<p><code>h[</code>...<code>]</code> index into <strong>h</strong> (which has a value when we finish evaluating the the bracket's content)</p>
<p> <code>N←⎕</code> prompt for numeric <strong>N</strong> (4)</p>
<p> <code>1+</code> add one to <strong>N</strong> (5)</p>
<p> <code>(</code>...<code>)÷</code> use that to divide the result of...</p>
<p>  <code>⍞⍞</code> prompt for two character strings ["7E0E7E","FF3762"]</p>
<p>  <code>(</code>...<code>)∘⍳¨</code> find the indices of the each string's characters in...</p>
<p>   <code>⎕D,⎕A</code> <strong>D</strong>igits followed by <strong>A</strong>lphabet</p>
<p>   <code>h←</code> assigned to <strong>h</strong></p>
<p>  now we have "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"</p>
<p>  <code>E B←</code> assign the indices to <strong>E</strong> and <strong>B</strong> [[7,14,0,14,7,14],[15,15,3,7,6,2]]</p>
<p>  <code>-/</code> subtract and enclose <strong>B</strong> from <strong>E</strong> [[-8,-1,-3,7,1,12]]</p>
<p>  the result so far is [[-1.6,-0.2,-0.6,1.4,0.2,2.4]]</p>
<p> <code>(</code>...<code>)×</code> multiply this by...</p>
<p>  <code>2+N</code> two plus <strong>N</strong> (6)</p>
<p>  <code>⍳</code> first integers [0,1,2,3,4,5]</p>
<p> this gives us [[0,0,0,0,0,0],[-1.6,-0.2,-0.6,1.4,0.2,2.4],[-3.2,-0.4,-1.2,2.8,0.4,4.8],...]</p>
<p> <code>B∘+¨</code> add <strong>B</strong> to each [[15,15,3,7,6,2],[13.4,14.8,2.4,8.4,6.2,4.4],[11.8,14.6,1.8,9.8,6.4,6.8],...]</p>
<p> <code>⌊</code> round down [[15,15,3,7,6,2],[13,14,2,8,6,4],[11,14,1,9,6,6],...]</p>
<p> <code>↑</code> make list of lists into table</p>
<pre class="lang-apl prettyprint-override"><code>[[15,15, 3, 7, 6, 2]
 [13,14, 2, 8, 6, 4]
 [11,14, 1, 9, 6, 6]
 [10,14, 1,11, 6, 9]
 [ 8,14, 0,12, 6,11]
 [ 7,14, 0,14, 7,14]]
</code>```

here we index into h, giving

[["F","F","3","7","6","2]
 ["D","E","2","8","6","4]
 ["B","E","1","9","6","6]
 ["A","E","1","B","6","9]
 ["8","E","0","C","6","B]
 ["7","E","0","E","7","E]]
```
<p>which is the same as</p>
<pre class="lang-apl prettyprint-override"><code>[["FF3762"]
 ["DE2864"]
 ["BE1966"]
 ["AE1B69"]
 ["8E0C6B"]
 ["7E0E7E"]]
</code>```

and prints as

FF3762
DE2864
BE1966
AE1B69
8E0C6B
7E0E7E
```

TryAPL online!

Title: RGB Gradients Generation

Body:
The Challenge

Given the two uppercase hexadecimal strings (both 6 characters long, XXXXXX and YYYYYY) representing RGB values (ranging from 000000 to FFFFFF inclusive), and a positive non-zero integer N, display a linear transition of the N+2 colors generated from XXXXXX to YYYYYY that would result in a color gradient.

Example

Input

```<code>FF3762
F08800
9
</code>```

Output

Please note in our example, I've requested 9 interim steps between the two colors, therefore 11 lines will be displayed from initial color to the final color

```<code>FF3762
FD3F58
FC474E
FA4F44
F9573A
F75F31
F66727
F46F1D
F37713
F17F09
F08800
</code>```

Caveats

While I've gone with a simple linear process of deriving the integer values for the interim colors before converting them back into hexadecimal, your methods may vary. Please consider the various ways one could round up/down your numbers accordingly.

Testing

To make this interesting, I've provided a snippet to allow testing of your code, inclusive of a button to provide you with two random colors to test your code against. Displaying your results is optional, but it's encouraged!

c1=()=>('00000'+(Math.random()*(1<<24)|0).toString(16)).slice(-6);

$("#col").click(function(){
  alert("Your two colors are: "+c1()+" and "+c1()+".");
});

$("#colors").blur(function(){
  $("#test").empty();
 var colArr = $("#colors").val().split("\n");
 for(c in colArr){
   $("#test").append('
'+colArr[c]+'
')
  }

});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>.tester{height: 20px;
width: 60px;padding: 4px;border: 1px solid black;}</code>```

<button id="col">Your two colors</button>

<textarea id="colors"></textarea>

```

1) You can access two random colors for your test by clicking on the "Your two colors" button.
2) The number of interim steps will be the same as the number of characters in your PPCG username inclusive of spaces, in the case of "WallyWest" it would be 9 (as per my example above).
3) Run your code with the two colors and the number and once you have your generated list, you have the option of pasting your output into the textarea and tabbing away from it to get your generated color gradient.

My example is shown here:

I must admit, that looks pretty awesome!

Please note: As I mentioned, showing your testing of your output using the snippet is optional, but it's encouraged! :)

Output

The list output must be in the form of N+2 sets of 6 digit hex numbers separated by line feeds (\n) as shown in my example above. Output can be in the form of separate lines, space/comma separated list, an array or whatever is best suited for your language... (Thanks @nimi for the heads up) Please remember, that if you plan on testing your code with the snippet, however you separate each "color" is up to you.

Rules

This is code-golf, so the shortest solution in bytes will be crowned the winner. No loopholes, naturally. Input must accept the two strings and a number (which as I said will be equivalent to the number of letters in your username on PPCG, thus your resulting output will always be a minimum of three lines long.

Body:
Dyalog APL, 44 bytes

Prompts for N, then Beginning-color, then Ending-color. Needs ⎕IO←0 which is default on many systems.

h[↑⌊B∘+¨(⍳2+N)×(-/E B←(h←⎕D,⎕A)∘⍳¨⍞⍞)÷1+N←⎕]

h[...] index into h (which has a value when we finish evaluating the the bracket's content)

 N←⎕ prompt for numeric N (4)

 1+ add one to N (5)

 (...)÷ use that to divide the result of...

  ⍞⍞ prompt for two character strings ["7E0E7E","FF3762"]

  (...)∘⍳¨ find the indices of the each string's characters in...

   ⎕D,⎕A Digits followed by Alphabet

   h← assigned to h

  now we have "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"

  E B← assign the indices to E and B [[7,14,0,14,7,14],[15,15,3,7,6,2]]

  -/ subtract and enclose B from E [[-8,-1,-3,7,1,12]]

  the result so far is [[-1.6,-0.2,-0.6,1.4,0.2,2.4]]

 (...)× multiply this by...

  2+N two plus N (6)

  ⍳ first integers [0,1,2,3,4,5]

 this gives us [[0,0,0,0,0,0],[-1.6,-0.2,-0.6,1.4,0.2,2.4],[-3.2,-0.4,-1.2,2.8,0.4,4.8],...]

 B∘+¨ add B to each [[15,15,3,7,6,2],[13.4,14.8,2.4,8.4,6.2,4.4],[11.8,14.6,1.8,9.8,6.4,6.8],...]

 ⌊ round down [[15,15,3,7,6,2],[13,14,2,8,6,4],[11,14,1,9,6,6],...]

 ↑ make list of lists into table

[[15,15, 3, 7, 6, 2]
 [13,14, 2, 8, 6, 4]
 [11,14, 1, 9, 6, 6]
 [10,14, 1,11, 6, 9]
 [ 8,14, 0,12, 6,11]
 [ 7,14, 0,14, 7,14]]

here we index into h, giving

[["F","F","3","7","6","2]
 ["D","E","2","8","6","4]
 ["B","E","1","9","6","6]
 ["A","E","1","B","6","9]
 ["8","E","0","C","6","B]
 ["7","E","0","E","7","E]]

which is the same as

[["FF3762"]
 ["DE2864"]
 ["BE1966"]
 ["AE1B69"]
 ["8E0C6B"]
 ["7E0E7E"]]

and prints as

FF3762
DE2864
BE1966
AE1B69
8E0C6B
7E0E7E

TryAPL online!


问:
Cambridge Transposition
I'm sure most, if not all, of you have come across this at some point or another:

Aoccdrnig to a rscheeachr at Cmabrigde Uinervtisy, it deosn't mttaer
in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is
taht the frist and lsat ltteer be at the rghit pclae. The rset can be
a toatl mses and you can sitll raed it wouthit porbelm. Tihs is
bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the
wrod as a wlohe.

Create a program that inputs any amount of text. For testing purposes, use the unscrambled version of the above text, found below.

The program must then randomly transpose the letters of each word with a length of 4 or more letters, except the first and last letter of each word.

All other formatting must remain the same (capitalization and punctuation, etc.).

Testing text:

According to a researcher at Cambridge University, it doesn't matter
in what order the letters in a word are, the only important thing is
that the first and last letter be at the right place. The rest can be
a total mess and you can still read it without problem. This is
because the human mind does not read every letter by itself but the
word as a whole.

As usual, this is a code-golf. Shortest code wins.

答:
PHP 84 bytes

```<code><?for(;$s=fgets(STDIN);)echo preg_filter('/\w\K\w+(?=\w)/e','str_shuffle("\0")',$s);
</code>```

Using a regex to capture words that are at least <s>4</s> 3 letters long†, and shuffling the inner characters. This code can handle input with multiple lines as well.

If only one line of input is required (as in the example), this can be reduced to 68 bytes

```<code><?=preg_filter('/\w\K\w+(?=\w)/e','str_shuffle("\0")',fgets(STDIN));
</code>```

† There's only one letter in the middle, so it doesn't matter if you shuffle it.

ContentLicense: CC BY-SA 4.0

Title: Cambridge Transposition

Body:
PHP 84 bytes

<?for(;$s=fgets(STDIN);)echo preg_filter('/\w\K\w+(?=\w)/e','str_shuffle("\0")',$s);

Using a regex to capture words that are at least <s>4</s> 3 letters long†, and shuffling the inner characters. This code can handle input with multiple lines as well.

If only one line of input is required (as in the example), this can be reduced to 68 bytes

<?=preg_filter('/\w\K\w+(?=\w)/e','str_shuffle("\0")',fgets(STDIN));

† There's only one letter in the middle, so it doesn't matter if you shuffle it.


Title: Bitflip and negate

Body:
Given an integer, make an expression that produces it from 0 using unary negation - and bitwise complement ~ (~n = -n-1), with the operators applied right to left.

```<code>...
-3  = ~-~-~0
-2  = ~-~0
-1  = ~0
 0  = 0
 1  = -~0
 2  = -~-~0
 3  = -~-~-~0
...
</code>```

Your expression must be as short as possible, which means no redundant parts of ~~, --, -0, or 00. Output or print the expression as a string or a sequence of characters.

var QUESTION_ID=92598,OVERRIDE_USER=20260;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/92598/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

 <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

```

Body:
Haskell, 41 bytes

<s>f n=['-'|n>0]++(tail$[1..abs n]>>"-~")++"0"</s>

f n|n<0=tail$f(-n)|x<-[1..n]>>"-~"=x++"0"

Thanks to nimi for 3 bytes


答:
Dyalog APL, 5 bytes

Begins at 0× or 1× depending on ⎕IO.

⎕×⍳10
```

⎕ input

× times

⍳10 first 10 integers

TryAPL online: with ⎕IO←0
and
with ⎕IO←1
.

Title: Print multiplication tables by input

Body:
Dyalog APL, 5 bytes

Begins at 0× or 1× depending on ⎕IO.

⎕×⍳10

⎕ input

× times

⍳10 first 10 integers

TryAPL online: with ⎕IO←0
and
with ⎕IO←1
.


答:
Dyalog APL, 3 bytes

∊,\
```

∊ flatten the

,\ cumulative concatenation

TryAPL online!

Title: Stringsplode the String!

Body:
The challenge is relatively simple, but will hopefully lead to some wonderfully creative answers. The task is to take a string as an input (via command line, function parameter etc.) and output/return a stringsploded version of it.

A stringsploded version of a string is its first letter followed by its first 2 letters, followed by its first 3 letters,... until you finally output the complete word.

You are guaranteed that the input will consist of printable ASCII characters and that the input will all be on one line (no new line characters).

Here are examples to clarify what stringsplosions are:

```<code>Input                 Output
==================================================================
"Code"       ---->   "CCoCodCode"
"name"       ---->   "nnanamname"
"harambe"    ---->   "hhaharharaharamharambharambe"
"sp aces?"   ---->   "sspsp sp asp acsp acesp acessp aces?"
"1234"       ---->   "1121231234"
"ss"         ---->   "sss"
</code>```

This is code golf so shortest code wins + up votes for interesting uses of your respective language.

Good luck!

Body:
Dyalog APL, 3 bytes

∊,\

∊ flatten the

,\ cumulative concatenation

TryAPL online!


答:
Python, <s>54 52</s> 50 bytes

```<code>def f(s,l={}):x=s.lower();r=x in l;l[x]=1;return r
</code>```

Test case is at ideone

This borrows this neat idea from @gowrath, but extends it by using the fact that when a function is defined with a default argument that is mutable, like a dictionary, it acts as a memoisation (the object retains state between function calls).

Saved 2 bytes by returning None for truthy ("Y") and 0 for falsey ("N").

Save 2 more by (confusingly) returning False for truthy ("Y") and True for falsey ("N").

Title: Noah's (upgraded) ark

Body:
As preparation for the nth Exodus, Noah decides to write a program that will decide If he will let animals on his ark.  However, Noah wants to go back to grass roots. Thus he decides that the program should be as small and as simple as possible.

GOAL:

Recreate the Contrabulous Choosematron, in a way that follows evangelical stories.

INPUT:

The program is simple, and elegant, and takes in 2 inputs:

The species of animal [String]

and The animal's gender [boolean]

OUTPUT:

The program then puts out Either 'Y' or 'N', Which determines whether or not the given  animal is allowed onto the ark.

RULES:

Only one Animal of each species and gender is allowed on the ark. No more.

Your output can be any set of boolean values (true false, yes no, y n, yin yang) so long as they're easily distinguishable.

If your program should want to accept a list of input, rather than use STDIN, that's fine. However, each output has to be in corresponding order of the input (FIFO), as well as be in the exact same format as the input.

This is a golf, so the lowest byte count wins, good luck!!!!

EXAMPLE:

"Monkey" true<

y

"Monkey" false<

y

"Monkey" false<

n

"Monkey with symbols" false<

y

"monkey" true<

n

This is valid, as your program doesn't need to distinguish that Monkey, and monkey with symbols are the same thing species, however, Monkey and monkey are very much the same thing, and so the last critter would be denied.

Body:
Python, <s>54 52</s> 50 bytes

def f(s,l={}):x=s.lower();r=x in l;l[x]=1;return r

Test case is at ideone

This borrows this neat idea from @gowrath, but extends it by using the fact that when a function is defined with a default argument that is mutable, like a dictionary, it acts as a memoisation (the object retains state between function calls).

Saved 2 bytes by returning None for truthy ("Y") and 0 for falsey ("N").

Save 2 more by (confusingly) returning False for truthy ("Y") and True for falsey ("N").


答:
JavaScript (ES6), 130 bytes

g=
(f,t,n)=>[...Array(++n+1)].map((_,i)=>f.replace(/../g,(e,j)=>((`0x${e}`*(n-i)+`0x${t[j]+t[j+1]}`*i)/n|256).toString(16).slice(1)))
;
p=_=>g(f.value,t.value,+n.value).map(e=>o.insertRow().insertCell().appendChild(document.createTextNode(e)).parentNode.bgColor=e);```
<pre class="snippet-code-html lang-html prettyprint-override"><code><input id=f value=e14f09><input id=t value=9a04f6><input id=n value=4 type=number><input type=button onclick=p() value=Go!><table id=o bgcolor=black cellpadding=4></code>```

Title: RGB Gradients Generation

Body:
JavaScript (ES6), 130 bytes

g=
(f,t,n)=>[...Array(++n+1)].map((_,i)=>f.replace(/../g,(e,j)=>((`0x${e}`*(n-i)+`0x${t[j]+t[j+1]}`*i)/n|256).toString(16).slice(1)))
;
p=_=>g(f.value,t.value,+n.value).map(e=>o.insertRow().insertCell().appendChild(document.createTextNode(e)).parentNode.bgColor=e);

<input id=f value=e14f09><input id=t value=9a04f6><input id=n value=4 type=number><input type=button onclick=p() value=Go!><table id=o bgcolor=black cellpadding=4>


答:
CJam, <s>18</s> 14 bytes

Took some inspiration from Emigna's answer to save 4 bytes.

```<code>li_z"-~"*\0<>0
</code>```

Try it online! (As a linefeed-separated test suite.)

Explanation

```<code>li      e# Read input and convert to integer N.
_z      e# Duplicate and get |N|.
"-~"*   e# Repeat this string |N| times.
\0<     e# Use the other copy of N to check if it's negative.
>       e# If so, discard the first '-'.
0       e# Put a 0 at the end.
</code>```

Title: Bitflip and negate

Body:
CJam, <s>18</s> 14 bytes

Took some inspiration from Emigna's answer to save 4 bytes.

li_z"-~"*\0<>0

Try it online! (As a linefeed-separated test suite.)

Explanation

li      e# Read input and convert to integer N.
_z      e# Duplicate and get |N|.
"-~"*   e# Repeat this string |N| times.
\0<     e# Use the other copy of N to check if it's negative.
>       e# If so, discard the first '-'.
0       e# Put a 0 at the end.


Title: Print multiplication tables by input

Body:
In this challenge you've to print multiplication tables by input, Here are some examples:

```<code>Input: 2

Output:
0 2  4 6 8  10  12  14  16  18  20

Input: 20

Output: 20 40 60 80 100 120 140 160 180 200
</code>```

Rules

The shortest code in bytes wins.

This challenge is a code-golf, It follows code-golf general rules (code-golf)

If, just if, your code can't print number, you can use letters, Here is an example:

Input: B

Output: B D F H J L N P R T

You can choose to start from 0 or your number (like 20). You can choose if put spaces or don't. The challenge is free, just take an input and print multiplication tables.

Your output must list the first 10 members of the times table for the given number. You may leave out 0*n.

Body:
Haskell, 16 bytes

(<$>[1..10]).(*)

Usage example: (<$>[1..10]).(*) $ 4 -> [4,8,12,16,20,24,28,32,36,40].

Pointfree version of: f n = map (n*) [1..10].


答:
Dyalog APL, 16 bytes

Case sensitive solution:

(⍳⍴)∊(∪⍳⍨)
```
<p><code>(⍳⍴)</code> which indices</p>
<p><code>∊</code> are member of</p>
<p><code>⍳⍨</code> each entry's first occurrence in the list</p>
<p>Unfortunately, case-insensitivity is bulky:</p>
<pre class="lang-apl prettyprint-override"><code>(⍳⍴)∊(∪c⍳c←819⌶)
</code>```

c←819⌶ assign the lowercase function to c

c⍳c is the same as ⍳⍨c. See explanation above.

TryAPL online! (casing is not supported on TryAPL)

Title: Noah's (upgraded) ark

Body:
Dyalog APL, 16 bytes

Case sensitive solution:

(⍳⍴)∊(∪⍳⍨)

(⍳⍴) which indices

∊ are member of

⍳⍨ each entry's first occurrence in the list

Unfortunately, case-insensitivity is bulky:

(⍳⍴)∊(∪c⍳c←819⌶)

c←819⌶ assign the lowercase function to c

c⍳c is the same as ⍳⍨c. See explanation above.

TryAPL online! (casing is not supported on TryAPL)


Title: Bitflip and negate

Body:
Pyke, <s>14</s> 13 bytes

X,"-~"*Q0<>0+

Try it here!


答:
J (48)

```<code>''[1!:2&4('\w(\w+)\w';,1)({~?~@#)rxapply 1!:1[3
</code>```

Explanation:

1!:1[3: read all input from stdin

rxapply: apply the given function to the portions of the input that match the regex

({~?~@#): a verb train that shuffles its input: # counts the length, this gets applied to both sides of ? giving N distinct numbers from 0 to N, { then selects the elements at those indices from the input array.

('\w(\w+)\w';,1): use that regex but only use the value from the first group

[1!:2&4: send unformatted output to stdout

''[: suppress formatted output. This is necessary because otherwise it only outputs that part of the output that fits on a terminal line and then ends with ....

Title: Cambridge Transposition

Body:
I'm sure most, if not all, of you have come across this at some point or another:

Aoccdrnig to a rscheeachr at Cmabrigde Uinervtisy, it deosn't mttaer
in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is
taht the frist and lsat ltteer be at the rghit pclae. The rset can be
a toatl mses and you can sitll raed it wouthit porbelm. Tihs is
bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the
wrod as a wlohe.

Create a program that inputs any amount of text. For testing purposes, use the unscrambled version of the above text, found below.

The program must then randomly transpose the letters of each word with a length of 4 or more letters, except the first and last letter of each word.

All other formatting must remain the same (capitalization and punctuation, etc.).

Testing text:

According to a researcher at Cambridge University, it doesn't matter
in what order the letters in a word are, the only important thing is
that the first and last letter be at the right place. The rest can be
a total mess and you can still read it without problem. This is
because the human mind does not read every letter by itself but the
word as a whole.

As usual, this is a code-golf. Shortest code wins.

Body:
J (48)

''[1!:2&4('\w(\w+)\w';,1)({~?~@#)rxapply 1!:1[3

Explanation:

1!:1[3: read all input from stdin

rxapply: apply the given function to the portions of the input that match the regex

({~?~@#): a verb train that shuffles its input: # counts the length, this gets applied to both sides of ? giving N distinct numbers from 0 to N, { then selects the elements at those indices from the input array.

('\w(\w+)\w';,1): use that regex but only use the value from the first group

[1!:2&4: send unformatted output to stdout

''[: suppress formatted output. This is necessary because otherwise it only outputs that part of the output that fits on a terminal line and then ends with ....


答:
Haskell (lambdabot), 10 bytes

```<code>join.inits
</code>```

Sample:

```<code>(join.inits) "Code"
"CCoCodCode"
</code>```

Title: Stringsplode the String!

Body:
Haskell (lambdabot), 10 bytes

join.inits

Sample:

(join.inits) "Code"
"CCoCodCode"


答:
C, 46 bytes

```<code>m(x){putchar(x?x<0?126:45:48);x&&m(-x-(x<0));}
</code>```

Unlike most (all?) other answers, this one outputs the operators ~ and - one by one.

Title: Bitflip and negate

Body:
C, 46 bytes

m(x){putchar(x?x<0?126:45:48);x&&m(-x-(x<0));}

Unlike most (all?) other answers, this one outputs the operators ~ and - one by one.


答:
Dyalog APL, 18 bytes

'0',⍨0∘>↓'-~'⍴⍨2×|
```

'0',⍨ character zero appended to

0∘> negativeness (i.e. 1 for numbers under 0; 0 for zero and up)

↓ dropped from

'-~'⍴⍨ the string "~-" cyclically reshaped to length

2× two times

| the absolute value

+ plus

0∘< positiveness (i.e 1 for numbers over 0)

TryAPL online!

Title: Bitflip and negate

Body:
Given an integer, make an expression that produces it from 0 using unary negation - and bitwise complement ~ (~n = -n-1), with the operators applied right to left.

```<code>...
-3  = ~-~-~0
-2  = ~-~0
-1  = ~0
 0  = 0
 1  = -~0
 2  = -~-~0
 3  = -~-~-~0
...
</code>```

Your expression must be as short as possible, which means no redundant parts of ~~, --, -0, or 00. Output or print the expression as a string or a sequence of characters.

var QUESTION_ID=92598,OVERRIDE_USER=20260;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/92598/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

 <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

```

Body:
Dyalog APL, 18 bytes

'0',⍨0∘>↓'-~'⍴⍨2×|

'0',⍨ character zero appended to

0∘> negativeness (i.e. 1 for numbers under 0; 0 for zero and up)

↓ dropped from

'-~'⍴⍨ the string "~-" cyclically reshaped to length

2× two times

| the absolute value

+ plus

0∘< positiveness (i.e 1 for numbers over 0)

TryAPL online!


答:
Pyth, 3 bytes

```<code>s._
</code>```

Explanation:

```<code>s   (s)um together
 ._ all prefixes
</code>```

Title: Stringsplode the String!

Body:
Pyth, 3 bytes

s._

Explanation:

s   (s)um together
 ._ all prefixes


问:
Lead Your Turtle by a String
Write a program or function that takes in a nonempty single-line string of printable ascii characters excluding space:

```<code>!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
</code>```

You may assume the input is valid.

Based on the input, draw a new string arranged on a textual grid of spaces and newlines following turtle graphics-esque rules where the turtle always occupies one grid space and can only face the cardinal directions.

Print the first character in the input string to the text grid. The turtle starts here facing right. Iterate over the rest of the characters in the input string (only stopping if the turtle gets stuck), repeating this process:

If the 4 grid spaces directly neighboring the turtle are all filled (i.e. none of them is a space), stop iterating. The turtle is stuck and the grid is as  complete as it can be.

Look at the current character in the input compared to the previous character:

If the current character is lexically before the previous, rotate the turtle a quarter turn left.

If the current character is lexically after the previous, rotate the turtle a quarter turn right.

If the current character equals the previous, don't rotate the turtle.

If the grid space the turtle is now facing is not empty (i.e. not a space), repeatedly rotate the turtle a quarter turn left until she is facing an empty grid space.

Move the turtle one grid step forward in the direction she's facing and print the current character on the grid in the turtle's new location.

Print or return the resulting text grid string with no extraneous rows or columns of whitespace. Lines may have trailing spaces up to the rightmost column with a non-space, but not beyond. A single trailing newline is optionally allowed.

The shortest code in bytes wins.

Example

Here are all the steps of the input spattuuxze. The ^V<> characters show the direction the turtle is facing, they are not part of the input or output.

```<code>s></code>```

```<code>^
p
s</code>```

```<code><ap
  s</code>```

```<code>^
t
ap
 s</code>```

```<code>^
t
t
ap
 s</code>```

```<code>tu>
t
ap
 s</code>```

```<code>tuu>
t
ap
 s</code>```

```<code>tuu
t x
apV
 s</code>```

```<code>tuu
<zx
ap
 s</code>```

At this point the turtle is stuck so the e never gets printed and the final output is:

```<code>s></code>```0

Following is a similar but invalid output since it has an unnecessary leading column of whitespace:

```<code>s></code>```1

Test Cases

```<code>s></code>```2

(Do tell me right away if any of these seem wrong.)

Title: Lead Your Turtle by a String

Body:
Groovy (357 Bytes)

No external turtle libs were used and no turtles were harmed.

R={s->s[0]?[0,-1*s[0]]:[s[1],0]}
L={s->s[0]?[0,s[0]]:[-1*s[1],0]}
def y(s){l=s.length()*2;z(new String[l][l],[l/4,l/4],s,null,[0,1])}
def z(g,l,w,p,h){if(w.length() && !g[(int)(l[0]+h[0])][(int)(l[1]+h[1])]){c=w.getAt(0);w=w.substring(1);if(p && p<c){h=R(h)}else if(p>c){h=L(h)};g[(int)l[0]+h[0]][(int)l[1]+h[1]]=c;z(g,[l[0]+h[0],l[1]+h[1]],w,c,h)}else{g}}

Try it here:
https://groovyconsole.appspot.com/edit/5115774872059904

Previous Attempts

Groovy (397 Bytes)

rotR={s->s[0]!=0?[0,-1*s[0]]:[s[1],0]}
rotL={s->s[0]!=0?[0,s[0]]:[-1*s[1],0]}
def y(s){z(new String[s.length()][s.length()],[s.length()/2,s.length()/2],s,null,[0,1])}
def z(g,l,w,p,h){if(w.length() && !g[(int)(l[0]+h[0])][(int)(l[1]+h[1])]){c=w.getAt(0);w=w.substring(1);if(p && p<c){h=rotR(h)}else if(p > c){h=rotL(h)};g[(int)l[0]+h[0]][(int)l[1]+h[1]]=c;z(g,[l[0]+h[0],l[1]+h[1]],w,c,h)}else{g}}

https://groovyconsole.appspot.com/script/5179465747398656