答:
Python

That's a lot of traversals, let's do all we need to do in one pass for efficiency.

Since y will be [1,2,...,len(x)] we can calculate it's sum and sum of squares using the formulas for triangle and square pyramid numbers respectively.

...and there's really no need for two square roots since the two are multiplied we can just square the product.

```<code>def p(l):
    y = sx = sxy = sx2 = 0
    for c in l:
        y += 1
        x = ord(c) - 96
        sx += x
        sxy += x * y
        sx2 += x * x
    sy = y * (y + 1) / 2
    sy2 = sy * (2 * y + 1) / 3
    return (n * sxy - sx * sy ) / ((n * sx2 - sx * sx) * (n * sy2 - sy * sy)) ** .5
</code>```

Title: Correlation Coefficient of Words

Body:
Python

That's a lot of traversals, let's do all we need to do in one pass for efficiency.

Since y will be [1,2,...,len(x)] we can calculate it's sum and sum of squares using the formulas for triangle and square pyramid numbers respectively.

...and there's really no need for two square roots since the two are multiplied we can just square the product.

def p(l):
    y = sx = sxy = sx2 = 0
    for c in l:
        y += 1
        x = ord(c) - 96
        sx += x
        sxy += x * y
        sx2 += x * x
    sy = y * (y + 1) / 2
    sy2 = sy * (2 * y + 1) / 3
    return (n * sxy - sx * sy ) / ((n * sx2 - sx * sx) * (n * sy2 - sy * sy)) ** .5


问:
Visualize sorting
Say I have a list such as [3, 0, 4, 2, 1], and I use selection sort to sort it, I could visualize it like this:

```<code>3,0,4,2,1
|-|
0,3,4,2,1
  |-----|
0,1,4,2,3
    |-|
0,1,2,4,3
      |-|
0,1,2,3,4
</code>```

This challenge is about visualizing sorting like this.

Input

Your input will be a list of positive integers, in any format you like.

Task

Your submission should sort the input list by only swapping two elements at a time, and at each swap, the submission should display the list, and a character under each of the elements being swapped. If a number that was swapped has more than one digit, the character can be anywhere underneath it. At the end, the submission should display the sorted list.

Other rules

The sorting must use fewer swaps than n4, where n is the length of the list.

The sorting doesn't have to be deterministic.

The characters under the swapped can be any char except space.

答:
Java 7, 256 241 282 Bytes

Thanks to @Geobits and @Axelh for saving 15 bytes

```<code> void f(int[]a){int m,i,j,l=a.length;for(i=0;i<l;j=a[i],a[i]=a[m],a[m]=j,i++){for(int k:a)System.out.print(k+" ");System.out.println();for(j=i+1,m=i;j<l;m=a[j]<a[m]?j:m,j++);for(j=0;j<=m&i!=l-1;j++)System.out.print(j==i|j==m?a[j]+" ":"  ");System.out.println();}}
</code>```

Ungolfed

```<code> void f(int[]a){
    int m,i,j,l=a.length;
for(i=0;i<l;j=a[i],a[i]=a[m],a[m]=j,i++){
    for(int k:a)
        System.out.print(k+" ");
    System.out.println();
     for(j=i+1,m=i;j<l;m=a[j]<a[m]?j:m,j++);
      for(j=0;j<=m&i!=l-1;j++)
      System.out.print(j==i|j==m?a[j]+" ":"  ");
      System.out.println();

}
}
</code>```

output

```<code>3 0 1 4 2
3 0
0 3 1 4 2
  3 1
0 1 3 4 2
    3   2
0 1 2 4 3
      4 3
0 1 2 3 4
</code>```

ContentLicense: CC BY-SA 3.0

Title: Visualize sorting

Body:
Java 7, 256 241 282 Bytes

Thanks to @Geobits and @Axelh for saving 15 bytes

 void f(int[]a){int m,i,j,l=a.length;for(i=0;i<l;j=a[i],a[i]=a[m],a[m]=j,i++){for(int k:a)System.out.print(k+" ");System.out.println();for(j=i+1,m=i;j<l;m=a[j]<a[m]?j:m,j++);for(j=0;j<=m&i!=l-1;j++)System.out.print(j==i|j==m?a[j]+" ":"  ");System.out.println();}}

Ungolfed

 void f(int[]a){
    int m,i,j,l=a.length;
for(i=0;i<l;j=a[i],a[i]=a[m],a[m]=j,i++){
    for(int k:a)
        System.out.print(k+" ");
    System.out.println();
     for(j=i+1,m=i;j<l;m=a[j]<a[m]?j:m,j++);
      for(j=0;j<=m&i!=l-1;j++)
      System.out.print(j==i|j==m?a[j]+" ":"  ");
      System.out.println();

}
}

output

3 0 1 4 2
3 0
0 3 1 4 2
  3 1
0 1 3 4 2
    3   2
0 1 2 4 3
      4 3
0 1 2 3 4


问:
Let's do the Wave!
Input:

A string (the wave-snippet) with a length >= 2.

A positive integer n >= 1.

Output:

We output a single-line wave. We do this by repeating the input string n times.

Challenge rules:

If the first and last character of the input string matches, we only output it once in the total output (i.e. ^_^ of length 2 becomes ^_^_^ and not ^_^^_^).

The input string won't contain any whitespaces/tabs/new-lines/etc.

If your language doesn't support non-ASCII characters, then that's fine. As long as it still complies to the challenge with ASCII-only wave-input.

General rules:

This is code-golf, so shortest answer in bytes wins.

Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.

Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.

Default Loopholes are forbidden.

If possible, please add a link with a test for your code.

Also, please add an explanation if necessary.

Test cases:

```<code>_.~"(              length 12
_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(

'°º¤o,¸¸,o¤º°'     length 3
'°º¤o,¸¸,o¤º°'°º¤o,¸¸,o¤º°'°º¤o,¸¸,o¤º°'

-__                length 1
-__

-__                length 8
-__-__-__-__-__-__-__-__

-__-               length 8
-__-__-__-__-__-__-__-__-

¯`·.¸¸.·´¯         length 24
¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯

**                 length 6
*******

String & length of your own choice (be creative!)
</code>```

答:
Postscript, 98 bytes

```<code>exch/s exch def/l s length 1 sub def s 0 get s l get eq{/s s 0 l getinterval def}if{s print}repeat
</code>```

...but you might need a ' flush' tacked onto that to get your PS interpreter to flush the comm buffer, another six bytes :(

Title: Let's do the Wave!

Body:
Postscript, 98 bytes

exch/s exch def/l s length 1 sub def s 0 get s l get eq{/s s 0 l getinterval def}if{s print}repeat

...but you might need a ' flush' tacked onto that to get your PS interpreter to flush the comm buffer, another six bytes :(


问:
ASCII PPCG Beta Logo Golf
We shall soon have a new logo & site design, let us use this last breath of the simple times and golf this ASCII version of the speech bubble beta logo:

```<code>+-------------------------------------------+
|    .---------------------------------.    |
|   .EPEpEpBPEpEGCXCgCgCGJgCgP&PWP&P&P&Y`   |
|  .RSRsRWRSRsRsHoNoNONxNONONuJuSUSUSVSUS`  |
|  :o@OTO@O@O@W@IDiDIWiDIDIDWZEZeZEWEZeZE-  |
|  :GWGFGfGFKFGFMEMwMEMEMeXEMZLZLWLZLzLZH-  |
|  :rLRLRLXLRLrLMBMGMGmGXGMGMLzTZLZLZLYLZ-  |
|  :AOAoBOAOAOAYAOAoAoBOAOAoAWZEZEZEVEZEZ-  |
|  :MGVGm!'""'!GRLr!'""'!LRKRS!'""'!uSuSU-  |
|  :XEME' .''% !Gf' .;G% 'GFG' .;P% '&PVP-  |
|  :IDID  !DI! !V! .OPoYOPOP!  -gCGCGHGCG-  |
|  :NONw  ``` .OR! .RWRRRRRR! !ONo* 'ONON-  |
|  :GBGC  !CXCGCP! !POP; !xOP  `IJ; `!IDW-  |
|  :P&P&._!&P&P&F~.____.;GFGF~.____.;eJEM-  |
|  :USUSVSUSuSuTLRlRLRWRLRlRLWMGMGmGwGmGM-  |
|  :ZeWEZEZeZWZeOAOaKAOAOaOwOOAoAOXoAoAOA-  |
|  :wLZLZLzHZLZLGMxMgMGMgBGMGLRLXLRLrLRTr-  |
|  :LZLZLYLZLZLzBMEMEMEyEmEMEfBFGFGfGWGFG-  |
|  :EZEVEZEZeZVZDIdIDYdIdIDIx@O@o@oKO@O@o-  |
|  `SkSuSuSUXUSuONOVONOnONWNOSRSRWRSRSRS-   |
|   `.&P&PVP&P&PCXcGCGCGVGcGCEPYPEpEPE?.-   |
|      ```````````````````:STACKE-`````     |
|                         :XCHA-`           |
|                         :NG-`             |
|           ?=W...HWYWVWB :E`               |
+-------------------------------------------+
</code>```

This is kolmogorov-complexity code-golf, so it's straight forward, output all the text that appears in the above code-block in as few bytes of code as possible, without any funny-business.

input

None

Output

The ASCII content of the code-block above as a return value or printed to STDOUT or equivalent;

carriage returns (13) and/or new lines (10) are acceptable;

a trailing empty line is also allowed.

Update

The original aim of this challenge was to have a puzzle aspect. It seems this has not been noticed, so I have decided to make the puzzle portion significantly easier, but still present, by performing a couple of steps to get you going:

There is a use of the string "STACKEXCHANGE" in the very bottom portion of the speech-bubble.

If one reads the rows of text in the main-portion of the speech-bubble, one might notice an almost repetitive nature of pairs of letters, for example the fourth row reads "GWGFGfGFKFGFMEMwMEMEMeXEMZLZLWLZLzLZH" which is almost "GFGFGFGFGFGFMEMEMEMEMEMEMZLZLZLZLZLZH", except some letters have been changed either to another letter (e.g. the second letter from F to W), to lower-case (e.g. the sixth letter from F to f), or both (e.g. the sixteenth letter from E to w). The rows seem to all conform to such a pattern with a 12-13-12 character split (ignoring the mess of the PPG logo's white space and border).

The process described in (2), once noticed, should be quite easy to undo for the unmasked rows of the speech-bubble (the top six and bottom seven), by first converting the whole text to upper-case and then replacing the odd-ones-out and results in:

```<code>+-------------------------------------------+
|    .---------------------------------.    |
|   .EPEPEPEPEPEGCGCGCGCGCGCGP&P&P&P&P&P`   |
|  .RSRSRSRSRSRSNONONONONONONUSUSUSUSUSUS`  |
|  :O@OTO@O@O@O@IDIDIWIDIDIDIZEZEZEZEZEZE-  |
|  :GFGFGFGFGFGFMEMEMEMEMEMEMZLZLZLZLZLZL-  |
|  :RLRLRLRLRLRLMGMGMGMGMGMGMLZLZLZLZLZLZ-  |
|  :AOAOAOAOAOAOAOAOAOBOAOAOAEZEZEZEZEZEZ-  |
|  :MGVGm!'""'!GRLr!'""'!LRKRS!'""'!uSuSU-  |
|  :XEME' .''% !Gf' .;G% 'GFG' .;P% '&PVP-  |
|  :IDID  !DI! !V! .OPoYOPOP!  -gCGCGHGCG-  |
|  :NONw  ``` .OR! .RWRRRRRR! !ONo* 'ONON-  |
|  :GBGC  !CXCGCP! !POP; !xOP  `IJ; `!IDW-  |
|  :P&P&._!&P&P&F~.____.;GFGF~.____.;eJEM-  |
|  :USUSUSUSUSURLRLRLRLRLRLRLGMGMGMGMGMGM-  |
|  :ZEZEZEZEZEZEOAOAOAOAOAOAOOAOAOAOAOAOA-  |
|  :ZLZLZLZLZLZLGMGMGMGMGMGMGLRLRLRLRLRLR-  |
|  :LZLZLZLZLZLZEMEMEMEMEMEMEFGFGFGFGFGFG-  |
|  :EZEZEZEZEZEZDIDIDIDIDIDID@O@O@O@O@O@O-  |
|  `SUSUSUSUSUSUONONONONONONOSRSRSRSRSRS-   |
|   `.&P&P&P&P&PCGCGCGCGCGCGCEPEPEPEPEP.-   |
|      ```````````````````:STACKE-`````     |
|                         :XCHA-`           |
|                         :NG-`             |
|           ?=W...HWYWVWB :E`               |
+-------------------------------------------+
</code>```

While carrying out (3) one may notice a couple of things. First the least obvious: that the only ?, in the very bottom-right became a P, whereas the extra text at the bottom says ?=W..., and that a large proportion of replaced characters were also W. Second that the odd-ones out in upper-case were B,H,J,K,T,V,W,X,Y. Third that the odd-ones out occurred every seven letters. The second and third observation helps to fill in the middle rows - which, if we remove the PCG mask of spaces and non-letters, non & (used in the top and bottom row) and replace it with the letters yields:

```<code>+-------------------------------------------+
|    .---------------------------------.    |
|   .EPEPEPEPEPEGCGCGCGCGCGCGP&P&P&P&P&P`   |
|  .RSRSRSRSRSRSNONONONONONONUSUSUSUSUSUS`  |
|  :O@O@O@O@O@O@IDIDIWIDIDIDIZEZEZEZEZEZE-  |
|  :GFGFGFGFGFGFMEMEMEMEMEMEMZLZLZLZLZLZL-  |
|  :RLRLRLRLRLRLMGMGMGMGMGMGMLZLZLZLZLZLZ-  |
|  :AOAOAOAOAOAOAOAOAOBOAOAOAEZEZEZEZEZEZ-  |
|  :MGMGMGMGMGMGRLRLRLRLRLRLRSUSUSUSUSUSU-  |
|  :MEMEMEMEMEMEGFGFGFGFGFGFG&P&P&P&P&P&P-  |
|  :IDIDIDIDIDIDOPOPOPOPOPOPOCGCGCGCGCGCG-  |
|  :NONONONONONORRRRRRRRRRRRRONONONONONON-  |
|  :GCGCGCGCGCGCPOPOPOPOPOPOPDIDIDIDIDIDI-  |
|  :P&P&P&P&P&P&FGFGFGFGFGFGFEMEMEMEMEMEM-  |
|  :USUSUSUSUSURLRLRLRLRLRLRLGMGMGMGMGMGM-  |
|  :ZEZEZEZEZEZEOAOAOAOAOAOAOOAOAOAOAOAOA-  |
|  :ZLZLZLZLZLZLGMGMGMGMGMGMGLRLRLRLRLRLR-  |
|  :LZLZLZLZLZLZEMEMEMEMEMEMEFGFGFGFGFGFG-  |
|  :EZEZEZEZEZEZDIDIDIDIDIDID@O@O@O@O@O@O-  |
|  `SUSUSUSUSUSUONONONONONONOSRSRSRSRSRS-   |
|   `.&P&P&P&P&PCGCGCGCGCGCGCEPEPEPEPEP.-   |
|      ```````````````````:STACKE-`````     |
|                         :XCHA-`           |
|                         :NG-`             |
|           ?=W...HWYWVWB :E`               |
+-------------------------------------------+
```

Now reading the columns one can see that the "input" text to make this base grid was PROGRAMMINGPUZZLES&CODEGOLFPROGRAMMINGPUZZLES&CODEGOLF@SE.

The lower-casing and replacement characters are to be determined by you, but also note that the ten remaining letters in the alphabet after removing those present in that string are B,H,J,K,Q,T,V,W,X,Y - the replacements plus Q.

Title: ASCII PPCG Beta Logo Golf

Body:
Bubblegum, <s>542</s> 541 bytes

Reversible hexdump:

00000000: d2d6 251e 68f3 72d5 002a 2903 1637 6138  ..%.h.r..*)..7a8
00000010: 8a7f 9578 7027 0c9a 0fd0 32ae 6a63 b435  ...xp'....2.jc.5
00000020: 2668 6734 00e7 d8d9 32b6 cea3 4769 57c6  &hg4....2...GiW.
00000030: 3efb 5e94 1a60 07c7 e5f1 7f89 f033 35ff  >.^..`.......35.
00000040: a725 18f4 5d92 5aec cf88 53a6 d80b 7b09  .%..].Z...S...{.
00000050: adf3 a88e f610 5fc3 d583 d228 a869 279c  ......_....(.i'.
00000060: 1665 f15a e8c1 5f93 3eef 7399 5f72 099d  .e.Z.._.>.s._r..
00000070: d6a7 f20b 54a1 da1b 3eef 9772 2b97 567a  ....T...>..r+.Vz
00000080: 99ae beaf 528d 82b4 61a6 334c 0f3e 9b70  ....R...a.3L.>.p
00000090: ae79 cc77 3cde c43c 164c 9c05 83ba 9a09  .y.w<..<.L......
000000a0: 9399 4ca3 ae99 491c 7ecc 0aa8 461d 3311  ..L...I.~...F.3.
000000b0: 0a2e f881 d770 915d b7b8 036a 32e3 f040  .....p.]...j2..@
000000c0: 067d 2803 ab06 d58f 5798 b561 5695 7587  .}(.....W..aV.u.
000000d0: 0b5e f183 e7df ddf9 1ec7 2f8c abac d814  .^......../.....
000000e0: e5b8 3c95 38b1 c3f1 94cc 27d4 f7ef 89c7  ..<.8.....'.....
000000f0: 7758 2df8 3df1 711e bb54 583e a84a 39dc  wX-.=.q..TX>.J9.
00000100: 7681 106f 957a c4ab 3c42 a5ea 1ba9 a4f2  v..o.z..<B......
00000110: 0899 2181 8827 2887 a3c3 6742 dab6 0559  ..!..'(...gB...Y
00000120: 0047 06c3 c0dd 32ef 3f11 5f82 7038 0f79  .G....2.?._.p8.y
00000130: 84dd a31a 3b29 30d8 7841 bc8b 54d8 235d  ....;)0.xA..T.#]
00000140: 2f48 eb21 0387 db94 e993 37a4 1dff a54f  /H.!......7....O
00000150: 1878 fc98 4feb 6ecd 84c3 6f39 a303 dbac  .x..O.n...o9....
00000160: f889 1034 0ab3 1e33 38a3 84c3 4da7 d990  ...4...38...M...
00000170: b736 1d1a fe75 1358 9767 697b 2feb de7a  .6...u.X.gi{/..z
00000180: e0f0 f390 dc35 b1ce c545 ecb1 e93e c4c6  .....5...E...>..
00000190: 53d6 c5f6 e8f0 5bce d035 14cc ea37 3bc0  S.....[..5...7;.
000001a0: 7761 3cbc 4d1a eef0 5bce 9da9 cc2a 7d4e  wa<.M...[....*}N
000001b0: 57cd b3f5 f482 77b4 5ff6 1b69 e709 6fcb  W.....w._..i..o.
000001c0: 1fe5 9073 8dd3 a2c5 15ea 97cc 752e 4b7c  ...s........u.K|
000001d0: 031a 0581 1e71 f014 1d44 ced6 a3fa 1b8f  .....q...D......
000001e0: a08a 6366 aab1 5f98 628f d4e1 76b4 ff8f  ..cf.._.b...v...
000001f0: 79b9 0da2 0d9b 0d17 401c fee6 98d7 5112  y.......@.....Q.
00000200: ccda e9fa 3d3c e70e 7e0b 7ffc ac29 a589  ....=<..~....)..
00000210: 6e74 a543 34cc c113 fea1 bfa5 7f         nt.C4........

<a href="http://bubblegum.tryitonline.net#code=MDAwMDAwMDA6IGQyZDYgMjUxZSA2OGYzIDcyZDUgMDAyYSAyOTAzIDE2MzcgNjEzOCAgLi4lLmguci4uKikuLjdhOAowMDAwMDAxMDogOGE3ZiA5NTc4IDcwMjcgMGM5YSAwZmQwIDMyYWUgNmE2MyBiNDM1ICAuLi54cCcuLi4uMi5qYy41CjAwMDAwMDIwOiAyNjY4IDY3MzQgMDBlNyBkOGQ5IDMyYjYgY2VhMyA0NzY5IDU3YzYgICZoZzQuLi4uMi4uLkdpVy4KMDAwMDAwMzA6IDNlZmIgNWU5NCAxYTYwIDA3YzcgZTVmMSA3Zjg5IGYwMzMgMzVmZiAgPi5eLi5gLi4uLi4uLjM1LgowMDAwMDA0MDogYTcyNSAxOGY0IDVkOTIgNWFlYyBjZjg4IDUzYTYgZDgwYiA3YjA5ICAuJS4uXS5aLi4uUy4uLnsuCjAwMDAwMDUwOiBhZGYzIGE4OGUgZjYxMCA1ZmMzIGQ1ODMgZDIyOCBhODY5IDI3OWMgIC4uLi4uLl8uLi4uKC5pJy4KMDAwMDAwNjA6IDE2NjUgZjE1YSBlOGMxIDVmOTMgM2VlZiA3Mzk5IDVmNzIgMDk5ZCAgLmUuWi4uXy4-LnMuX3IuLgowMDAwMDA3MDogZDZhNyBmMjBiIDU0YTEgZGExYiAzZWVmIDk3NzIgMmI5NyA1NjdhICAuLi4uVC4uLj4uLnIrLlZ6CjAwMDAwMDgwOiA5OWFlIGJlYWYgNTI4ZCA4MmI0IDYxYTYgMzM0YyAwZjNlIDliNzAgIC4uLi5SLi4uYS4zTC4-LnAKMDAwMDAwOTA6IGFlNzkgY2M3NyAzY2RlIGM0M2MgMTY0YyA5YzA1IDgzYmEgOWEwOSAgLnkudzwuLjwuTC4uLi4uLgowMDAwMDBhMDogOTM5OSA0Y2EzIGFlOTkgNDkxYyA3ZWNjIDBhYTggNDYxZCAzMzExICAuLkwuLi5JLn4uLi5GLjMuCjAwMDAwMGIwOiAwYTJlIGY4ODEgZDc3MCA5MTVkIGI3YjggMDM2YSAzMmUzIGYwNDAgIC4uLi4ucC5dLi4uajIuLkAKMDAwMDAwYzA6IDA2N2QgMjgwMyBhYjA2IGQ1OGYgNTc5OCBiNTYxIDU2OTUgNzU4NyAgLn0oLi4uLi5XLi5hVi51LgowMDAwMDBkMDogMGI1ZSBmMTgzIGU3ZGYgZGRmOSAxZWM3IDJmOGMgYWJhYyBkODE0ICAuXi4uLi4uLi4uLy4uLi4uCjAwMDAwMGUwOiBlNWI4IDNjOTUgMzhiMSBjM2YxIDk0Y2MgMjdkNCBmN2VmIDg5YzcgIC4uPC44Li4uLi4nLi4uLi4KMDAwMDAwZjA6IDc3NTggMmRmOCAzZGYxIDcxMWUgYmI1NCA1ODNlIGE4NGEgMzlkYyAgd1gtLj0ucS4uVFg-Lko5LgowMDAwMDEwMDogNzY4MSAxMDZmIDk1N2EgYzRhYiAzYzQyIGE1ZWEgMWJhOSBhNGYyICB2Li5vLnouLjxCLi4uLi4uCjAwMDAwMTEwOiAwODk5IDIxODEgODgyNyAyODg3IGEzYzMgNjc0MiBkYWI2IDA1NTkgIC4uIS4uJyguLi5nQi4uLlkKMDAwMDAxMjA6IDAwNDcgMDZjMyBjMGRkIDMyZWYgM2YxMSA1ZjgyIDcwMzggMGY3OSAgLkcuLi4uMi4_Ll8ucDgueQowMDAwMDEzMDogODRkZCBhMzFhIDNiMjkgMzBkOCA3ODQxIGJjOGIgNTRkOCAyMzVkICAuLi4uOykwLnhBLi5ULiNdCjAwMDAwMTQwOiAyZjQ4IGViMjEgMDM4NyBkYjk0IGU5OTMgMzdhNCAxZGZmIGE1NGYgIC9ILiEuLi4uLi43Li4uLk8KMDAwMDAxNTA6IDE4NzggZmM5OCA0ZmViIDZlY2QgODRjMyA2ZjM5IGEzMDMgZGJhYyAgLnguLk8ubi4uLm85Li4uLgowMDAwMDE2MDogZjg4OSAxMDM0IDBhYjMgMWUzMyAzOGEzIDg0YzMgNGRhNyBkOTkwICAuLi40Li4uMzguLi5NLi4uCjAwMDAwMTcwOiBiNzM2IDFkMWEgZmU3NSAxMzU4IDk3NjcgNjk3YiAyZmViIGRlN2EgIC42Li4udS5YLmdpey8uLnoKMDAwMDAxODA6IGUwZjAgZjM5MCBkYzM1IGIxY2UgYzU0NSBlY2IxIGU5M2UgYzRjNiAgLi4uLi41Li4uRS4uLj4uLgowMDAwMDE5MDogNTNkNiBjNWY2IGU4ZjAgNWJjZSBkMDM1IDE0Y2MgZWEzNyAzYmMwICBTLi4uLi5bLi41Li4uNzsuCjAwMDAwMWEwOiA3NzYxIDNjYmMgNGQxYSBlZWYwIDViY2UgOWRhOSBjYzJhIDdkNGUgIHdhPC5NLi4uWy4uLi4qfU4KMDAwMDAxYjA6IDU3Y2QgYjNmNSBmNDgyIDc3YjQgNWZmNiAxYjY5IGU3MDkgNmZjYiAgVy4uLi4udy5fLi5pLi5vLgowMDAwMDFjMDogMWZlNSA5MDczIDhkZDMgYTJjNSAxNWVhIDk3Y2MgNzUyZSA0YjdjICAuLi5zLi4uLi4uLi51Lkt8CjAwMDAwMWQwOiAwMzFhIDA1ODEgMWU3MSBmMDE0IDFkNDQgY2VkNiBhM2ZhIDFiOGYgIC4uLi4ucS4uLkQuLi4uLi4KMDAwMDAxZTA6IGEwOGEgNjM2NiBhYWIxIDVmOTggNjI4ZiBkNGUxIDc2YjQgZmY4ZiAgLi5jZi4uXy5iLi4udi4uLgowMDAwMDFmMDogNzliOSAwZGEyIDBkOWIgMGQxNyA0MDFjIGZlZTYgOThkNyA1MTEyICB5Li4uLi4uLkAuLi4uLlEuCjAwMDAwMjAwOiBjY2RhIGU5ZmEgM2QzYyBlNzBlIDdlMGIgN2ZmYyBhYzI5IGE1ODkgIC4uLi49PC4ufi4uLi4pLi4KMDAwMDAyMTA6IDZlNzQgYTU0MyAzNGNjIGMxMTMgZmVhMSBiZmE1IDdmICAgICAgICAgbnQuQzQuLi4uLi4uLg" rel="nofollow">Try it online!

Just Zopfli'd the string for 1 million iterations. Running for 100 million iterations does not yield a shorter solution.


Title: Visualize sorting

Body:
Say I have a list such as [3, 0, 4, 2, 1], and I use selection sort to sort it, I could visualize it like this:

```<code>3,0,4,2,1
|-|
0,3,4,2,1
  |-----|
0,1,4,2,3
    |-|
0,1,2,4,3
      |-|
0,1,2,3,4
</code>```

This challenge is about visualizing sorting like this.

Input

Your input will be a list of positive integers, in any format you like.

Task

Your submission should sort the input list by only swapping two elements at a time, and at each swap, the submission should display the list, and a character under each of the elements being swapped. If a number that was swapped has more than one digit, the character can be anywhere underneath it. At the end, the submission should display the sorted list.

Other rules

The sorting must use fewer swaps than n4, where n is the length of the list.

The sorting doesn't have to be deterministic.

The characters under the swapped can be any char except space.

Body:
PHP, 248 Bytes

Bubblesort boring wins

<?for($c=count($a=$_GET[a]);$c--;){for($s=$i=0;$i<$c;){$l=strlen($j=join(",",$a));if($a[$i]>$a[$i+1]){$t=$a[$i];$a[$i]=$a[$i+1];$a[$i+1]=$t;$m=" ";$m[$s]=I;$m[$s+strlen($a[$i].$a[$i+1])]=X;echo"$j\n$m\n";}$s+=strlen($a[$i++])+1;}}echo join(",",$a);

PHP, 266 Bytes a way with array_slice and min

modified output I  X instead of *~~*

<?for($c=count($a=$_GET[a]);$i<$c;){$j=join(",",$s=($d=array_slice)($a,$i));$x=array_search($m=min($s),$s);echo($o=join(",",$a));$a[$x+$i]=$a[$i];$a[$i]=$m;if($i++!=$c-1){$t=" ";$t[$z=($f=strlen)($o)-($l=$f($j))]=I;$t[$l+$z-$f(join(",",$d($s,$x)))]=X;echo"\n$t\n";}}

282 Bytes

<?for($c=count($a=$_GET[a]);$i<$c;){$j=join(",",$s=($d=array_slice)($a,$i));$x=array_search($m=min($s),$s);echo($o=join(",",$a));$a[$x+$i]=$a[$i];$a[$i]=$m;if($i++!=$c-1)echo"\n".str_repeat(" ",($f=strlen)($o)-($l=$f($j))).($x?str_pad("*",$l-$f(join(",",$d($s,$x))),"~"):"")."*\n";}

How it works

Looks for the minimum in an array and take this on first position
Look for the minimum without first position .... and so on
If a value is double the first value will be swap

Output Example

31,7,0,5,5,5,753,5,99,4,333,5,2,1001,35,1,67
*~~~~*
0,7,31,5,5,5,753,5,99,4,333,5,2,1001,35,1,67
  *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
0,1,31,5,5,5,753,5,99,4,333,5,2,1001,35,7,67
    *~~~~~~~~~~~~~~~~~~~~~~~~~*
0,1,2,5,5,5,753,5,99,4,333,5,31,1001,35,7,67
      *~~~~~~~~~~~~~~*
0,1,2,4,5,5,753,5,99,5,333,5,31,1001,35,7,67
        *
0,1,2,4,5,5,753,5,99,5,333,5,31,1001,35,7,67
          *
0,1,2,4,5,5,753,5,99,5,333,5,31,1001,35,7,67
            *~~~*
0,1,2,4,5,5,5,753,99,5,333,5,31,1001,35,7,67
              *~~~~~~*
0,1,2,4,5,5,5,5,99,753,333,5,31,1001,35,7,67
                *~~~~~~~~~~*
0,1,2,4,5,5,5,5,5,753,333,99,31,1001,35,7,67
                  *~~~~~~~~~~~~~~~~~~~~~*
0,1,2,4,5,5,5,5,5,7,333,99,31,1001,35,753,67
                    *~~~~~~*
0,1,2,4,5,5,5,5,5,7,31,99,333,1001,35,753,67
                       *~~~~~~~~~~~*
0,1,2,4,5,5,5,5,5,7,31,35,333,1001,99,753,67
                          *~~~~~~~~~~~~~~~*
0,1,2,4,5,5,5,5,5,7,31,35,67,1001,99,753,333
                             *~~~~*
0,1,2,4,5,5,5,5,5,7,31,35,67,99,1001,753,333
                                *~~~~~~~~*
0,1,2,4,5,5,5,5,5,7,31,35,67,99,333,753,1001
                                    *
0,1,2,4,5,5,5,5,5,7,31,35,67,99,333,753,1001


Title: Visualize sorting

Body:
JavaScript (ES6), 158 bytes

a=>{for(;;){console.log(``+a);i=a.findIndex((e,i)=>e<a[i-1]);if(i<0)break;console.log(` `.repeat(`${a.slice(0,i)}`.length-1)+`|-|`);t=a[i];a[i]=a[--i];a[i]=t}}

Bubble sort. Sample output:

3,0,4,2,1
|-|
0,3,4,2,1
    |-|
0,3,2,4,1
  |-|
0,2,3,4,1
      |-|
0,2,3,1,4
    |-|
0,2,1,3,4
  |-|
0,1,2,3,4


答:
Perl, 62 bytes

Includes +3 for -p

Give input as a single line of numbers on STDIN:

```<code>perl -M5.010 visisort.pl <<< "3 0 4 2 1"
</code>```

Repeatedly swaps the first inversion. Swap complexity is O(n^2), time complexity is O(n^3). Uses the numbers being swapped as mark:

```<code>3 0 4 2 1
3 0
0 3 4 2 1
    4 2
0 3 2 4 1
  3 2
0 2 3 4 1
      4 1
0 2 3 1 4
    3 1
0 2 1 3 4
  2 1
0 1 2 3 4
</code>```

visisort.pl:

```<code>#!/usr/bin/perl -p
$&>$'&&say$_.$"x"@-".!s/(\S+) \G(\S+)/$2 $1/.$&while/\S+ /g
</code>```

The program also supports negative values and floating point numbers

If you insist on a connecting character the code becomes 66 bytes:

```<code>#!/usr/bin/perl -p
$&>$'&&say$_.$"x"@-".!s/(\S+) \G(\S+)/$2 $1/.$1.-$2while/\S+ /g
</code>```

But now it doesn't support negative numbers and 0 anymore (but the program only has to support positive integers anyways. The 0 in the example is a mistake)

Title: Visualize sorting

Body:
Perl, 62 bytes

Includes +3 for -p

Give input as a single line of numbers on STDIN:

perl -M5.010 visisort.pl <<< "3 0 4 2 1"

Repeatedly swaps the first inversion. Swap complexity is O(n^2), time complexity is O(n^3). Uses the numbers being swapped as mark:

3 0 4 2 1
3 0
0 3 4 2 1
    4 2
0 3 2 4 1
  3 2
0 2 3 4 1
      4 1
0 2 3 1 4
    3 1
0 2 1 3 4
  2 1
0 1 2 3 4

visisort.pl:

#!/usr/bin/perl -p
$&>$'&&say$_.$"x"@-".!s/(\S+) \G(\S+)/$2 $1/.$&while/\S+ /g

The program also supports negative values and floating point numbers

If you insist on a connecting character the code becomes 66 bytes:

#!/usr/bin/perl -p
$&>$'&&say$_.$"x"@-".!s/(\S+) \G(\S+)/$2 $1/.$1.-$2while/\S+ /g

But now it doesn't support negative numbers and 0 anymore (but the program only has to support positive integers anyways. The 0 in the example is a mistake)


问:
Count the number of ones in an unsigned 16-bit integer
Write some statement(s) which will count the number of ones in an unsigned sixteen-bit integer.

For example, if the input is 1337, then the result is 6 because 1337 as a sixteen bit binary number is 0000010100111001, which contains six ones.

答:
05AB1E, 3 bytes

```<code>bSO
</code>```

Try it online!

Body:
05AB1E, 3 bytes

bSO

Try it online!

ContentLicense: CC BY-SA 4.0


答:
K, 12 Bytes

```<code>{,/[y#(,)x]}

/in action
{,/[y#(,)x]}["lollol";4]
"lollollollollollollollol"
{,/[y#(,)x]}["-_";10]
"-_-_-_-_-_-_-_-_-_-_"

/explanation (read function from right to left)
x is the string and y is the number of repetitions
(,)y    --enlist x so it becomes 1 value (rather than a list)
y#x     --take y many items of x
,/      --coalesce the list ,/[("-_";"-_")] --> "-_-_"
</code>```

Thanks

Title: Let's do the Wave!

Body:
Input:

A string (the wave-snippet) with a length >= 2.

A positive integer n >= 1.

Output:

We output a single-line wave. We do this by repeating the input string n times.

Challenge rules:

If the first and last character of the input string matches, we only output it once in the total output (i.e. ^_^ of length 2 becomes ^_^_^ and not ^_^^_^).

The input string won't contain any whitespaces/tabs/new-lines/etc.

If your language doesn't support non-ASCII characters, then that's fine. As long as it still complies to the challenge with ASCII-only wave-input.

General rules:

This is code-golf, so shortest answer in bytes wins.

Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.

Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.

Default Loopholes are forbidden.

If possible, please add a link with a test for your code.

Also, please add an explanation if necessary.

Test cases:

```<code>_.~"(              length 12
_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(

'°º¤o,¸¸,o¤º°'     length 3
'°º¤o,¸¸,o¤º°'°º¤o,¸¸,o¤º°'°º¤o,¸¸,o¤º°'

-__                length 1
-__

-__                length 8
-__-__-__-__-__-__-__-__

-__-               length 8
-__-__-__-__-__-__-__-__-

¯`·.¸¸.·´¯         length 24
¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯

**                 length 6
*******

String & length of your own choice (be creative!)
</code>```

Body:
K, 12 Bytes

{,/[y#(,)x]}

/in action
{,/[y#(,)x]}["lollol";4]
"lollollollollollollollol"
{,/[y#(,)x]}["-_";10]
"-_-_-_-_-_-_-_-_-_-_"

/explanation (read function from right to left)
x is the string and y is the number of repetitions
(,)y    --enlist x so it becomes 1 value (rather than a list)
y#x     --take y many items of x
,/      --coalesce the list ,/[("-_";"-_")] --> "-_-_"

Thanks


答:
CJam (accuracy 50016828/100000000, 6 bytes)

```<code>{+1&!}
</code>```

(In ALGOL-style pseudocode for non-CJammers: return ((x + y) & 1) == 0).

This performs better than any of the other two dozen simple heuristics I've tried. It's even better than any combination with the next two best ones.

The score assumes that my calculated section of the matrix is correct. Independent verification welcomed. I'm hosting the calculated parity bits at http://cheddarmonk.org/codegolf/PPCG95604-parity.bz2 (8MB download, extracts to 50MB text file: since the matrix is symmetric about the main diagonal, I've only included each line starting from the main diagonal, so you have to offset, transpose, and bitwise OR to get the full square).

The code which I used to calculate it is Java. It uses the definition fairly straightforwardly, but with a set data structure which run-length encodes the ranges so that it's quick to skip to the next permitted value. Further optimisation would be possible, but it runs on my moderately old desktop in about two hours and 1.5GB of heap space.

import java.util.*;

public class PPCG95604Analysis
{
    static final int N = 30000;

    public static void main(String[] args) {
        Indicator[] cols = new Indicator[N];
        Indicator[] diag = new Indicator[N];
        for (int i = 0; i < N; i++) {
            cols[i] = new Indicator();
            diag[i] = new Indicator();
        }

        int maxVal = 0;

        for (int y = 0; y < N; y++) {
            Indicator row = new Indicator(cols[y]);

            for (int x = y; x < N; x++) {
                Indicator col = cols[x];
                Indicator dia = diag[x - y];

                Indicator.Result rr = row.firstCandidate();
                Indicator.Result rc = col.firstCandidate();
                Indicator.Result rd = dia.firstCandidate();

                while (true) {
                    int max = Math.max(Math.max(rr.candidateValue(), rc.candidateValue()), rd.candidateValue());
                    if (rr.candidateValue() == max && rc.candidateValue() == max && rd.candidateValue() == max) break;

                    if (rr.candidateValue() != max) rr = rr.firstCandidateGreaterThan(max - 1);
                    if (rc.candidateValue() != max) rc = rc.firstCandidateGreaterThan(max - 1);
                    if (rd.candidateValue() != max) rd = rd.firstCandidateGreaterThan(max - 1);
                }

                if (y >= 20000 && x >= 20000) System.out.format("%d", rr.candidateValue() & 1);
                maxVal = Math.max(maxVal, rr.candidateValue());
                rr.markUsed();
                rc.markUsed();
                rd.markUsed();
            }
            if (y >= 20000) System.out.println();
        }
    }

    static class Indicator
    {
        private final int INFINITY = (short)0xffff;
        private final int MEMBOUND = 10000;

        private short[] runLengths = new short[MEMBOUND];

        public Indicator() { runLengths[1] = INFINITY; }

        public Indicator(Indicator clone) { System.arraycopy(clone.runLengths, 0, runLengths, 0, MEMBOUND); }

        public Result firstCandidate() {
            // We have a run of used values, followed by a run of unused ones.
            return new Result(1, 0xffff & runLengths[0], 0xffff & runLengths[0]);
        }

        class Result
        {
            private final int runIdx;
            private final int runStart;
            private final int candidateValue;

            Result(int runIdx, int runStart, int candidateValue) {
                this.runIdx = runIdx;
                this.runStart = runStart;
                this.candidateValue = candidateValue;
            }

            public int candidateValue() {
                return candidateValue;
            }

            public Result firstCandidateGreaterThan(int x) {
                if (x < candidateValue) throw new IndexOutOfBoundsException();

                int idx = runIdx;
                int start = runStart;
                while (true) {
                    int end = start + (0xffff & runLengths[idx]) - 1;
                    if (end > x) return new Result(idx, start, x + 1);

                    // Run of excluded
                    start += 0xffff & runLengths[idx];
                    idx++;
                    // Run of included
                    start += 0xffff & runLengths[idx];
                    idx++;

                    if (start > x) return new Result(idx, start, start);
                }
            }

            public void markUsed() {
                if (candidateValue == runStart) {
                    // Transfer one from the start of the run to the previous run
                    runLengths[runIdx - 1]++;
                    if (runLengths[runIdx] != INFINITY) runLengths[runIdx]--;
                    // May need to merge runs
                    if (runLengths[runIdx] == 0) {
                        runLengths[runIdx - 1] += runLengths[runIdx + 1];
                        for (int idx = runIdx; idx < MEMBOUND - 2; idx++) {
                            runLengths[idx] = runLengths[idx + 2];
                            if (runLengths[idx] == INFINITY) break;
                        }
                    }

                    return;
                }

                if (candidateValue == runStart + (0xffff & runLengths[runIdx]) - 1) {
                    // Transfer one from the end of the run to the following run.
                    if (runLengths[runIdx + 1] != INFINITY) runLengths[runIdx + 1]++;
                    if (runLengths[runIdx] != INFINITY) runLengths[runIdx]--;
                    // We never need to merge runs, because if we did we'd have hit the previous case instead
                    return;
                }

                // Need to split the run. From
                //   runIdx: a+1+b
                // to
                //   runIdx: a
                //   runIdx+1: 1
                //   runIdx+2: b
                //   runIdx+3: previous val at runIdx+1
                for (int idx = MEMBOUND - 1; idx > runIdx + 2; idx--) {
                    runLengths[idx] = runLengths[idx - 2];
                }
                runLengths[runIdx + 2] = runLengths[runIdx] == INFINITY ? INFINITY : (short)((0xffff & runLengths[runIdx]) + runStart - 1 - candidateValue);
                runLengths[runIdx + 1] = 1;
                runLengths[runIdx] = (short)(candidateValue - runStart);
            }
        }
    }
}
```

Title: Print a specific value in the Wythoff matrix modulo 2

Body:
The Wythoff matrix is an infinite matrix consisting of the Grundy numbers of each square on a chessboard in Wythoff's game.

Each entry in this matrix is equal to the smallest nonnegative number that does not appear anywhere above, to the left, or diagonally northwest of the position of the entry.

The top-left 20-by-20 square looks like this:

```<code>  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19
  1  2  0  4  5  3  7  8  6 10 11  9 13 14 12 16 17 15 19 20
  2  0  1  5  3  4  8  6  7 11  9 10 14 12 13 17 15 16 20 18
  3  4  5  6  2  0  1  9 10 12  8  7 15 11 16 18 14 13 21 17
  4  5  3  2  7  6  9  0  1  8 13 12 11 16 15 10 19 18 17 14
  5  3  4  0  6  8 10  1  2  7 12 14  9 15 17 13 18 11 16 21
  6  7  8  1  9 10  3  4  5 13  0  2 16 17 18 12 20 14 15 11
  7  8  6  9  0  1  4  5  3 14 15 13 17  2 10 19 21 12 22 16
  8  6  7 10  1  2  5  3  4 15 16 17 18  0  9 14 12 19 23 24
  9 10 11 12  8  7 13 14 15 16 17  6 19  5  1  0  2  3  4 22
 10 11  9  8 13 12  0 15 16 17 14 18  7  6  2  3  1  4  5 23
 11  9 10  7 12 14  2 13 17  6 18 15  8 19 20 21  4  5  0  1
 12 13 14 15 11  9 16 17 18 19  7  8 10 20 21 22  6 23  3  5
 13 14 12 11 16 15 17  2  0  5  6 19 20  9  7  8 10 22 24  4
 14 12 13 16 15 17 18 10  9  1  2 20 21  7 11 23 22  8 25 26
 15 16 17 18 10 13 12 19 14  0  3 21 22  8 23 20  9 24  7 27
 16 17 15 14 19 18 20 21 12  2  1  4  6 10 22  9 13 25 11 28
 17 15 16 13 18 11 14 12 19  3  4  5 23 22  8 24 25 21 26 10
 18 19 20 21 17 16 15 22 23  4  5  0  3 24 25  7 11 26 12 13
 19 20 18 17 14 21 11 16 24 22 23  1  5  4 26 27 28 10 13 25
</code>```

There is currently no known efficient algorithm for computing an arbitrary entry in the Wythoff matrix. However, your task in this problem is to try to design a heuristic function that will tell whether the number at a specific coordinate wythoff(x, y) is even or odd.

Your program may not contain more than 64 KB (65,536 bytes) of source code, or use more than 2 MB (2,097,152 bytes) of working memory.

In particular for memory usage, this means that the maximum resident set size of your program may not exceed 2 MB more than the maximum resident set size of an empty program in that language. In the case of an interpreted language, it would be the memory usage of the interpreter / virtual machine itself, and in the case of a compiled language, it would be the memory usage of a program that executes the main method and does nothing.

Your program will be tested on the 10000 x 10000 matrix for row values in 20000 <= x <= 29999 and column values in 20000 <= y <= 29999.

The score of your program is the accuracy rate (number of correct guesses) your program achieves, with shorter code acting as a tiebreaker.

Body:
CJam (accuracy 50016828/100000000, 6 bytes)

{+1&!}

(In ALGOL-style pseudocode for non-CJammers: return ((x + y) & 1) == 0).

This performs better than any of the other two dozen simple heuristics I've tried. It's even better than any combination with the next two best ones.

The score assumes that my calculated section of the matrix is correct. Independent verification welcomed. I'm hosting the calculated parity bits at http://cheddarmonk.org/codegolf/PPCG95604-parity.bz2 (8MB download, extracts to 50MB text file: since the matrix is symmetric about the main diagonal, I've only included each line starting from the main diagonal, so you have to offset, transpose, and bitwise OR to get the full square).

The code which I used to calculate it is Java. It uses the definition fairly straightforwardly, but with a set data structure which run-length encodes the ranges so that it's quick to skip to the next permitted value. Further optimisation would be possible, but it runs on my moderately old desktop in about two hours and 1.5GB of heap space.

import java.util.*;

public class PPCG95604Analysis
{
    static final int N = 30000;

    public static void main(String[] args) {
        Indicator[] cols = new Indicator[N];
        Indicator[] diag = new Indicator[N];
        for (int i = 0; i < N; i++) {
            cols[i] = new Indicator();
            diag[i] = new Indicator();
        }

        int maxVal = 0;

        for (int y = 0; y < N; y++) {
            Indicator row = new Indicator(cols[y]);

            for (int x = y; x < N; x++) {
                Indicator col = cols[x];
                Indicator dia = diag[x - y];

                Indicator.Result rr = row.firstCandidate();
                Indicator.Result rc = col.firstCandidate();
                Indicator.Result rd = dia.firstCandidate();

                while (true) {
                    int max = Math.max(Math.max(rr.candidateValue(), rc.candidateValue()), rd.candidateValue());
                    if (rr.candidateValue() == max && rc.candidateValue() == max && rd.candidateValue() == max) break;

                    if (rr.candidateValue() != max) rr = rr.firstCandidateGreaterThan(max - 1);
                    if (rc.candidateValue() != max) rc = rc.firstCandidateGreaterThan(max - 1);
                    if (rd.candidateValue() != max) rd = rd.firstCandidateGreaterThan(max - 1);
                }

                if (y >= 20000 && x >= 20000) System.out.format("%d", rr.candidateValue() & 1);
                maxVal = Math.max(maxVal, rr.candidateValue());
                rr.markUsed();
                rc.markUsed();
                rd.markUsed();
            }
            if (y >= 20000) System.out.println();
        }
    }

    static class Indicator
    {
        private final int INFINITY = (short)0xffff;
        private final int MEMBOUND = 10000;

        private short[] runLengths = new short[MEMBOUND];

        public Indicator() { runLengths[1] = INFINITY; }

        public Indicator(Indicator clone) { System.arraycopy(clone.runLengths, 0, runLengths, 0, MEMBOUND); }

        public Result firstCandidate() {
            // We have a run of used values, followed by a run of unused ones.
            return new Result(1, 0xffff & runLengths[0], 0xffff & runLengths[0]);
        }

        class Result
        {
            private final int runIdx;
            private final int runStart;
            private final int candidateValue;

            Result(int runIdx, int runStart, int candidateValue) {
                this.runIdx = runIdx;
                this.runStart = runStart;
                this.candidateValue = candidateValue;
            }

            public int candidateValue() {
                return candidateValue;
            }

            public Result firstCandidateGreaterThan(int x) {
                if (x < candidateValue) throw new IndexOutOfBoundsException();

                int idx = runIdx;
                int start = runStart;
                while (true) {
                    int end = start + (0xffff & runLengths[idx]) - 1;
                    if (end > x) return new Result(idx, start, x + 1);

                    // Run of excluded
                    start += 0xffff & runLengths[idx];
                    idx++;
                    // Run of included
                    start += 0xffff & runLengths[idx];
                    idx++;

                    if (start > x) return new Result(idx, start, start);
                }
            }

            public void markUsed() {
                if (candidateValue == runStart) {
                    // Transfer one from the start of the run to the previous run
                    runLengths[runIdx - 1]++;
                    if (runLengths[runIdx] != INFINITY) runLengths[runIdx]--;
                    // May need to merge runs
                    if (runLengths[runIdx] == 0) {
                        runLengths[runIdx - 1] += runLengths[runIdx + 1];
                        for (int idx = runIdx; idx < MEMBOUND - 2; idx++) {
                            runLengths[idx] = runLengths[idx + 2];
                            if (runLengths[idx] == INFINITY) break;
                        }
                    }

                    return;
                }

                if (candidateValue == runStart + (0xffff & runLengths[runIdx]) - 1) {
                    // Transfer one from the end of the run to the following run.
                    if (runLengths[runIdx + 1] != INFINITY) runLengths[runIdx + 1]++;
                    if (runLengths[runIdx] != INFINITY) runLengths[runIdx]--;
                    // We never need to merge runs, because if we did we'd have hit the previous case instead
                    return;
                }

                // Need to split the run. From
                //   runIdx: a+1+b
                // to
                //   runIdx: a
                //   runIdx+1: 1
                //   runIdx+2: b
                //   runIdx+3: previous val at runIdx+1
                for (int idx = MEMBOUND - 1; idx > runIdx + 2; idx--) {
                    runLengths[idx] = runLengths[idx - 2];
                }
                runLengths[runIdx + 2] = runLengths[runIdx] == INFINITY ? INFINITY : (short)((0xffff & runLengths[runIdx]) + runStart - 1 - candidateValue);
                runLengths[runIdx + 1] = 1;
                runLengths[runIdx] = (short)(candidateValue - runStart);
            }
        }
    }
}


答:
JavaScript (ES6), 185 bytes

```<code>a=>a.map((b,r)=>b.map((d,c)=>d.map((e,i)=>e.map((g,j)=>[1,2,3,4,5,6,7,8,9].filter(v=>a.every(b=>b[c].every(e=>e[j]-v))&b.every(d=>d[i].every(g=>g-v))&d.every(e=>e.every(g=>g-v))&!g)))))
</code>```

Takes as input an array of three rows of an array of three columns of a three by three array of cells of integers, and returns a five-dimensional array where all the integers have been replaced by arrays.

Title: Retrieve all possible marks that can be placed in a Sudoku puzzle

Body:
Given a Sudoku puzzle, find all possible marks that can be filled into each empty cell.

Test case

Input:

```<code>[
    [
        // Top left:
        [
            0, 0, 0,
            3, 4, 0,
            0, 0, 2
        ],
        // Top middle:
        [
            7, 4, 0,
            0, 0, 0,
            0, 0, 3
        ],
        // Top right:
        [
            8, 0, 0,
            1, 7, 0,
            0, 0, 0
        ]
    ],
    [
        // Middle left:
        [
            9, 0, 4,
            7, 0, 0,
            1, 0, 3
        ],
        // Center:
        [
            0, 5, 0,
            0, 0, 0,
            0, 7, 0
        ],
        // Middle right:
        [
            0, 0, 0,
            6, 4, 0,
            0, 0, 0
        ]
    ],
    [
        // Bottom left:
        [
            0, 0, 7,
            6, 3, 0,
            0, 0, 0
        ],
        // Bottom middle:
        [
            0, 0, 5,
            0, 0, 0,
            9, 1, 0
        ],
        // Bottom right:
        [
            0, 0, 0,
            5, 2, 0,
            7, 0, 0
        ]
    ]
]
</code>```

Output:

```<code>[
    [
        // Top left:
        [
            [5], [1, 5, 6, 9], [1, 5, 6, 9],
            [], [], [5, 6, 8, 9],
            [5, 8], [1, 5, 6, 7, 8, 9], []
        ],
        // Top middle:
        [
            [], [], [1, 2, 6, 9],
            [2, 5, 6, 8], [2, 6, 8, 9], [2, 6, 8, 9],
            [1, 5, 6, 8], [6, 8, 9], []
        ],
        // Top right:
        [
            [], [3, 5, 6, 9], [2, 3, 5, 6, 9],
            [], [], [2, 5, 6, 9],
            [4, 9], [5, 6, 9], [4, 5, 6, 9]
        ]
    ],
    [
        // Middle left:
        [
            [], [2, 6, 8], [],
            [], [2, 5, 8], [5, 8],
            [], [2, 5, 6, 8], []
        ],
        // Center:
        [
            [1, 2, 3, 6, 8], [], [1, 2, 6, 8],
            [1, 2, 3, 8], [2, 3, 8, 9], [1, 2, 8, 9],
            [2, 4, 6, 8], [], [2, 4, 6, 8, 9]
        ],
        // Middle right:
        [
            [2, 3], [1, 3, 8], [1, 2, 3, 7, 8],
            [], [], [1, 2, 3, 5, 8, 9],
            [2, 9], [5, 8, 9], [2, 5, 8, 9]
        ]
    ],
    [
        // Bottom left:
        [
            [2, 4, 8], [1, 2, 8, 9], [],
            [], [], [1, 8, 9],
            [2, 4, 5, 8], [2, 5, 8], [5, 8]
        ],
        // Bottom middle:
        [
            [2, 3, 4, 6, 8], [2, 3, 6, 8], [],
            [4, 8], [8], [4, 7, 8],
            [], [], [2, 4, 6, 8]
        ],
        // Bottom right:
        [
            [3, 4, 9], [1, 3, 6, 8, 9], [1, 3, 4, 6, 8, 9],
            [], [], [1, 4, 8, 9],
            [], [3, 6, 8], [3, 4, 6, 8]
        ]
    ]
]
</code>```

Output visualisation; the small numbers:

Rules

This is a code-golf. The shortest answer in bytes (or equivalent) wins.

Input can be in array or string format.

Input must be in the order presented above (top-left, top-middle, top-right, etc...)

Output can be in array or string format, as long as the output can logically represent the expected result.

Output must be in the same order as the input (top-left, top-middle, top-right, etc...)

Output does not need to be prettified.

Code must be applicable to any valid incomplete Sudoku grid.

Standard golfing rules apply.

Additional Notes:

You get additional fake internet points if your program or function uses the result to solve the Sudoku puzzle to the point where cell values can no longer be logically solved. For example, the very first cell in the test case can only ever possibly contain the number 5, so it should be considered when filling in the other values. This is just for fun and additional challenge, otherwise the shortest answer wins regardless of whether or not this criterion is met.

Body:
JavaScript (ES6), 185 bytes

a=>a.map((b,r)=>b.map((d,c)=>d.map((e,i)=>e.map((g,j)=>[1,2,3,4,5,6,7,8,9].filter(v=>a.every(b=>b[c].every(e=>e[j]-v))&b.every(d=>d[i].every(g=>g-v))&d.every(e=>e.every(g=>g-v))&!g)))))

Takes as input an array of three rows of an array of three columns of a three by three array of cells of integers, and returns a five-dimensional array where all the integers have been replaced by arrays.


问:
Surround a string with hashes
I've already made this in Python, but it seems that it could be shortened a lot:

```<code>txt = input("Type something.. ")
c = "#"
b = " "
print(c * (len(txt) + 4))
print(c, b * len(txt), c)
print(c, txt, c)
print(c, b * len(txt), c)
print(c * (len(txt) + 4))
</code>```

So if the user types:

```<code>Hello World
</code>```

The program prints:

```<code>###############
#             #
# Hello World #
#             #
###############
</code>```

Fewest bytes wins—and of course, the answer can be written in any language.

答:
05AB1E (legacy), 20 bytes

```<code>g4+'#×©,¹' .ø'#.ø,®,
</code>```

Try it online!

Title: Surround a string with hashes

Body:
05AB1E (legacy), 20 bytes

g4+'#×©,¹' .ø'#.ø,®,

Try it online!


问:
Sum the unique numbers in a list
For this challenge, the objective is to take a list of integers, and output the sum of every unique integer in that list, i.e. count multiples of the same integer only once.

Your input will be a string in the format "{1,2,3,4}" with any amount of elements. The string will never have whitespace or be in a format that does not match the example above. A list with 0 elements should return 0.

Examples

```<code>"{1,2,3,4}" -> 10
"{5,2,5}" -> 7
"{13,13,13}" -> 13
"{-5,5,5}" -> 0
"{12,12,13,13,14,14}" -> 39
"{}" -> 0
"{3}" -> 3
</code>```

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

Good luck!

答:
Perl, 28 bytes

Includes +1 for -p

Give input on STDIN

```<code>#!/usr/bin/perl -p
s%-?\d*%$a{$&}//=$_+=$&%reg
</code>```

Surprisingly hard to support the empty set and go below 29 bytes

Title: Sum the unique numbers in a list

Body:
Perl, 28 bytes

Includes +1 for -p

Give input on STDIN

#!/usr/bin/perl -p
s%-?\d*%$a{$&}//=$_+=$&%reg

Surprisingly hard to support the empty set and go below 29 bytes


问:
A square of text

The Challenge

Given a string, output the text in the shape of a square.

You can assume that the text will always fit in a square, and that it will never be an empty string.

You can also assume it will never have newlines.

Example

```<code>Input:
Hi, world

Output:
Hi,
 wo
rld
</code>```

Test Cases

```<code>Input:
Hi, world! Hello

Output:
Hi,
worl
d! H
ello

Input:
Lorem ipsum dolor sit amt

Output:
Lorem
 ipsu
m dol
or si
t amt

Input:
H

Output:
H
</code>```

Rules

This is code-golf, so shortest answer in bytes wins! Tiebreaker is most upvoted answer.

Standard loopholes are forbidden.

答:
QBIC, 41 bytes

```<code>;c=sqr(len(A))[1,c|?mid$$|(A,q,c) q=c*a+1
</code>```

Unfortunately, it doesn't work on text parameters with spaces in it. I'll put it on the QBIC todo-list.

Explanation:

```<code>;           gets the input as string A$
sqr(len(A)) calls the QBasic square root function, with the length of A$ as argument
[1,c...     Loops from 1 to the height of the square
?mid$$|(..) Prints the middel part of A$. The '$' has a reserved meaning in QBIC and needs to be escaped
q=c*a+1     Sets the starting point of the next mid$
<implicit>  NEXT
</code>```

Note that a more modern version of QBIC can solve this in 27 bytes:

```<code>_L;|g=sqr(a)[1,a,g|?_sA,b,g
</code>```

Improvements are: inline cmd-arg-grabbing (;), implementation of len (_L or _l) and substring (_s). Also, I've improved conditions and workings of the FOR-loop itself.

Title: A square of text

Body:
QBIC, 41 bytes

;c=sqr(len(A))[1,c|?mid$$|(A,q,c) q=c*a+1

Unfortunately, it doesn't work on text parameters with spaces in it. I'll put it on the QBIC todo-list.

Explanation:

;           gets the input as string A$
sqr(len(A)) calls the QBasic square root function, with the length of A$ as argument
[1,c...     Loops from 1 to the height of the square
?mid$$|(..) Prints the middel part of A$. The '$' has a reserved meaning in QBIC and needs to be escaped
q=c*a+1     Sets the starting point of the next mid$
<implicit>  NEXT

Note that a more modern version of QBIC can solve this in 27 bytes:

_L;|g=sqr(a)[1,a,g|?_sA,b,g

Improvements are: inline cmd-arg-grabbing (;), implementation of len (_L or _l) and substring (_s). Also, I've improved conditions and workings of the FOR-loop itself.


问:
The Real Slim Shady
Echo the following in as few bytes as possible:

```<code>I'm Slim Shady. Yes, I'm the real Shady.
All you other Slim Shadys are just imitating.
So, won't the real Slim Shady please stand up?
Please stand up. Please stand up.
</code>```

The following five words must appear EXACTLY ONCE in your code:

I'm

Slim

Shady

real

stand

答:
///, <s>131</s> <s>132</s> 135 bytes

```<code>/!/lease stand up//#/ Shady//@/ Slim#//$/ real//%/I'm/%@. Yes, % the$#.
All you other@s are just imitating.
So, won't the$@ p!?
P!. P!.
</code>```

Try it online!

Title: The Real Slim Shady

Body:
///, <s>131</s> <s>132</s> 135 bytes

/!/lease stand up//#/ Shady//@/ Slim#//$/ real//%/I'm/%@. Yes, % the$#.
All you other@s are just imitating.
So, won't the$@ p!?
P!. P!.

Try it online!


答:
x86 cpu instructions, 30 bytes

```<code>56 89 E6 8B 44 04 3D 00 00 74 0F D1 E8 50 E8 EF FF 8B 4C 04 81 E1 01 00 01 C8 5E C2 02 00
</code>```

meaning and disassembly:

```<code>; input in the stack sp+4
; output in ax
;0i,2Ka,4P
f:
push  si
mov   si,  sp
mov   ax,  [si+4]
cmp   ax,  0
je   .z
shr   ax,  1
push  ax
call  f
mov   cx,  [si+4]
and   cx,  1
add   ax,  cx
.z:
pop   si
ret 2

0000000F  56                push si
00000010  89E6              mov si,sp
00000012  8B4404            mov ax,[si+0x4]
00000015  3D0000            cmp ax,0x0
00000018  740F              jz 0x29
0000001A  D1E8              shr ax,1
0000001C  50                push ax
0000001D  E8EFFF            call 0xf
00000020  8B4C04            mov cx,[si+0x4]
00000023  81E10100          and cx,0x1
00000027  01C8              add ax,cx
00000029  5E                pop si
0000002A  C20200            ret 0x2
//30
</code>```

Title: Count the number of ones in an unsigned 16-bit integer

Body:
Write some statement(s) which will count the number of ones in an unsigned sixteen-bit integer.

For example, if the input is 1337, then the result is 6 because 1337 as a sixteen bit binary number is 0000010100111001, which contains six ones.

Body:
x86 cpu instructions, 30 bytes

56 89 E6 8B 44 04 3D 00 00 74 0F D1 E8 50 E8 EF FF 8B 4C 04 81 E1 01 00 01 C8 5E C2 02 00

meaning and disassembly:

; input in the stack sp+4
; output in ax
;0i,2Ka,4P
f:
push  si
mov   si,  sp
mov   ax,  [si+4]
cmp   ax,  0
je   .z
shr   ax,  1
push  ax
call  f
mov   cx,  [si+4]
and   cx,  1
add   ax,  cx
.z:
pop   si
ret 2

0000000F  56                push si
00000010  89E6              mov si,sp
00000012  8B4404            mov ax,[si+0x4]
00000015  3D0000            cmp ax,0x0
00000018  740F              jz 0x29
0000001A  D1E8              shr ax,1
0000001C  50                push ax
0000001D  E8EFFF            call 0xf
00000020  8B4C04            mov cx,[si+0x4]
00000023  81E10100          and cx,0x1
00000027  01C8              add ax,cx
00000029  5E                pop si
0000002A  C20200            ret 0x2
//30


答:
Python; accuracy = 54,074,818; size = 65,526 bytes

Previous scores: 50,227,165; 50,803,687; 50,953,001

```<code>#coding=utf-8
d=r'''<65,400 byte string>'''
def f(x,y):
 a=max(x,y)-20000;b=min(x,y)-20000;c=(a*(a+1)//2+b)%523200
 return(ord(d[c//8])>>(c%8))&1
</code>```

This approach divides all unique entries of the matrix into 523,200 groups and reads the best guess for the group (x, y) from a binary string. You can download the full source code from Google Drive.

I've used @PeterTaylor's parities to generate the string and to compute the accuracy.

Body:
Python; accuracy = 54,074,818; size = 65,526 bytes

Previous scores: 50,227,165; 50,803,687; 50,953,001

#coding=utf-8
d=r'''<65,400 byte string>'''
def f(x,y):
 a=max(x,y)-20000;b=min(x,y)-20000;c=(a*(a+1)//2+b)%523200
 return(ord(d[c//8])>>(c%8))&1

This approach divides all unique entries of the matrix into 523,200 groups and reads the best guess for the group (x, y) from a binary string. You can download the full source code from Google Drive.

I've used @PeterTaylor's parities to generate the string and to compute the accuracy.


问:
Simulate keystrokes
Your job is to simulate a couple of keystrokes that a user types in.

Input

A string array or string with a delimiter of your choice (outside the range 32-126) containing at least one 'keystroke'.

This array will only contain two types of string: passive keystrokes (single chars) and commands (chars within brackets [ ]).

Passive keystrokes

ASCII character codes [32-126]

Commands:

[B] : backspace (remove last character added if there is one)

[C] : copy all of what has already been written

[D] : delete all of what has been written

[P] : paste what has been copied

Output

The string produced by the keystrokes.

Examples

```<code>['H', 'e', 'l', 'l', 'o'] -> 'Hello'
['H', 'e', 'l', 'l', 'o', ' ', '[C]', '[P]'] -> 'Hello Hello '
['[D]', 'D', '[B]'] -> ''
['H', '[C]', 'i', '[P]', '[C]', '[P]'] -> 'HiHHiH'
['e', '[C]', '[B]', 'I', ' ', 'l', 'i', 'k', '[P]', ' ', 'b', '[P]', '[P]', 's', '!'] -> I like bees!
['N', '[P]'] -> 'N'
['#', '5', '0', 'K', '0', '0', '1', '[D]', '#', 'n', 'o', 't'] -> '#not'
['H', 'o', 'w', ' ', '[D]', 'H', 'e', 'y'] -> 'Hey'
['s', 'u', 'd', '[B]', 'p', '[C]', '[D]', 'I', ' ' , 'h', 'a', 'v', 'e', ' ', '[P]', 'p', 'e', 'r', '!'] -> 'I have supper!'
</code>```

This is code-golf, so shortest code in bytes wins!

答:
Vim, <s>76, 64, 62</s>, 58 keystrokes

Thanks to Loovjo for saving 7 keystrokes

Did someone say simulate keystrokes? Well then, it's a good thing my favorite language to golf in is all about simulating keystrokes!

```<code>:no s :%s/\M[
sB]/<C-v><C-h>
sC]/<C-v><esc>0y$A
sD]/<C-v><esc>"_S
sP]/<C-v><C-r>"
s<bs>\n
S<C-r>"
</code>```

Input comes in this format:

```<code>h
e
l
l
o

[C]
[P]
</code>```

This is a pretty straightforward answer. It just translates each "command" to the vim keystroke equivalent of that command. Let's take it line by line.

```<code>:no s :%s/\M[
</code>```

This saves a ton of bytes. Vim has a builtin "command line" where you can create mappings, change settings, save files, etc. Here we are creating a mapping. :no is short for :nnoremap which means "When we are in normal mode, substitute this left hand side for this right hand side." Since we are calling :%s/ five different times, this saves a lot. The \M is a nice trick. It means that the following search will be "Very No Magic", which means that the regex [B] will match the literal text [B] rather than a range containing just a B in it. Since the majority of the substitute commands have a brackets in them, we fill in the first one.

Then, we call five substitute commands. It's worth noting why I called <C-v> so many times. Characters like <esc>, <C-v>, <C-r>, etc. are unprintable characters, and must be typed into the command line with a <C-v>.

[B]: backspace. This one is pretty easy. Simply substitute each [B] with Ctrl-h, which is equivalent to backspace in vim.

[C]: copy all of what has already been written. This is translated to <esc>0y$A. This means:

```<code><esc>      " Escape to normal mode
     0     " Move to the beginning of this line
      y$   " Yank to the end of the line
        A  " Re enter insert mode at the end of this line.
</code>```

We could almost simply do Y in place of 0y$ which means "yank the whole line", but this also grabs a newline that we don't want.

[D]: delete all of what has been written. This is <esc>"_S. As before, <esc> exits insert mode so we can run commands. There are some things that are more convenient here. So we do

```<code>  S         " Delete this whole line and enter insert mode again
"_          " Send it to 'the black hole register'. This is just so that we don't overwrite the main register.
</code>```

[P]: paste what has been copied. This one is also very straightforward. It is just <C-r>" which means Insert the contents of register '"'. " happens to be the main register that 'y' yanks to.

Now that we have translated all of the commands, we must join all the lines together by removing all of the newline characters. Thanks to our mapping, this is just

```<code>s<bs>\n
</code>```

The <bs> is a backspace, (ASCII 0x08) and we need it because of the [ we filled in.

By now, we have translated the input into vim code, and we just need to run it. So we:

```<code>S           " Delete this whole line and enter insert mode
 <C-r>"     " Insert the keystrokes of register '"' as if they were typed by the user
</code>```

Title: Simulate keystrokes

Body:
Vim, <s>76, 64, 62</s>, 58 keystrokes

Thanks to Loovjo for saving 7 keystrokes

Did someone say simulate keystrokes? Well then, it's a good thing my favorite language to golf in is all about simulating keystrokes!

:no s :%s/\M[
sB]/<C-v><C-h>
sC]/<C-v><esc>0y$A
sD]/<C-v><esc>"_S
sP]/<C-v><C-r>"
s<bs>\n
S<C-r>"

Input comes in this format:

h
e
l
l
o

[C]
[P]

This is a pretty straightforward answer. It just translates each "command" to the vim keystroke equivalent of that command. Let's take it line by line.

:no s :%s/\M[

This saves a ton of bytes. Vim has a builtin "command line" where you can create mappings, change settings, save files, etc. Here we are creating a mapping. :no is short for :nnoremap which means "When we are in normal mode, substitute this left hand side for this right hand side." Since we are calling :%s/ five different times, this saves a lot. The \M is a nice trick. It means that the following search will be "Very No Magic", which means that the regex [B] will match the literal text [B] rather than a range containing just a B in it. Since the majority of the substitute commands have a brackets in them, we fill in the first one.

Then, we call five substitute commands. It's worth noting why I called <C-v> so many times. Characters like <esc>, <C-v>, <C-r>, etc. are unprintable characters, and must be typed into the command line with a <C-v>.

[B]: backspace. This one is pretty easy. Simply substitute each [B] with Ctrl-h, which is equivalent to backspace in vim.

[C]: copy all of what has already been written. This is translated to <esc>0y$A. This means:

<esc>      " Escape to normal mode
     0     " Move to the beginning of this line
      y$   " Yank to the end of the line
        A  " Re enter insert mode at the end of this line.

We could almost simply do Y in place of 0y$ which means "yank the whole line", but this also grabs a newline that we don't want.

[D]: delete all of what has been written. This is <esc>"_S. As before, <esc> exits insert mode so we can run commands. There are some things that are more convenient here. So we do

  S         " Delete this whole line and enter insert mode again
"_          " Send it to 'the black hole register'. This is just so that we don't overwrite the main register.

[P]: paste what has been copied. This one is also very straightforward. It is just <C-r>" which means Insert the contents of register '"'. " happens to be the main register that 'y' yanks to.

Now that we have translated all of the commands, we must join all the lines together by removing all of the newline characters. Thanks to our mapping, this is just

s<bs>\n

The <bs> is a backspace, (ASCII 0x08) and we need it because of the [ we filled in.

By now, we have translated the input into vim code, and we just need to run it. So we:

S           " Delete this whole line and enter insert mode
 <C-r>"     " Insert the keystrokes of register '"' as if they were typed by the user


问:
Which Row is the Key On?
Given any of the following characters (or a newline):

```<code>`1234567890-=~!@#$%^&*()_+qwertyuiop[]\QWERTYUIOP{}|asdfghjkl;'ASDFGHJKL:"zxcvbnm,./ZXCVBNM<>?
</code>```

Your program must output the row that it is on the keyboard

Because my keyboard is (almost) out of battery, your code must be as short as possible

The keyboard your program should use (for the row lookup), should look like:

Row 1:~` !1@2 #3$4 %5^6 &7*8 (9)0 _-+=

Row 2:                         Q W E R T Y U I O P {[ }]    |\
Row 3:                              A S D F G H J K L :; "' ↵ return
Row 4:                                 Z X C V B N M <, >. ?/
Row 5:                                                    space

Where ↵  return is a newline. Empty keys don't mean anything.

Examples

```<code>"$"
1

"R"
2

"a"
3

"?"
4

"\n"
3

" "
5
</code>```

where \n is a newline character.

Specifications

Your program should be case insensitive

Your program only needs to handle the characters on the keyboard shown

Title: Which Row is the Key On?

Body:
Python 2, 146 bytes

e="\n";lambda x:("`1234567890-=~!@#$%^&*()_+qwertyuiop[]\\QWERTYUIOP{}|asdfghjkl;'ASDFGHJKL:\""+e*4+"zxcvbnm,./ZXCVBNM<>?"+e*13+" ").index(x)/26+1


答:
PHP, 131 Bytes

17 Bytes save by @IsmaelMiguel ternary operator

```<code><?$c=[];foreach($_GET[a]as$v)($t=$v[1])!=P?$t!=C?$t!=B?$t!=D?$o[]=$v:$o=[]:array_pop($o):$c=$o:$o=array_merge($o,$c);echo join($o);
</code>```

Title: Simulate keystrokes

Body:
Your job is to simulate a couple of keystrokes that a user types in.

Input

A string array or string with a delimiter of your choice (outside the range 32-126) containing at least one 'keystroke'.

This array will only contain two types of string: passive keystrokes (single chars) and commands (chars within brackets [ ]).

Passive keystrokes

ASCII character codes [32-126]

Commands:

[B] : backspace (remove last character added if there is one)

[C] : copy all of what has already been written

[D] : delete all of what has been written

[P] : paste what has been copied

Output

The string produced by the keystrokes.

Examples

```<code>['H', 'e', 'l', 'l', 'o'] -> 'Hello'
['H', 'e', 'l', 'l', 'o', ' ', '[C]', '[P]'] -> 'Hello Hello '
['[D]', 'D', '[B]'] -> ''
['H', '[C]', 'i', '[P]', '[C]', '[P]'] -> 'HiHHiH'
['e', '[C]', '[B]', 'I', ' ', 'l', 'i', 'k', '[P]', ' ', 'b', '[P]', '[P]', 's', '!'] -> I like bees!
['N', '[P]'] -> 'N'
['#', '5', '0', 'K', '0', '0', '1', '[D]', '#', 'n', 'o', 't'] -> '#not'
['H', 'o', 'w', ' ', '[D]', 'H', 'e', 'y'] -> 'Hey'
['s', 'u', 'd', '[B]', 'p', '[C]', '[D]', 'I', ' ' , 'h', 'a', 'v', 'e', ' ', '[P]', 'p', 'e', 'r', '!'] -> 'I have supper!'
</code>```

This is code-golf, so shortest code in bytes wins!

Body:
PHP, 131 Bytes

17 Bytes save by @IsmaelMiguel ternary operator

<?$c=[];foreach($_GET[a]as$v)($t=$v[1])!=P?$t!=C?$t!=B?$t!=D?$o[]=$v:$o=[]:array_pop($o):$c=$o:$o=array_merge($o,$c);echo join($o);


答:
Python <s>120 119</s> 116 bytes

f=lambda s,r='',c='':f(s[1:],*{'B':(r[:-1],c),'C':(r,r),'D':('',c),'P':(r+c,c),'':(r+s[0],c)}[s[0][1:2]])if s else r
```

Ideone

A recursive function with input, s, a list of the key-strokes.

Each recursive call updates the return text, r and, in the case of a [C], the clipboard, c until s is empty.

The new values of r and c are found by indexing into a dictionary, {...}, and passed with unpacking, *. For the passive keystrokes s[0][1:2]will return an empty string and the key '' will be used instead.

Title: Simulate keystrokes

Body:
Python <s>120 119</s> 116 bytes

f=lambda s,r='',c='':f(s[1:],*{'B':(r[:-1],c),'C':(r,r),'D':('',c),'P':(r+c,c),'':(r+s[0],c)}[s[0][1:2]])if s else r

Ideone

A recursive function with input, s, a list of the key-strokes.

Each recursive call updates the return text, r and, in the case of a [C], the clipboard, c until s is empty.

The new values of r and c are found by indexing into a dictionary, {...}, and passed with unpacking, *. For the passive keystrokes s[0][1:2]will return an empty string and the key '' will be used instead.


答:
Mathematica, 100 bytes

```<code>""<>Fold[Switch[#2,"[B]",Most@#~Check~{},"[C]",a=#,"[D]",{},"[P]",#~Join~a,_,Append@##]&,a={};{},#]&
</code>```

Anonymous function. Takes a list of strings as input and returns a string as output. Ignore any messages generated.

Title: Simulate keystrokes

Body:
Mathematica, 100 bytes

""<>Fold[Switch[#2,"[B]",Most@#~Check~{},"[C]",a=#,"[D]",{},"[P]",#~Join~a,_,Append@##]&,a={};{},#]&

Anonymous function. Takes a list of strings as input and returns a string as output. Ignore any messages generated.


答:
JavaScript (ES6), <s>84</s> <s>80</s> <s>77</s> 76 bytes

Saved 3 bytes thanks to @Neil, 1 more thanks to @edc65

```<code>x=>x.reduce((s,[c,z])=>z<'C'?s.slice(0,-1):z<'D'?t=s:z<'P'?"":s+=z?t:c,t="")
</code>```

.map is two bytes longer:

```<code>x=>x.map(([c,z])=>s=z<'C'?s.slice(0,-1):z<'D'?t=s:z<'P'?"":s+=z?t:c,s=t="")&&s
</code>```

Test snippet

f=x=>x.reduce((s,[c,z])=>z<'C'?s.slice(0,-1):z<'D'?t=s:z<'P'?"":s+=z?t:c,t="")

console.log(f(['e', '[C]', '[B]', 'I', ' ', 'l', 'i', 'k', '[P]', ' ', 'b', '[P]', '[P]', 's', '!']))```
<pre class="snippet-code-html lang-html prettyprint-override"><code><button onclick="console.log(f(I.value.split('\n')))">Run</button>
<br><textarea id=I rows=10>H
e
l
l
o

[C]
[P]</textarea><br></code>```

Title: Simulate keystrokes

Body:
JavaScript (ES6), <s>84</s> <s>80</s> <s>77</s> 76 bytes

Saved 3 bytes thanks to @Neil, 1 more thanks to @edc65

x=>x.reduce((s,[c,z])=>z<'C'?s.slice(0,-1):z<'D'?t=s:z<'P'?"":s+=z?t:c,t="")

.map is two bytes longer:

x=>x.map(([c,z])=>s=z<'C'?s.slice(0,-1):z<'D'?t=s:z<'P'?"":s+=z?t:c,s=t="")&&s

Test snippet

f=x=>x.reduce((s,[c,z])=>z<'C'?s.slice(0,-1):z<'D'?t=s:z<'P'?"":s+=z?t:c,t="")

console.log(f(['e', '[C]', '[B]', 'I', ' ', 'l', 'i', 'k', '[P]', ' ', 'b', '[P]', '[P]', 's', '!']))

<button onclick="console.log(f(I.value.split('\n')))">Run</button>
<br><textarea id=I rows=10>H
e
l
l
o

[C]
[P]</textarea><br>


Title: Simulate keystrokes

Body:
Python 2, 96 95 93 bytes

r=c=""
for o in input():c=[c,r][x=="[C]"];r=[r+c,r[:-1],r,"",r+o][ord(o[1:2]or"E")%5]
print r


答:
RProgN, 8 Bytes

```<code>2 B S ++
</code>```

Explination

```<code>2 B     # Convert to base 2
S       # Convert from string to a stack of individual characters
++      # Sum the stack.
</code>```

Simple enough, Could be made cheaper if the sugar for sum was single character, instead of double, as ►2BS<SUM> could then be used, saving a byte.

Test Cases

```<code>1337:       6.0
16:         1.0
255:        8.0
1236172031: 21.0
</code>```

Body:
RProgN, 8 Bytes

2 B S ++

Explination

2 B     # Convert to base 2
S       # Convert from string to a stack of individual characters
++      # Sum the stack.

Simple enough, Could be made cheaper if the sugar for sum was single character, instead of double, as ►2BS<SUM> could then be used, saving a byte.

Test Cases

1337:       6.0
16:         1.0
255:        8.0
1236172031: 21.0


答:
Jelly, <s>50 51</s> 48 bytes

```<code>Ṿ”;;µṭ“Ṗ“ø©“ḣ0“;®”
L>1a2ị$i@“BCDP0”ịÇ
Ç€“⁶Ṗ©”;FV
</code>```

TryItOnline

Or all test cases

How?

```<code>Ṿ”;;µṭ“Ṗ“ø©“ḣ0“;®” - Link 1, CreateCodeLookupValueList: keystroke
      “Ṗ“ø©“ḣ0“;®” - list of strings, ["Ṗ","ø©","ḣ0"";®"] - these are Jelly code for:
                         Ṗ  : pop (i.e. delete last entry)
                         ø© : niladic separation and copy to register (i.e. copy)
                         ḣ0 : head to 0 (i.e. delete all entries)
                         ;® : concatenate with value of register (i.e. paste)
    µ              - monadic chain separation
Ṿ                  - uneval - make a Jelly code version of the keystroke
                                               e.g. "I" -> "“I”"
 ”;                - string literal ";"                      |
   ;               - concatenate e.g. ";I"                   v
     ṭ             - tack, to make the list ["Ṗ","ø©",";®","“I”"]
                             a keystroke - a command will evaluate to a string like
                             "“[C]”" but wont be accessed)

L>1a2ị$i@“BCDP0”ịÇ - Link 2, ConvertAKeystokeToJellyCodeString: keystroke
L>1                - length greater than 1? (i.e. isCommand?)
      $            - last two links as a monad
   a               - and
    2ị             - index 2 of the keystroke (0 due to and for a passive keystroke)
         “BCDP0”   - Literal string "BCP0"
       i@          - find first matching index of, with reversed arguments
                ị  - index into
                 Ç - call last link (1) as a monad (get code to replace this keystroke)

Ç€“⁶Ṗ©”;FV - Main link: list of keystrokes
Ç€         - call last link (2) as a monad (convert to Jelly code)
  “⁶Ṗ©”    - literal string "⁶Ṗ©" - setup the register with an empty string:
                 ⁶ :literal " ";
                 Ṗ : pop the space to give an empty string;
                 © : places it into the register
       ;   - concatenate (put that at the front)
        F  - flatten list (lists and strings are equivalent in Jelly)
         V - evaluate the string
</code>```

For example

```<code>The input:
    ['e', '[C]', '[B]', 'I', ' ', 'l', 'i', 'k', '[P]', ' ', 'B', '[P]', '[P]', 's', '!']
Becomes the Jelly code:
    "⁶Ṗ©;“e”ø©Ṗ;“I”;“ ”;“l”;“i”;“k”;®;“ ”;“B”;®;®;“s”;“!”"
Which then evaluates to
    "I like Bees!"
</code>```

- with a capital 'B' as a test case, since before I fixed a bug it would have returned "I likeees!"

Title: Simulate keystrokes

Body:
Jelly, <s>50 51</s> 48 bytes

Ṿ”;;µṭ“Ṗ“ø©“ḣ0“;®”
L>1a2ị$i@“BCDP0”ịÇ
Ç€“⁶Ṗ©”;FV

TryItOnline

Or <a href="http://jelly.tryitonline.net/#code=4bm-4oCdOzvCteG5reKAnOG5luKAnMO4wqnigJzhuKMw4oCcO8Ku4oCdCkw-MWEy4buLJGlA4oCcQkNEUDDigJ3hu4vDhwrDh-KCrOKAnOKBtuG5lsKp4oCdO0ZWCsOH4oKsWQ&input=&args=W1snSCcsICdlJywgJ2wnLCAnbCcsICdvJ10sWydIJywgJ2UnLCAnbCcsICdsJywgJ28nLCAnICcsICdbQ10nLCAnW1BdJ10sWydbRF0nLCAnRCcsICdbQl0nXSxbJyddLFsnZScsICdbQ10nLCAnW0JdJywgJ0knLCAnICcsICdsJywgJ2knLCAnaycsICdbUF0nLCAnICcsICdiJywgJ1tQXScsICdbUF0nLCAncycsICchJ10sWydOJywgJ1tQXSddLFsnIycsICc1JywgJzAnLCAnSycsICcwJywgJzAnLCAnMScsICdbRF0nLCAnIycsICduJywgJ28nLCAndCddXQ" rel="nofollow">all test cases

How?

Ṿ”;;µṭ“Ṗ“ø©“ḣ0“;®” - Link 1, CreateCodeLookupValueList: keystroke
      “Ṗ“ø©“ḣ0“;®” - list of strings, ["Ṗ","ø©","ḣ0"";®"] - these are Jelly code for:
                         Ṗ  : pop (i.e. delete last entry)
                         ø© : niladic separation and copy to register (i.e. copy)
                         ḣ0 : head to 0 (i.e. delete all entries)
                         ;® : concatenate with value of register (i.e. paste)
    µ              - monadic chain separation
Ṿ                  - uneval - make a Jelly code version of the keystroke
                                               e.g. "I" -> "“I”"
 ”;                - string literal ";"                      |
   ;               - concatenate e.g. ";I"                   v
     ṭ             - tack, to make the list ["Ṗ","ø©",";®","“I”"]
                             a keystroke - a command will evaluate to a string like
                             "“[C]”" but wont be accessed)

L>1a2ị$i@“BCDP0”ịÇ - Link 2, ConvertAKeystokeToJellyCodeString: keystroke
L>1                - length greater than 1? (i.e. isCommand?)
      $            - last two links as a monad
   a               - and
    2ị             - index 2 of the keystroke (0 due to and for a passive keystroke)
         “BCDP0”   - Literal string "BCP0"
       i@          - find first matching index of, with reversed arguments
                ị  - index into
                 Ç - call last link (1) as a monad (get code to replace this keystroke)

Ç€“⁶Ṗ©”;FV - Main link: list of keystrokes
Ç€         - call last link (2) as a monad (convert to Jelly code)
  “⁶Ṗ©”    - literal string "⁶Ṗ©" - setup the register with an empty string:
                 ⁶ :literal " ";
                 Ṗ : pop the space to give an empty string;
                 © : places it into the register
       ;   - concatenate (put that at the front)
        F  - flatten list (lists and strings are equivalent in Jelly)
         V - evaluate the string

For example

The input:
    ['e', '[C]', '[B]', 'I', ' ', 'l', 'i', 'k', '[P]', ' ', 'B', '[P]', '[P]', 's', '!']
Becomes the Jelly code:
    "⁶Ṗ©;“e”ø©Ṗ;“I”;“ ”;“l”;“i”;“k”;®;“ ”;“B”;®;®;“s”;“!”"
Which then evaluates to
    "I like Bees!"

- with a capital 'B' as a test case, since before I fixed a bug it would have returned "I likeees!"


问:
Draw an ASCII chess board!
Here is a simple challenge for you: You must produce this ASCII representation of a chess board. White is represented by uppercase characters, and black is represented by lowercase. Empty tiles are represented by a .. Here is the full board:

```<code>rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR
</code>```

Since this is a kolmogorov-complexity question, you may not take any input and you must output this board by any default method, for example, saving a file, printing to STDOUT or returning from a function. You may optionally produce one trailing newline. Standard loopholes apply, and the shortest program in bytes!

However, remember this is equally as much a competition between submissions in the same language. While it's unlikely that a languages like Java could beat a language like perl, or a golfing language like pyth or cjam, having the shortest Java answer is still really impressive! To help you track the shortest answer in each language, you may use this leaderboard, which will show the shortest submission by language and overall.

Leaderboards

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```<code># Language Name, N bytes
</code>```

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

```<code># Ruby, <s>104</s> <s>101</s> 96 bytes
</code>```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

```<code># Perl, 43 + 2 (-p flag) = 45 bytes
</code>```

You can also make the language name a link which will then show up in the leaderboard snippet:

```<code># [><>](http://esolangs.org/wiki/Fish), 121 bytes
</code>```

var QUESTION_ID=95745,OVERRIDE_USER=31716;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/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

```

答:
Actually, 26 bytes

```<code>'p8*"rnbqkbnr"│û@û4'.8*n((
</code>```

Try it online!

Explanation:

```<code>'p8*"rnbqkbnr"│û@û4'.8*n((
'p8*                        "p"*8 ["pppppppp"]
    "rnbqkbnr"              that string ["rnbqkbnr", "pppppppp"]
              │             duplicate stack ["rnbqkbnr", "pppppppp", "rnbqkbnr", "pppppppp"]
                û@û         uppercase the dupes ["RNBQKBNR", "PPPPPPPP", "rnbqkbnr", "pppppppp"]
               4   '.8*n    "."*8, 4 times ["RNBQKBNR", "PPPPPPPP", "........", "........", "........", "........", "rnbqkbnr", "pppppppp"]
                        ((  move the uppercase strings to the bottom of the stack, implicitly print
</code>```

Title: Draw an ASCII chess board!

Body:
Actually, 26 bytes

'p8*"rnbqkbnr"│û@û4'.8*n((

Try it online!

Explanation:

'p8*"rnbqkbnr"│û@û4'.8*n((
'p8*                        "p"*8 ["pppppppp"]
    "rnbqkbnr"              that string ["rnbqkbnr", "pppppppp"]
              │             duplicate stack ["rnbqkbnr", "pppppppp", "rnbqkbnr", "pppppppp"]
                û@û         uppercase the dupes ["RNBQKBNR", "PPPPPPPP", "rnbqkbnr", "pppppppp"]
               4   '.8*n    "."*8, 4 times ["RNBQKBNR", "PPPPPPPP", "........", "........", "........", "........", "rnbqkbnr", "pppppppp"]
                        ((  move the uppercase strings to the bottom of the stack, implicitly print


答:
V, <s>27</s>, 26 bytes

```<code>i¸P
RNBQKBNRäkgujddppÒ.4Ä
</code>```

Try it online!

This contains some unprintable characters, so here is the readable version:

```<code>i¸P
RNBQKBNR<esc>äkgujddppÒ.4Ä
</code>```

where <esc> represents 0x1B. Explanation:

```<code>i                               " Enter insert mode
 ¸P                             " Enter 8 'P' characters
                                " and a newline
RNBQKBNR<esc>                   " Enter the first row and escape to normal mode.
             äk                 " Duplicate this line and the line above
               guj              " Convert this line, and the line below to lowercase
                  dd            " Delete this line
                    pp          " And paste it twice below us
                      Ò.        " Replace this whole line with '.' chars
                        4Ä      " And create four copies of this line
</code>```

Title: Draw an ASCII chess board!

Body:
Here is a simple challenge for you: You must produce this ASCII representation of a chess board. White is represented by uppercase characters, and black is represented by lowercase. Empty tiles are represented by a .. Here is the full board:

```<code>rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR
</code>```

Since this is a kolmogorov-complexity question, you may not take any input and you must output this board by any default method, for example, saving a file, printing to STDOUT or returning from a function. You may optionally produce one trailing newline. Standard loopholes apply, and the shortest program in bytes!

However, remember this is equally as much a competition between submissions in the same language. While it's unlikely that a languages like Java could beat a language like perl, or a golfing language like pyth or cjam, having the shortest Java answer is still really impressive! To help you track the shortest answer in each language, you may use this leaderboard, which will show the shortest submission by language and overall.

Leaderboards

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```<code># Language Name, N bytes
</code>```

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

```<code># Ruby, <s>104</s> <s>101</s> 96 bytes
</code>```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

```<code># Perl, 43 + 2 (-p flag) = 45 bytes
</code>```

You can also make the language name a link which will then show up in the leaderboard snippet:

```<code># [><>](http://esolangs.org/wiki/Fish), 121 bytes
</code>```

var QUESTION_ID=95745,OVERRIDE_USER=31716;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/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, <s>27</s>, 26 bytes

i¸P
RNBQKBNRäkgujddppÒ.4Ä

Try it online!

This contains some unprintable characters, so here is the readable version:

i¸P
RNBQKBNR<esc>äkgujddppÒ.4Ä

where <esc> represents 0x1B. Explanation:

i                               " Enter insert mode
 ¸P                             " Enter 8 'P' characters
                                " and a newline
RNBQKBNR<esc>                   " Enter the first row and escape to normal mode.
             äk                 " Duplicate this line and the line above
               guj              " Convert this line, and the line below to lowercase
                  dd            " Delete this line
                    pp          " And paste it twice below us
                      Ò.        " Replace this whole line with '.' chars
                        4Ä      " And create four copies of this line


Title: Draw an ASCII chess board!

Body:
J, <s>55</s> 52 bytes

'.rnbkqpPQKBNR'{~(+-@|.)8 8$1 2 3 4 5 3 2 1,8 48#6 0

Test and intermediate steps

   '.rnbkqpPQKBNR'{~(+-@|.)8 8$1 2 3 4 5 3 2 1,8 48#6 0
rnbkqbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBKQBNR
   8 48#6 0
6 6 6 6 6 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
   1 2 3 4 5 3 2 1,8 48#6 0
1 2 3 4 5 3 2 1 6 6 6 6 6 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
   8 8$1 2 3 4 5 3 2 1,8 48#6 0
1 2 3 4 5 3 2 1
6 6 6 6 6 6 6 6
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
   (+-@|.)8 8$1 2 3 4 5 3 2 1,8 48#6 0
 1  2  3  4  5  3  2  1
 6  6  6  6  6  6  6  6
 0  0  0  0  0  0  0  0
 0  0  0  0  0  0  0  0
 0  0  0  0  0  0  0  0
 0  0  0  0  0  0  0  0
_6 _6 _6 _6 _6 _6 _6 _6
_1 _2 _3 _4 _5 _3 _2 _1
   '.rnbkqpPQKBNR'{~(+-@|.)8 8$1 2 3 4 5 3 2 1,8 48#6 0
rnbkqbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBKQBNR


答:
Cheddar, 56 bytes

```<code>a=['rnbqkbnr','p'*8]+['.'*8]*2->(a+a.rev=>@.upper).vfuse
</code>```

Uses the new => feature.

Explanation

```<code>a=                      // set a to the first half
  ['rnbqkbnr','p'*8] +  // First two rows
  ['.'*8]*2             // Next two dots
->(
   a +
   a.rev=>@.upper       // Reverse and map all items to uppercase
).vfuse                 // Join on newlines
</code>```

Title: Draw an ASCII chess board!

Body:
Cheddar, 56 bytes

a=['rnbqkbnr','p'*8]+['.'*8]*2->(a+a.rev=>@.upper).vfuse

Uses the new => feature.

Explanation

a=                      // set a to the first half
  ['rnbqkbnr','p'*8] +  // First two rows
  ['.'*8]*2             // Next two dots
->(
   a +
   a.rev=>@.upper       // Reverse and map all items to uppercase
).vfuse                 // Join on newlines


答:
Jolf, 32 bytes

```<code>pη++γͺ"rnbqkbnr"*8'p*²*8'.6ΜγdBH
</code>```

I oughta remake this language soon... Try it here!

Bonus: all-ascii version:

```<code>pη++on~."rnbqkbnr"*8'p*~:*8'.6ΜndBH
</code>```

Explanation

```<code>pη++γͺ"rnbqkbnr"*8'p*²*8'.6ΜγdBH
     ͺ                           pair
      "rnbqkbnr"                  this string
                *8'p              and 8 p's
    γ                            (call this γ)
   +                             add that with
                      *8'.        8 .'s
                     ²             wrapped in an array
                    *     6         repeated 6 times
  +                               add THAT with
                            Μγd    γ mapped over
                              BH   the uppercase version of H
pη                                and join all this with newlines
</code>```

Title: Draw an ASCII chess board!

Body:
Jolf, 32 bytes

pη++γͺ"rnbqkbnr"*8'p*²*8'.6ΜγdBH

I oughta remake this language soon... Try it here!

Bonus: all-ascii version:

pη++on~."rnbqkbnr"*8'p*~:*8'.6ΜndBH

Explanation

pη++γͺ"rnbqkbnr"*8'p*²*8'.6ΜγdBH
     ͺ                           pair
      "rnbqkbnr"                  this string
                *8'p              and 8 p's
    γ                            (call this γ)
   +                             add that with
                      *8'.        8 .'s
                     ²             wrapped in an array
                    *     6         repeated 6 times
  +                               add THAT with
                            Μγd    γ mapped over
                              BH   the uppercase version of H
pη                                and join all this with newlines


答:
Jelly, <s>25</s> 24 bytes

```<code>“.“.“p“rnbqkbn”ṁ€8µṚ;ŒuY
</code>```

Try it online!

Thanks to @Lynn for golfing off 1 byte!

How it works

```<code>“.“.“p“rnbqkbn”ṁ€8µṚ;ŒuY  Main link. No arguments.

“.“.“p“rnbqkbn”           Yield [".", ".", "p", "rnbqkbnr"].
               ṁ€8        Mold-each 8; reshape each string like the array
                          [1, 2, 3, 4, 5, 6, 7, 8], i.e., cyclically repeat its
                          contents to create strings of length 8.
                          This yields the upper half of the board in reversed
                          order, i.e., the string array
                          A := "........", "........", "pppppppp", "rnbqkbnr"].
                  µ       Begin a new, monadic chain. Argument: A
                   Ṛ      Reverse A.
                     Œu   Convert all characters in A to uppercase.
                    ;     Concatenate the results to both sides.
                       Y  Join the strings, separating by linefeeds.
</code>```

Title: Draw an ASCII chess board!

Body:
Jelly, <s>25</s> 24 bytes

“.“.“p“rnbqkbn”ṁ€8µṚ;ŒuY

Try it online!

Thanks to @Lynn for golfing off 1 byte!

How it works

“.“.“p“rnbqkbn”ṁ€8µṚ;ŒuY  Main link. No arguments.

“.“.“p“rnbqkbn”           Yield [".", ".", "p", "rnbqkbnr"].
               ṁ€8        Mold-each 8; reshape each string like the array
                          [1, 2, 3, 4, 5, 6, 7, 8], i.e., cyclically repeat its
                          contents to create strings of length 8.
                          This yields the upper half of the board in reversed
                          order, i.e., the string array
                          A := "........", "........", "pppppppp", "rnbqkbnr"].
                  µ       Begin a new, monadic chain. Argument: A
                   Ṛ      Reverse A.
                     Œu   Convert all characters in A to uppercase.
                    ;     Concatenate the results to both sides.
                       Y  Join the strings, separating by linefeeds.


答:
Ruby, <s>45</s> 44

1 byte saved thanks to tuxcrafting.

```<code>puts"rnbqkbnr",?p*8,[?.*8]*4,?P*8,"RNBQKBNR"
</code>```

This is 45

```<code>puts s="rnbqkbnr",?p*8,[?.*8]*4,?P*8,s.upcase
</code>```

Trying anything cleverer just seems to make it longer.

Title: Draw an ASCII chess board!

Body:
Ruby, <s>45</s> 44

1 byte saved thanks to tuxcrafting.

puts"rnbqkbnr",?p*8,[?.*8]*4,?P*8,"RNBQKBNR"

This is 45

puts s="rnbqkbnr",?p*8,[?.*8]*4,?P*8,s.upcase

Trying anything cleverer just seems to make it longer.


答:
Gloo, 46 Bytes

Gloo is a very, erm, young language with very little stack manipulation implemented. I think this is probably the best I can do since there's also no uppercase function. The raw bytes are below, and can be run from the interpreter using gloo.py -f <file>.

```<code>Offset   00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
000000   22 72 6E 62 71 6B 62 6E 72 0A 22 22 70 22 38 2A   "rnbqkbnr.""p"8*
000010   22 0A 22 22 2E 22 38 2A 22 0A 22 2B 34 2A 22 50   ".""."8*"."+4*"P
000020   22 38 2A 22 0A 52 4E 42 51 4B 42 4E 52 22         "8*".RNBQKBNR"
</code>```

This doesn't count because it was updated after the challenge started, but now there's an easy 32 byte solution:

"rnbqkbnr"'p8*[_?¶Ä'.4*‘8*’;[¶jj

```<code>Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

00000000  22 72 6E 62 71 6B 62 6E 72 22 27 70 38 2A 5B 5F  "rnbqkbnr"'p8*[_
00000010  3F B6 C4 27 2E 34 2A 91 38 2A 92 3B 5B B6 6A 6A  ?¶Ä'.4*‘8*’;[¶jj
</code>```

Title: Draw an ASCII chess board!

Body:
Gloo, 46 Bytes

Gloo is a very, erm, young language with very little stack manipulation implemented. I think this is probably the best I can do since there's also no uppercase function. The raw bytes are below, and can be run from the interpreter using gloo.py -f <file>.

Offset   00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
000000   22 72 6E 62 71 6B 62 6E 72 0A 22 22 70 22 38 2A   "rnbqkbnr.""p"8*
000010   22 0A 22 22 2E 22 38 2A 22 0A 22 2B 34 2A 22 50   ".""."8*"."+4*"P
000020   22 38 2A 22 0A 52 4E 42 51 4B 42 4E 52 22         "8*".RNBQKBNR"

This doesn't count because it was updated after the challenge started, but now there's an easy 32 byte solution:

"rnbqkbnr"'p8*[_?¶Ä'.4*‘8*’;[¶jj

Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

00000000  22 72 6E 62 71 6B 62 6E 72 22 27 70 38 2A 5B 5F  "rnbqkbnr"'p8*[_
00000010  3F B6 C4 27 2E 34 2A 91 38 2A 92 3B 5B B6 6A 6A  ?¶Ä'.4*‘8*’;[¶jj


答:
Perl, <s>53</s> 50 bytes

Includes +1 for -p

Give input on STDIN terminated by newlines (the last newline may be left out, so it counts as a string separated by newlines):

```<code>keystrokes.pl
H
e
[C]
[D]
a
b
[B]
[P]
z
^D
</code>```

gives

```<code>aHez
</code>```

keystrokes.pl:

```<code>#!/usr/bin/perl -p
$\.=/^.$/?$&:/P/?$a:(/C/?$a=$\:chop($\x=/B/))x0}{
</code>```

Almost caught the Jelly answer but the fiend escaped to 48 bytes...

Title: Simulate keystrokes

Body:
Your job is to simulate a couple of keystrokes that a user types in.

Input

A string array or string with a delimiter of your choice (outside the range 32-126) containing at least one 'keystroke'.

This array will only contain two types of string: passive keystrokes (single chars) and commands (chars within brackets [ ]).

Passive keystrokes

ASCII character codes [32-126]

Commands:

[B] : backspace (remove last character added if there is one)

[C] : copy all of what has already been written

[D] : delete all of what has been written

[P] : paste what has been copied

Output

The string produced by the keystrokes.

Examples

```<code>['H', 'e', 'l', 'l', 'o'] -> 'Hello'
['H', 'e', 'l', 'l', 'o', ' ', '[C]', '[P]'] -> 'Hello Hello '
['[D]', 'D', '[B]'] -> ''
['H', '[C]', 'i', '[P]', '[C]', '[P]'] -> 'HiHHiH'
['e', '[C]', '[B]', 'I', ' ', 'l', 'i', 'k', '[P]', ' ', 'b', '[P]', '[P]', 's', '!'] -> I like bees!
['N', '[P]'] -> 'N'
['#', '5', '0', 'K', '0', '0', '1', '[D]', '#', 'n', 'o', 't'] -> '#not'
['H', 'o', 'w', ' ', '[D]', 'H', 'e', 'y'] -> 'Hey'
['s', 'u', 'd', '[B]', 'p', '[C]', '[D]', 'I', ' ' , 'h', 'a', 'v', 'e', ' ', '[P]', 'p', 'e', 'r', '!'] -> 'I have supper!'
</code>```

This is code-golf, so shortest code in bytes wins!

Body:
Perl, <s>53</s> 50 bytes

Includes +1 for -p

Give input on STDIN terminated by newlines (the last newline may be left out, so it counts as a string separated by newlines):

keystrokes.pl
H
e
[C]
[D]
a
b
[B]
[P]
z
^D

gives

aHez

keystrokes.pl:

#!/usr/bin/perl -p
$\.=/^.$/?$&:/P/?$a:(/C/?$a=$\:chop($\x=/B/))x0}{

Almost caught the Jelly answer but the fiend escaped to 48 bytes...