答:
Java, 372 bytes

```<code>import static java.lang.System.*;class A{public static void main(String[]v){String l=" ",s=console().readLine()+l+console().readLine();Integer i=0,n[]=new Integer[4],y;for(;i<4;i++)n[i]=i.parseInt(s.replaceAll("[A-Z] *",l).split(l)[i])*(s.replaceAll("\\d| ","").charAt(i)==(i%2<1?83:87)?1:-1);i=n[0]+n[2];y=n[1]+n[3];out.println((i<0?-i+"N":i+"S")+l+(y<0?-y+"E":y+"W"));}}
</code>```

Ungolfed

```<code>import static java.lang.System.console;
import static java.lang.System.out;

class A {
    public static void main(String[] v) {
        String l = " ", s = console().readLine() + l + console().readLine();
        Integer i = 0, n[] = new Integer[4], y;
        for (; i < 4; i++)
            n[i] = i.parseInt(s.replaceAll("[A-Z] *", l).split(l)[i]) * (s.replaceAll("\\d| ", "").charAt(i) == (i % 2 < 1 ? 83 : 87) ? 1 : -1);
        i = n[0] + n[2];
        y = n[1] + n[3];
        out.println((i < 0 ? -i + "N" : i + "S") + l + (y < 0 ? -y + "E" : y + "W"));
    }
}
</code>```

Notes

Save as A.java, compile with javac A.java, run with java A. Then enter the inputs line separated or as two separate inputs on stdin.

Outputs:

```<code>0S 0E
0S 0W
0S 0W

0S 9999E
9999N 9999W
9999N 0W

42S 314W
42N 2718W
0S 3032W

5555N 8888W
7777S 0E
2222S 8888W

0001N        4545W
0999N        5454W
1000N 9999W

8888N 8888W
9999N 9999W
18887N 18887W
</code>```

Title: Traveling on a flat Earth

Body:
Coordinates in the flat-Earth world consist of latitude (x) and longitude (y), which are integers in the range 0...9999. Much like Gaussian integers, but they are always written using this notation:

```<code>411S 370E
</code>```

That is, with S or N appended to the latitude, and E or W appended to the longitude, with space(s) between the two components.

Goal

Write a program (not a function) that reads two coordinates, separated by whitespace, and outputs their sum. The first coordinate is a starting point, the second one is a displacement, and the output is the resulting position.

Input/Output

Since this challenge is partially about formatting, I'll try to define the input and output formats unambiguously.

The preferred input format has 1 space between the coordinate components, no leading zeros, and a newline character between the two coordinates. The program must be able to read the preferred format.

The output can contain any amount of whitespace and leading zeros. If it's different from the preferred input format, the program must be able to read this format too.

Just to make it clear, the input cannot (will not) contain any additional formatting characters. Just spaces and newlines where needed.

Scoring

This is an experiment on a new winning condition. I'll choose the winner by accepting an answer in a few weeks. If a better answer appears afterwards, I'll change the accepted answer.

The score for the program is its byte count. The winning program is one that is shorter than 400 bytes, has the fewest byte count, but is written in the most verbose programming language. To determine the winner:

Remove programs with byte count 400 or more (they can participate but cannot win)

Consider only the shortest program for each programming language

The longest program wins

Polyglots compete against programs in all languages in which they are valid (e.g. if a program is valid in both bash and sh, it competes against programs in both languages).

Test cases

In the test cases, the first two lines are the input, and the third line is the output.

```<code>0S 0E
0S 0W
0N 0E
</code>```

(the direction of zero doesn't matter, both in input and output)

```<code>0S 9999E
9999N 9999W
9999N 0E
</code>```

(maximal values)

```<code>42S 314W
42N 2718W
0N 3032W
</code>```

(the direction of zero doesn't matter in the output)

```<code>5555N 8888W
7777S 0E
2222S 8888W
</code>```

(no negative values; change the direction if you need to change the sign)

```<code>0001N        4545W
0999N        5454W
1000N        9999W
</code>```

(if the program outputs leading zeros and several spaces, it must be able to read them; it must also be able to read input that doesn't contain them)

```<code>8888N 8888W
9999N 9999W
</code>```

(invalid input - any behavior is acceptable, including crash and infinite loop)

Body:
Java, 372 bytes

import static java.lang.System.*;class A{public static void main(String[]v){String l=" ",s=console().readLine()+l+console().readLine();Integer i=0,n[]=new Integer[4],y;for(;i<4;i++)n[i]=i.parseInt(s.replaceAll("[A-Z] *",l).split(l)[i])*(s.replaceAll("\\d| ","").charAt(i)==(i%2<1?83:87)?1:-1);i=n[0]+n[2];y=n[1]+n[3];out.println((i<0?-i+"N":i+"S")+l+(y<0?-y+"E":y+"W"));}}

Ungolfed

import static java.lang.System.console;
import static java.lang.System.out;

class A {
    public static void main(String[] v) {
        String l = " ", s = console().readLine() + l + console().readLine();
        Integer i = 0, n[] = new Integer[4], y;
        for (; i < 4; i++)
            n[i] = i.parseInt(s.replaceAll("[A-Z] *", l).split(l)[i]) * (s.replaceAll("\\d| ", "").charAt(i) == (i % 2 < 1 ? 83 : 87) ? 1 : -1);
        i = n[0] + n[2];
        y = n[1] + n[3];
        out.println((i < 0 ? -i + "N" : i + "S") + l + (y < 0 ? -y + "E" : y + "W"));
    }
}

Notes

Save as A.java, compile with javac A.java, run with java A. Then enter the inputs line separated or as two separate inputs on stdin.

Outputs:

0S 0E
0S 0W
0S 0W

0S 9999E
9999N 9999W
9999N 0W

42S 314W
42N 2718W
0S 3032W

5555N 8888W
7777S 0E
2222S 8888W

0001N        4545W
0999N        5454W
1000N 9999W

8888N 8888W
9999N 9999W
18887N 18887W


问:
ASCII piano keyboard
Piano keys are     3 characters wide, and 7 characters tall. However, if every key was 3 charactes wide, there wouldn't be enough room for the black keys. That's why some of the white keys have parts of them cut out. There are 3 types of white keys.

Keys with the right half missing (R):

```<code>____
|  |
|  |
|  |
|  |
|   |
|   |
|___|
</code>```

Keys with the left half missing (L):

```<code> ____
 |  |
 |  |
 |  |
 |  |
|   |
|   |
|___|
</code>```

And keys with the left and right halves missing (M):

```<code> ___
 | |
 | |
 | |
 | |
|   |
|   |
|___|
</code>```

On a real keyboard, the pattern of these goes like this:

```<code>RMLRMML, RMLRMML, RMLRMML...
</code>```

and repeats for a total of 88 keys. Now you can't see it when the keys are shown individually, but when you shove them together, you can see the black keys.

```<code>_________________________________________________________
|  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |
|  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |
|  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |
|  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |
|   |   |   |   |   |   |   |   |   |   |   |   |   |   |
|   |   |   |   |   |   |   |   |   |   |   |   |   |   |
|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
</code>```

Your task

Given a positive integer N, print this ASCII-art of a piano with N white keys. You should be able to handle any N from 1 to 52 inclusive (since real 88-key pianos have 52 white keys). Here is test output from 1 to 8, and after that the pattern increases in a similar fashion.

```<code>1
____
|  |
|  |
|  |
|  |
|   |
|   |
|___|

2
________
|  | | |
|  | | |
|  | | |
|  | | |
|   |   |
|   |   |
|___|___|

3
_____________
|  | | | |  |
|  | | | |  |
|  | | | |  |
|  | | | |  |
|   |   |   |
|   |   |   |
|___|___|___|

4
________________
|  | | | |  |  |
|  | | | |  |  |
|  | | | |  |  |
|  | | | |  |  |
|   |   |   |   |
|   |   |   |   |
|___|___|___|___|

5
____________________
|  | | | |  |  | | |
|  | | | |  |  | | |
|  | | | |  |  | | |
|  | | | |  |  | | |
|   |   |   |   |   |
|   |   |   |   |   |
|___|___|___|___|___|

6
________________________
|  | | | |  |  | | | | |
|  | | | |  |  | | | | |
|  | | | |  |  | | | | |
|  | | | |  |  | | | | |
|   |   |   |   |   |   |
|   |   |   |   |   |   |
|___|___|___|___|___|___|

7
_____________________________
|  | | | |  |  | | | | | |  |
|  | | | |  |  | | | | | |  |
|  | | | |  |  | | | | | |  |
|  | | | |  |  | | | | | |  |
|   |   |   |   |   |   |   |
|   |   |   |   |   |   |   |
|___|___|___|___|___|___|___|

8
________________________________
|  | | | |  |  | | | | | |  |  |
|  | | | |  |  | | | | | |  |  |
|  | | | |  |  | | | | | |  |  |
|  | | | |  |  | | | | | |  |  |
|   |   |   |   |   |   |   |   |
|   |   |   |   |   |   |   |   |
|___|___|___|___|___|___|___|___|
</code>```

And last but not least, here is a full 52 key output:

```<code>_________________________________________________________________________________________________________________________________________________________________________________________________________________
|  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |
|  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |
|  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |
|  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |
|   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
|   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
</code>```

Standard loopholes are banned, and the shortest answer in bytes wins!

答:
C# 1683 bytes

So....after seeing Neil's answer above this is pretty embarrassing, but I'll post it anyway 'cause it took me a while (bless). I used C# to create mine. Inside the "Fncs" class I created an array of the typical order of keys. Then, I created a function which can allow the user to get an appropriate index for this array based on a given integer. In order to edit individual lines, I created a "PianoKeyboard" class which contains a dictionary storing multiple strings representing the individual lines. Finally, I created the "DrawKey" function which appends the appropriate text to the individual lines and the "GetKeys" function which returns the overall string value.

```<code>namespace ASCIIPiano{public enum WhiteKeyType{Left,Middle,Right}public static class Fncs{public static WhiteKeyType[] Order{get{return new WhiteKeyType[]{WhiteKeyType.Left,WhiteKeyType.Middle,WhiteKeyType.Right,WhiteKeyType.Left,WhiteKeyType.Middle,WhiteKeyType.Middle,WhiteKeyType.Right};}}public static PianoKeyboard DrawKey(this PianoKeyboard keyboard, WhiteKeyType type){keyboard.Append(1,"_____");if (type == WhiteKeyType.Left){keyboard.Append( 2,"|  | ");keyboard.Append( 3,"|  | ");keyboard.Append( 4,"|  | ");keyboard.Append( 5, "|  | ");}else if (type == WhiteKeyType.Middle){keyboard.Append(2, " | | ");keyboard.Append(3," | | ");keyboard.Append( 4," | | ");keyboard.Append(5," | | ");}else{keyboard.Append( 2," |  |");keyboard.Append(3, " |  |");keyboard.Append(4," |  |");keyboard.Append(5, " |  |");}keyboard.Append(6,"|   |");keyboard.Append(7,"|   |");keyboard.Append(8,"|___|");return keyboard;}public static int GetWhiteKeyIndex(this int number){return number % 7;}public static string GetKeys(this int quantityofwhitekeys){PianoKeyboard keyboard = new PianoKeyboard();for (int i = 0; i < quantityofwhitekeys; i++){WhiteKeyType key=Fncs.Order[i.GetWhiteKeyIndex()];keyboard.DrawKey(key);}return keyboard.TOTALSTRING;}}public class PianoKeyboard{public PianoKeyboard(){}private Dictionary<int, string> lines = new Dictionary<int, string>();public void Append(int index,string value){if (index > 8 || index < 1){throw new Exception("URGH!");}else{if (lines.Keys.Contains(index)){lines[index] += value;}else{lines.Add(index, value);}}}public string TOTALSTRING{get{string returner = "";foreach (int key in lines.Keys){returner += lines[key] + "\n";}return returner;}}}}
</code>```

ContentLicense: CC BY-SA 3.0

Title: ASCII piano keyboard

Body:
C# 1683 bytes

So....after seeing Neil's answer above this is pretty embarrassing, but I'll post it anyway 'cause it took me a while (bless). I used C# to create mine. Inside the "Fncs" class I created an array of the typical order of keys. Then, I created a function which can allow the user to get an appropriate index for this array based on a given integer. In order to edit individual lines, I created a "PianoKeyboard" class which contains a dictionary storing multiple strings representing the individual lines. Finally, I created the "DrawKey" function which appends the appropriate text to the individual lines and the "GetKeys" function which returns the overall string value.

namespace ASCIIPiano{public enum WhiteKeyType{Left,Middle,Right}public static class Fncs{public static WhiteKeyType[] Order{get{return new WhiteKeyType[]{WhiteKeyType.Left,WhiteKeyType.Middle,WhiteKeyType.Right,WhiteKeyType.Left,WhiteKeyType.Middle,WhiteKeyType.Middle,WhiteKeyType.Right};}}public static PianoKeyboard DrawKey(this PianoKeyboard keyboard, WhiteKeyType type){keyboard.Append(1,"_____");if (type == WhiteKeyType.Left){keyboard.Append( 2,"|  | ");keyboard.Append( 3,"|  | ");keyboard.Append( 4,"|  | ");keyboard.Append( 5, "|  | ");}else if (type == WhiteKeyType.Middle){keyboard.Append(2, " | | ");keyboard.Append(3," | | ");keyboard.Append( 4," | | ");keyboard.Append(5," | | ");}else{keyboard.Append( 2," |  |");keyboard.Append(3, " |  |");keyboard.Append(4," |  |");keyboard.Append(5, " |  |");}keyboard.Append(6,"|   |");keyboard.Append(7,"|   |");keyboard.Append(8,"|___|");return keyboard;}public static int GetWhiteKeyIndex(this int number){return number % 7;}public static string GetKeys(this int quantityofwhitekeys){PianoKeyboard keyboard = new PianoKeyboard();for (int i = 0; i < quantityofwhitekeys; i++){WhiteKeyType key=Fncs.Order[i.GetWhiteKeyIndex()];keyboard.DrawKey(key);}return keyboard.TOTALSTRING;}}public class PianoKeyboard{public PianoKeyboard(){}private Dictionary<int, string> lines = new Dictionary<int, string>();public void Append(int index,string value){if (index > 8 || index < 1){throw new Exception("URGH!");}else{if (lines.Keys.Contains(index)){lines[index] += value;}else{lines.Add(index, value);}}}public string TOTALSTRING{get{string returner = "";foreach (int key in lines.Keys){returner += lines[key] + "\n";}return returner;}}}}


问:
Briefest code to find vowels and print consonants
Challenge: Read a string from user, print number of each vowel, then place all remaining chars in a line. Shortest answer wins!

Output must look like this:

Enter String: Input

Vowel Count: a: #, e: #, i: #, o: #, u: #

Remaining characters: Vowel-less Input

For example:

```<code>Enter String: LoremIpsumDolorSitAmetConsecuteurAdipscingElit!
Vowel Count: a: 0, e: 4, i: 4, o: 4, u: 3
Remaining characters: LrmIpsmDlrStAmtCnsctrAdpscngElt!
</code>```

答:
C++, 449 bytes

Golfed:

#include <iostream>
#include <string>
int main(){std::string x;std::cout<<"Enter String: ",std::cin>>x;int a=0,e=0,i=0,o=0,u=0;for(int c=0;c<x.length();c++){switch(x[c]){case 'a':a++;x.erase(c,1);break;case 'e':e++;x.erase(c,1);break;case 'i':i++;x.erase(c,1);break;case 'o':o++;x.erase(c,1);break;case 'u':u++;x.erase(c,1);break;}}std::cout<<"\n Vowel Count: a: "<<a<<", e: "<<e<<", i: "<<i<<", o: "<<o<<", u: "<<u<<"\n Remaining characters: "<<x;}
```

<h3>Ungolfed:</h3>

<pre class="lang-cpp prettyprint-override"><code>#include <iostream>
#include <string>

int main(){
    std::string x;
    std::cout<<"Enter String: ", std::cin>>x;
    int a=0,e=0,i=0,o=0,u=0;
    for(int c = 0; c < x.length(); c++){
        switch(x[c]){
            case 'a':
                a++;
                x.erase(c,1);
                break;
            case 'e':
                e++;
                x.erase(c,1);
                break;
            case 'i':
                i++;
                x.erase(c,1);
                break;
            case 'o':
                o++;
                x.erase(c,1);
                break;
            case 'u':
                u++;
                x.erase(c,1);
                break;
        }
    }
    std::cout<<"\n Vowel Count: a: "<<a<<", e: "<<e<<", i: "<<i<<", o: "<<o<<", u: "<<u<<"\n Remaining characters: "<<x;
}
</code>```

Body:
C++, 449 bytes

Golfed:

#include <iostream>
#include <string>
int main(){std::string x;std::cout<<"Enter String: ",std::cin>>x;int a=0,e=0,i=0,o=0,u=0;for(int c=0;c<x.length();c++){switch(x[c]){case 'a':a++;x.erase(c,1);break;case 'e':e++;x.erase(c,1);break;case 'i':i++;x.erase(c,1);break;case 'o':o++;x.erase(c,1);break;case 'u':u++;x.erase(c,1);break;}}std::cout<<"\n Vowel Count: a: "<<a<<", e: "<<e<<", i: "<<i<<", o: "<<o<<", u: "<<u<<"\n Remaining characters: "<<x;}

Ungolfed:

#include <iostream>
#include <string>

int main(){
    std::string x;
    std::cout<<"Enter String: ", std::cin>>x;
    int a=0,e=0,i=0,o=0,u=0;
    for(int c = 0; c < x.length(); c++){
        switch(x[c]){
            case 'a':
                a++;
                x.erase(c,1);
                break;
            case 'e':
                e++;
                x.erase(c,1);
                break;
            case 'i':
                i++;
                x.erase(c,1);
                break;
            case 'o':
                o++;
                x.erase(c,1);
                break;
            case 'u':
                u++;
                x.erase(c,1);
                break;
        }
    }
    std::cout<<"\n Vowel Count: a: "<<a<<", e: "<<e<<", i: "<<i<<", o: "<<o<<", u: "<<u<<"\n Remaining characters: "<<x;
}


问:
Showcase of Languages

Notes

This thread is open and unlocked only because the community decided to make an exception. Please do not use this question as evidence that you can ask similar questions here. Please do not create additional showcase questions.

This is no longer a popularity-contest, nor are snippet lengths limited by the vote tally. If you know this thread from before, please make sure you familiarize yourself with the changes.

This thread is dedicated to showing off interesting, useful, obscure, and/or unique features your favorite programming languages have to offer. This is neither a challenge nor a competition, but a collaboration effort to showcase as many programming languages as possible as well as possible.

How this works

All answers should include the name of the programming language at the top of the post, prefixed by a #.

Answers may contain one (and only one) factoid, i.e., a couple of sentences without code that describe the language.

Aside from the factoid, answers should consist of snippets of code, which can (but don't have to be) programs or functions.

The snippets do not need to be related. In fact, snippets that are too related may be redundant.

Since this is not a contest, all programming languages are welcome, whenever they were created.

Answers that contain more than a handful of code snippets should use a Stack Snippet to collapse everything except the factoid and one of the snippets.

Whenever possible, there should be only one answer per programming language. This is a community wiki, so feel free to add snippets to any answer, even if you haven't created it yourself. There is a Stack Snippet for compressing posts, which should mitigate the effect of the 30,000 character limit.

Answers that predate these guidelines should be edited. Please help updating them as needed.

Current answers, sorted alphabetically by language name

$.ajax({type:"GET",url:"https://api.stackexchange.com/2.2/questions/44680/answers?site=codegolf&filter=withbody",success:function(data){for(var i=0;i<data.items.length;i++){var temp=document.createElement('p');temp.innerHTML = data.items[i].body.split("\n")[0];$('#list').append('
' + temp.innerText || temp.textContent + '');}}})```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><base href="http://codegolf.stackexchange.com"><ul id="list"></ul></code>```

答:
GNU Octave

Snippet 7:

```<code>disp(j)
 0 + 1i
</code>```

Prints j out to the screen without the ans = overhead

Snippet 6:

```<code>[i](1)
ans =  0 + 1i
</code>```

This generates an instance of a scalar only containing sqrt(-1), takes the first element of it (a complex number), and prints it out. A scalar is basically an array.

Snippet 3:

```<code>{3}
ans =
{
  [1,1] =  3
}
</code>```

This generates an instance of a matrix with one entry, 3.

Snippet 2:

```<code>[]
ans = [](0x0)
</code>```

This is just a simple empty array.

Snippet 1:

```<code>j
ans =  0 + 1i
</code>```

Yes, Octave understands i or j as the square root of -1!

Factoid: Octave is free and approximately 80% compatible with Matlab! (except toolboxes)

Title: Showcase of Languages

Body:
GNU Octave

Snippet 7:

disp(j)
 0 + 1i

Prints j out to the screen without the ans = overhead

Snippet 6:

[i](1)
ans =  0 + 1i

This generates an instance of a scalar only containing sqrt(-1), takes the first element of it (a complex number), and prints it out. A scalar is basically an array.

Snippet 3:

{3}
ans =
{
  [1,1] =  3
}

This generates an instance of a matrix with one entry, 3.

Snippet 2:

[]
ans = [](0x0)

This is just a simple empty array.

Snippet 1:

j
ans =  0 + 1i

Yes, Octave understands i or j as the square root of -1!

Factoid: Octave is free and approximately 80% compatible with Matlab! (except toolboxes)


答:
Pyth, <s>68</s> <s>65</s> 63 bytes

```<code>*lJ:+\|s@Lj;*L" |"_j4536 7*4Q" $"k\_jb+*4]J*2]K+\|*Q"   |":Kd\_
</code>```

Try it online!

Test suite.

In this version, I just substituted the assignments (J and K) inside to save 2 bytes. Therefore, read the version below.

Previous 65-byte version with explanation

```<code>J:+\|s@Lj;*L" |"_j4536 7*4Q" $"kK+\|*Q"   |"*lJ\_jb+*4]J*2]K:Kd\_
</code>```

Try it online!

```<code>J:+\|s@Lj;*L" |"_j4536 7*4Q" $"k    This part generates the most irregular line.

        j;*L" |"_j4536 7            Generate the whole line by black magic
      @L                *4Q         Get the first (4*input) characters of it, with wrapping.
  +\|                               Add "|" in front of it (we took away the first "|")
 :                         " $"k    Replace the ending space by nothing
J                                   Store the line to J.

K+\|*Q"   |"      This part generates the line just below the irregular line.
    *Q"   |"      Repeat "   |" input times
 +\|              Prepend "|"
K                 Store to K

*lJ\_     Now we can actually start printing

*  \_     Repeat "_" ...
 lJ                      [the length of J] times
          (and implicitly print it out)

jb+*4]J*2]K

   *4]J             Repeat J 4 times
       *2]K         Repeat K 2 times
  +                 Concatenate them together
jb                  Join with newlines
                    (and implicitly print it out)

:Kd\_

:K      Replace in K
  d                  " "
   \_                    by "_"
        (and implicitly print it out)
</code>```

Black magic

```<code>We find the irregular line from input=7, and cut out the first "|":
"  | | | |  |  | | | | | |  |"
 2  1 1 1 2  2  1 1 1 1 1 2

j;*L" |"_j4536 7    Black magic.

         j4536 7    4536 converted to base 7: [1,6,1,4,0]
        _           Reverse: [0,4,1,6,1]
  *L" |"            Repeat " |" <each element> times:
                    [""," | | | |"," |"," | | | | | |"," |"]
j;                  Join by whitespace:
                    "  | | | |  |  | | | | | |  |"
</code>```

Title: ASCII piano keyboard

Body:
Piano keys are     3 characters wide, and 7 characters tall. However, if every key was 3 charactes wide, there wouldn't be enough room for the black keys. That's why some of the white keys have parts of them cut out. There are 3 types of white keys.

Keys with the right half missing (R):

```<code>____
|  |
|  |
|  |
|  |
|   |
|   |
|___|
</code>```

Keys with the left half missing (L):

```<code> ____
 |  |
 |  |
 |  |
 |  |
|   |
|   |
|___|
</code>```

And keys with the left and right halves missing (M):

```<code> ___
 | |
 | |
 | |
 | |
|   |
|   |
|___|
</code>```

On a real keyboard, the pattern of these goes like this:

```<code>RMLRMML, RMLRMML, RMLRMML...
</code>```

and repeats for a total of 88 keys. Now you can't see it when the keys are shown individually, but when you shove them together, you can see the black keys.

```<code>_________________________________________________________
|  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |
|  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |
|  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |
|  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |
|   |   |   |   |   |   |   |   |   |   |   |   |   |   |
|   |   |   |   |   |   |   |   |   |   |   |   |   |   |
|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
</code>```

Your task

Given a positive integer N, print this ASCII-art of a piano with N white keys. You should be able to handle any N from 1 to 52 inclusive (since real 88-key pianos have 52 white keys). Here is test output from 1 to 8, and after that the pattern increases in a similar fashion.

```<code>1
____
|  |
|  |
|  |
|  |
|   |
|   |
|___|

2
________
|  | | |
|  | | |
|  | | |
|  | | |
|   |   |
|   |   |
|___|___|

3
_____________
|  | | | |  |
|  | | | |  |
|  | | | |  |
|  | | | |  |
|   |   |   |
|   |   |   |
|___|___|___|

4
________________
|  | | | |  |  |
|  | | | |  |  |
|  | | | |  |  |
|  | | | |  |  |
|   |   |   |   |
|   |   |   |   |
|___|___|___|___|

5
____________________
|  | | | |  |  | | |
|  | | | |  |  | | |
|  | | | |  |  | | |
|  | | | |  |  | | |
|   |   |   |   |   |
|   |   |   |   |   |
|___|___|___|___|___|

6
________________________
|  | | | |  |  | | | | |
|  | | | |  |  | | | | |
|  | | | |  |  | | | | |
|  | | | |  |  | | | | |
|   |   |   |   |   |   |
|   |   |   |   |   |   |
|___|___|___|___|___|___|

7
_____________________________
|  | | | |  |  | | | | | |  |
|  | | | |  |  | | | | | |  |
|  | | | |  |  | | | | | |  |
|  | | | |  |  | | | | | |  |
|   |   |   |   |   |   |   |
|   |   |   |   |   |   |   |
|___|___|___|___|___|___|___|

8
________________________________
|  | | | |  |  | | | | | |  |  |
|  | | | |  |  | | | | | |  |  |
|  | | | |  |  | | | | | |  |  |
|  | | | |  |  | | | | | |  |  |
|   |   |   |   |   |   |   |   |
|   |   |   |   |   |   |   |   |
|___|___|___|___|___|___|___|___|
</code>```

And last but not least, here is a full 52 key output:

```<code>_________________________________________________________________________________________________________________________________________________________________________________________________________________
|  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |
|  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |
|  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |
|  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | | | |  |
|   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
|   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
</code>```

Standard loopholes are banned, and the shortest answer in bytes wins!

Body:
Pyth, <s>68</s> <s>65</s> 63 bytes

*lJ:+\|s@Lj;*L" |"_j4536 7*4Q" $"k\_jb+*4]J*2]K+\|*Q"   |":Kd\_

Try it online!

Test suite.

In this version, I just substituted the assignments (J and K) inside to save 2 bytes. Therefore, read the version below.

Previous 65-byte version with explanation

J:+\|s@Lj;*L" |"_j4536 7*4Q" $"kK+\|*Q"   |"*lJ\_jb+*4]J*2]K:Kd\_

Try it online!

J:+\|s@Lj;*L" |"_j4536 7*4Q" $"k    This part generates the most irregular line.

        j;*L" |"_j4536 7            Generate the whole line by black magic
      @L                *4Q         Get the first (4*input) characters of it, with wrapping.
  +\|                               Add "|" in front of it (we took away the first "|")
 :                         " $"k    Replace the ending space by nothing
J                                   Store the line to J.

K+\|*Q"   |"      This part generates the line just below the irregular line.
    *Q"   |"      Repeat "   |" input times
 +\|              Prepend "|"
K                 Store to K

*lJ\_     Now we can actually start printing

*  \_     Repeat "_" ...
 lJ                      [the length of J] times
          (and implicitly print it out)

jb+*4]J*2]K

   *4]J             Repeat J 4 times
       *2]K         Repeat K 2 times
  +                 Concatenate them together
jb                  Join with newlines
                    (and implicitly print it out)

:Kd\_

:K      Replace in K
  d                  " "
   \_                    by "_"
        (and implicitly print it out)

Black magic

We find the irregular line from input=7, and cut out the first "|":
"  | | | |  |  | | | | | |  |"
 2  1 1 1 2  2  1 1 1 1 1 2

j;*L" |"_j4536 7    Black magic.

         j4536 7    4536 converted to base 7: [1,6,1,4,0]
        _           Reverse: [0,4,1,6,1]
  *L" |"            Repeat " |" <each element> times:
                    [""," | | | |"," |"," | | | | | |"," |"]
j;                  Join by whitespace:
                    "  | | | |  |  | | | | | |  |"


答:
Python, 168 bytes

```<code>s=input('Enter String:')
v='aeiou'
print('Vowel Count: '+', '.join([a+':'+str(s.count(a)) for a in v])+'\nRemaining characters: '+''.join([a for a in s if a not in v]))
</code>```

https://repl.it/CMzO/1

Title: Briefest code to find vowels and print consonants

Body:
Challenge: Read a string from user, print number of each vowel, then place all remaining chars in a line. Shortest answer wins!

Output must look like this:

Enter String: Input

Vowel Count: a: #, e: #, i: #, o: #, u: #

Remaining characters: Vowel-less Input

For example:

```<code>Enter String: LoremIpsumDolorSitAmetConsecuteurAdipscingElit!
Vowel Count: a: 0, e: 4, i: 4, o: 4, u: 3
Remaining characters: LrmIpsmDlrStAmtCnsctrAdpscngElt!
</code>```

Body:
Python, 168 bytes

s=input('Enter String:')
v='aeiou'
print('Vowel Count: '+', '.join([a+':'+str(s.count(a)) for a in v])+'\nRemaining characters: '+''.join([a for a in s if a not in v]))

https://repl.it/CMzO/1


问:
Golf the K-means algorithm
K-means is a standard unsupervised clustering algorithm, which, given a set of "points" and a number of clusters K, will assign each "point" to one of K clusters.

Pseudo-Code of K-means

Note that there are many variants of K-means. You have to implement the algorithm I am describing below. You may have some variation on the algorithm or use built-ins as long as you would get the same result as this algorithm given the same initial points.

In this challenge, all inputs will be points on the 2D plane (each point is represented by its coordinates in x and y).

```<code>Inputs: K, the number of clusters
        P, the set of points

Choose K points of P uniformly at random
Each chosen point is the initial centroid of its cluster

Loop:
     For each point in P:
         Assign to the cluster whose centroid is the nearest (Euclidean distance)
         In case of a tie, any of the tied cluster can be chosen

     Recompute the centroid of each cluster:
         Its x coordinate is the average of all x's of the points in the cluster
         Its y coordinate is the average of all y's of the points in the cluster

Until the clusters don't change from one iteration to the next

Output: the set of clusters
</code>```

Inputs and Outputs

You may take K and P through STDIN, or as a function argument, etc.

P and the points in P can be represented using any structure that is natural for set/lists in your language of choice.

K is a strictly positive integer.

You may assume that inputs are valid.

There will always be at least K points in P.

You may output the clusters to STDOUT, return them from a function, etc.

The ordering of the clusters and the ordering inside the clusters is unimportant.
-You can either return groups of points to represent clusters, or each point labeled with an identifier for the cluster (e.g. an integer).

Test cases

Since the resulting clusters depend on which points were initially chosen, you may not all get the same results (or the same result each time you run your code).

Therefore, only take the output as an example output.

```<code>Input:
  K = 1
  P = [[1,2.5]]
Output:
  [[[1,2.5]]]

Input:
  K = 3
  P = [[4,8], [15,16], [23,42], [-13.37,-12.1], [666,-666]]
Output:
  [[[666,-666]],[[-13.37,-12.1],[4,8]],[[15,16],[23,42]]]

Input:
  K = 2
  P = [[1,1], [1,1], [1,1]]
Output:
  [[[1,1]],[[1,1],[1,1]]]
</code>```

Scoring

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

答:
C++, <s>479</s> 474 bytes

Only ~20x as much as Matlab!

Golfed

#define V vector

#define f float
struct P{f x,y,i=0;f d(P&p){return(p.x-x)*(p.x-x)+(p.y-y)*(p.y-y);}f n(P&p){return i?x/=i,y/=i,d(p):x=p.x,y=p.y,0;}f a(P&p){x+=p.x,y+=p.y,i++;}};P z;int l(P a,P b){return a.d(z)<b.d(z);}f m(f k,V&p){f s=p.size(),i,j=0,t=1;V c(k),n=c,d;for(random_shuffle(p.begin(),p.end());j<k;c[j].i=j++)c[j]=p[j];for(;t;c=n,n=V(k)){for(i=0;i<s;i++)d=c,z=p[i],sort(d.begin(),d.end(),l),j=d[0].i,p[i].i=j,n[j].a(p[i]);for(j=t=0;j<k;j++)t+=n[j].n(c[j]);}}
```

<p>The input/output to the algorithm is a set of points (<code>struct P</code>) with <code>x</code> and <code>y</code>; and the output is the same set, with their <code>i</code>'s set to indicate the index of the output cluster that the point ends in. </p>

<p>That extra <code>i</code> is also used to identify the clusters. In the main loop, the closest centroid to each point is found by sorting a copy of the current centroids by proximity to that point.</p>

<p>This handles degenerate cases (empty clusters) by keeping the corresponding centroids' previous position (see definition of <code>P::n</code>, which also returns distance-to-previous-centroid). A few chars could be saved by assuming that these will not crop up.</p>

<p><strong>Ungolfed, with main</strong></p>

<pre class="lang-c++ prettyprint-override"><code>#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;

#define V vector<P>
#define f float
struct P{
    f x,y,i=0;
    f d(P&p){return(p.x-x)*(p.x-x)+(p.y-y)*(p.y-y);} // distance squared
    f n(P&p){return i?x/=i,y/=i,d(p):x=p.x,y=p.y,0;} // normalize-or-reset
    f a(P&p){x+=p.x,y+=p.y,i++;}                     // add coordinates
};
P z;int l(P a,P b){return a.d(z)<b.d(z);}            // closer-to-z comparator
f m(f k,V&p){
    f s=p.size(),i,j=0,t=1;V c(k),n=c,d;
    for(random_shuffle(p.begin(),p.end());j<k;c[j].i=j++)
        c[j]=p[j];                                // initial random assignment
    for(;t;c=n,n=V(k)){
        for(i=0;i<s;i++)                          // assign to clusters
            d=c,z=p[i],sort(d.begin(),d.end(),l),
            j=d[0].i,p[i].i=j,n[j].a(p[i]);       // and add those coords
        for(j=t=0;j<k;j++)t+=n[j].n(c[j]);        // normalize & count changes
    }
}

int main(int argc, char **argv) {
    srand((unsigned long)time(0));

    int k;
    V p;
    sscanf(argv[1], "%d", &k);
    printf("Input:\n");
    for (int i=2,j=0; i<argc; i+=2, j++) {
        P n;
        sscanf(argv[i], "%f", &(n.x));
        sscanf(argv[i+1], "%f", &(n.y));
        p.push_back(n);
        printf("%d : %f,%f\n", j, p[j].x, p[j].y);
    }

    m(k,p);
    printf("Clusters:\n");
    for (int q=0; q<k; q++) {
        printf("%d\n", q);
        for (unsigned int i=0; i<p.size(); i++) {
            if (p[i].i == q) printf("\t%f,%f (%d)\n", p[i].x, p[i].y, i);
        }
    }
    return 0;
}
</code>```

Title: Golf the K-means algorithm

Body:
C++, <s>479</s> 474 bytes

Only ~20x as much as Matlab!

Golfed

#define V vector<P>
#define f float
struct P{f x,y,i=0;f d(P&p){return(p.x-x)*(p.x-x)+(p.y-y)*(p.y-y);}f n(P&p){return i?x/=i,y/=i,d(p):x=p.x,y=p.y,0;}f a(P&p){x+=p.x,y+=p.y,i++;}};P z;int l(P a,P b){return a.d(z)<b.d(z);}f m(f k,V&p){f s=p.size(),i,j=0,t=1;V c(k),n=c,d;for(random_shuffle(p.begin(),p.end());j<k;c[j].i=j++)c[j]=p[j];for(;t;c=n,n=V(k)){for(i=0;i<s;i++)d=c,z=p[i],sort(d.begin(),d.end(),l),j=d[0].i,p[i].i=j,n[j].a(p[i]);for(j=t=0;j<k;j++)t+=n[j].n(c[j]);}}

The input/output to the algorithm is a set of points (struct P) with x and y; and the output is the same set, with their i's set to indicate the index of the output cluster that the point ends in.

That extra i is also used to identify the clusters. In the main loop, the closest centroid to each point is found by sorting a copy of the current centroids by proximity to that point.

This handles degenerate cases (empty clusters) by keeping the corresponding centroids' previous position (see definition of P::n, which also returns distance-to-previous-centroid). A few chars could be saved by assuming that these will not crop up.

Ungolfed, with main

#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;

#define V vector<P>
#define f float
struct P{
    f x,y,i=0;
    f d(P&p){return(p.x-x)*(p.x-x)+(p.y-y)*(p.y-y);} // distance squared
    f n(P&p){return i?x/=i,y/=i,d(p):x=p.x,y=p.y,0;} // normalize-or-reset
    f a(P&p){x+=p.x,y+=p.y,i++;}                     // add coordinates
};
P z;int l(P a,P b){return a.d(z)<b.d(z);}            // closer-to-z comparator
f m(f k,V&p){
    f s=p.size(),i,j=0,t=1;V c(k),n=c,d;
    for(random_shuffle(p.begin(),p.end());j<k;c[j].i=j++)
        c[j]=p[j];                                // initial random assignment
    for(;t;c=n,n=V(k)){
        for(i=0;i<s;i++)                          // assign to clusters
            d=c,z=p[i],sort(d.begin(),d.end(),l),
            j=d[0].i,p[i].i=j,n[j].a(p[i]);       // and add those coords
        for(j=t=0;j<k;j++)t+=n[j].n(c[j]);        // normalize & count changes
    }
}

int main(int argc, char **argv) {
    srand((unsigned long)time(0));

    int k;
    V p;
    sscanf(argv[1], "%d", &k);
    printf("Input:\n");
    for (int i=2,j=0; i<argc; i+=2, j++) {
        P n;
        sscanf(argv[i], "%f", &(n.x));
        sscanf(argv[i+1], "%f", &(n.y));
        p.push_back(n);
        printf("%d : %f,%f\n", j, p[j].x, p[j].y);
    }

    m(k,p);
    printf("Clusters:\n");
    for (int q=0; q<k; q++) {
        printf("%d\n", q);
        for (unsigned int i=0; i<p.size(); i++) {
            if (p[i].i == q) printf("\t%f,%f (%d)\n", p[i].x, p[i].y, i);
        }
    }
    return 0;
}


问:
KOTH: Every coin has two sides
Final results available

Introduction

After my previous KOTH with heavy themes (fantasy war, worldwide pandemic...), I'm back with a new lighthearted game. This time, you are facing off in a "board game-like" situation. A pile of upside down coins is placed at the center of a really big table, and you are determined to get your share of the loot!

Glossary

Coins: Tokens that can either be flipped or unflipped.

  Unflipped: Coins placed on the table with their value pointing down. This is the default state of the coins.

  Flipped: Coins placed on the table with their value pointing up.

  Local: Refers to your pile of coins.

  Global: Refers to the pile of coins at the center.

Principle

At the start of the game, each player starts with 0 points and 0 coins (flipped or unflipped). The game is turn-based. During their turn, players can take up to 3 actions interacting either with the pile of coins at the center of the table, their own pile of coins or with other players.

Play order is defined randomly at the start of the game. The order of the players in the argument list represents the turn order, and it goes from left to right in that list. "Next" and "Previous" refer respectively to "on the right in that list" and "on the left in that list" with a loop if you're the last of either side.

The game lasts for 50 rounds or until there are 0 coins at the center at the end of a player turn (meaning that you will finish your 3 actions even if the pile is empty after your first action, and you can put back coins to let the game continue). The starting number of global coins is defined randomly with this formula:

```<code>(2 ^ nb_players) + (nb_players * 10) - random(1 + (nb_players ^ 2))`
</code>```

Each action will get you points (or make you lose some) and at the end of the game, each coin you have will be added to your points (-1 for unflipped, +2 for flipped). The player with the highest score wins.

The controller provides you with input via command arguments, and your program has to output via stdout.

Syntax

Input

Each time your program is called, it will receive arguments in this format:

Round;YourPlayerId;Coins;PlayerId_Points_Flipped_Unflipped;PlayerId_Points_Flipped_Unflipped;...

Rounds are 1-indexed.

Example input

6;2;52;1_20_3_12;0_-2_0_1;2_12_1_0

Here, you see it is the 6th round and you are player 2. There are 52 coins in the central pile. You have 12 points, 1 flipped coin and 0 unflipped coin. Points can be negative.

Output

You have to output three characters (no space, no separator), which each correspond to one action you'll take this turn. The order of the characters determine the order of the actions. You can output the same actions multiple times. In case there is not enough coins to complete your action, it will use the maximum of available coins and count points only for the coins used.

N: Do Nothing

1: Take 1 coin from the central pile [Effects: +1 local unflipped / -1 point / -1 global unflipped]

2: Take 2 coins from the central pile [Effects: +2 local unflipped / -2 points / -2 global unflipped]

3: Take 3 coins from the central pile [Effects: +3 local unflipped / -3 points / -3 global unflipped]

A: Put back 1 coin from your pile [Effects: -1 local unflipped / +1 point / +1 global unflipped]

B: Put back 2 coins from your pile [Effects: -2 local unflipped / +2 points / +2 global unflipped]

C: Put back 3 coins from your pile [Effects: -3 local unflipped / +3 points / +3 global unflipped]

X: Remove 1 coin from your pile [Effects: -1 local unflipped / 0 point]

Y: Remove 2 coins from your pile [Effects: -2 local unflipped / 0 point]

Z: Remove 3 coins from your pile [Effects: -3 local unflipped / 0 point]

R: Rotate coins to previous player [Effects: -1 point per unflipped received, +2 points per flipped received / applies to all players]

T: Rotate coins to next player [Effects: -1 point per unflipped received, +2 points per flipped received / applies to all players]

F: Flip 1 coin [Effects: -1 local unflipped / +1 local flipped / +2 point]

U: Unflip 1 coin [Effects: +1 local unflipped / -1 local flipped / -2 point]

Example output

2FF : Takes two coins and flips two coin, scoring -2 + 2 + 2 = 2 points

If your output is incorrect, controller will assume NNN.

Controller

You can find the controller on GitHub. It also contains two samplebots, written in Java.
To make it run, check out the project and open it in your Java IDE. The entry point in the main method of the class Game. Java 8 required.

To add bots, first you need either the compiled version for Java (.class files) or the sources for interpreted languages. Place them in the root folder of the project. Then, create a new Java class in the players package (you can take example on the already existing bots). This class must implement Player to override the method String getCmd(). The String returned is the shell command to run your bots. You can for example make a Ruby bot work with this command : return "C:\Ruby\bin\ruby.exe MyBot.rb";. Finally, add the bot in the players array at the top of the Game class.

Rules

Bots should not be written to beat or support specific other bots.

Writing to files is allowed. Please write to"yoursubmissionname.txt", the folder will be emptied before a game starts. Other external resources are disallowed.

Your submission has 1 second to respond.

Provide commands to compile and run your submissions.

Supported Languages

I'll try and support every language, but it needs to be available online for free. Please provide instructions for installation if you're not using a "mainstream" language.

As of right now, I can run : Java 6-7-8, PHP, Ruby, Perl, Python 2-3, Lua, R, node.js, Haskell, Kotlin, C++ 11.

Final results

These are the results of 100 games (points are added up) :

```<code>1. BirdInTheHand: 1017790
2. Balance: 851428
3. SecondBest: 802316
4. Crook: 739080
5. Jim: 723440
6. Flipper: 613290
7. Wheeler: 585516
8. Oracle: 574916
9. SimpleBot: 543665
10. TraderBot: 538160
11. EgoisticalBot: 529567
12. RememberMe: 497513
13. PassiveBot: 494441
14. TheJanitor: 474069
15. GreedyRotation: 447057
16. Devil: 79212
17. Saboteur: 62240
</code>```

Individual results of the games are available here : http://pasted.co/63f1e924 (with starting coins and number of rounds per game).

A bounty of 50 reputations is awarded to the winner : Bird In The Hand by Martin Büttner.

Thank you all for your participation, see you next KOTH~

答:
Wheeler

Wheeler calculated the best possible move for it when rotating the coins.

```<code>import java.util.ArrayList;
import java.util.List;

public class Wheeler {

String[] actions = {"TTT", "TTR", "TRR", "TRT", "RRR", "RRT", "RTR", "RTT"};
String paramString;

class Player{
    private int id;
    private int points;
    private int flip;
    private int unflip;

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public int getPoints() {
        return points;
    }
    public void setPoints(int points) {
        this.points = points;
    }
    public int getFlip() {
        return flip;
    }
    public void setFlip(int flip) {
        this.flip = flip;
    }
    public int getUnflip() {
        return unflip;
    }
    public void setUnflip(int unflip) {
        this.unflip = unflip;
    }
    @Override
    public String toString() {
        return "Player [id=" + id + ", points=" + points + ", flip=" + flip + ", unflip=" + unflip + "]";
    }

}

int round;
int coins;
int otherMaxPoints = 0;
Player myself = new Player();
List<Player> players = new ArrayList<>();

public static void main (String[] s){
    new Wheeler().play(s);
}

private void play(String[] s){
    paramString = s[0];
    reset();
    System.out.println(action());
}

private int rotateNext(){
    int flip, unflip, nflip, nunflip;
    flip = players.get(0).getFlip();
    unflip = players.get(0).getUnflip();
    for (int i = 0; i < players.size(); i++){
        int next = i + 1 <= players.size() - 1 ? i + 1 : 0;
        nflip = players.get(next).getFlip();
        nunflip = players.get(next).getUnflip();
        players.get(next).setFlip(flip);
        players.get(next).setUnflip(unflip);
        players.get(next).setPoints(players.get(next).getPoints() + 2 * flip - unflip);
        flip = nflip;
        unflip = nunflip;
    }
    return myself.getPoints();
}

private int rotatePrev(){
    int flip, unflip,  nflip, nunflip;
    flip = players.get(players.size() -1).getFlip();
    unflip = players.get(players.size() -1).getUnflip();
    for (int i = players.size() -1; i > 0; i--){
        int prev = i - 1 >= 0 ? i - 1 : players.size() - 1;
        nflip = players.get(prev).getFlip();
        nunflip = players.get(prev).getUnflip();
        players.get(prev).setFlip(flip);
        players.get(prev).setUnflip(unflip);
        players.get(prev).setPoints(players.get(prev).getPoints() + 2 * flip - unflip);
        flip = nflip;
        unflip = nunflip;
    }
    return myself.getPoints();
}

private String action() {
    int maxPoints = myself.getPoints();
    String action = "1F2";
    for (String s : actions){
        int cPoints = 0;
        for (char c : s.toCharArray()){
            if (c == 'T'){
                cPoints += rotateNext();
            } else {
                cPoints += rotatePrev();
            }
        }
        if (cPoints > maxPoints){
            action = s;
        }
        reset();
    }
    return action;
}

private void reset(){
    players = new ArrayList<>();
    String[] ps = paramString.split(";");
    round = Integer.parseInt(ps[0]);
    myself.setId(Integer.parseInt(ps[1]));
    coins = round = Integer.parseInt(ps[2]);
    for (int i = 3; i < ps.length; i++){
        String[] sp2 = ps[i].split("_");
        if (Integer.parseInt(sp2[0]) == myself.getId()){
            myself.setPoints(Integer.parseInt(sp2[1]));
            myself.setFlip(Integer.parseInt(sp2[2]));
            myself.setUnflip(Integer.parseInt(sp2[3]));
            players.add(myself);
        } else {
            Player p = new Player();
            p.setId(Integer.parseInt(sp2[0]));
            p.setPoints(Integer.parseInt(sp2[1]));
            p.setFlip(Integer.parseInt(sp2[2]));
            p.setUnflip(Integer.parseInt(sp2[3]));
            players.add(p);
            if (p.getPoints() > otherMaxPoints){
                otherMaxPoints = p.getPoints();
            }
        }
    }
}

}
</code>```

Title: KOTH: Every coin has two sides

Body:
Wheeler

Wheeler calculated the best possible move for it when rotating the coins.

import java.util.ArrayList;
import java.util.List;

public class Wheeler {

String[] actions = {"TTT", "TTR", "TRR", "TRT", "RRR", "RRT", "RTR", "RTT"};
String paramString;

class Player{
    private int id;
    private int points;
    private int flip;
    private int unflip;

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public int getPoints() {
        return points;
    }
    public void setPoints(int points) {
        this.points = points;
    }
    public int getFlip() {
        return flip;
    }
    public void setFlip(int flip) {
        this.flip = flip;
    }
    public int getUnflip() {
        return unflip;
    }
    public void setUnflip(int unflip) {
        this.unflip = unflip;
    }
    @Override
    public String toString() {
        return "Player [id=" + id + ", points=" + points + ", flip=" + flip + ", unflip=" + unflip + "]";
    }

}

int round;
int coins;
int otherMaxPoints = 0;
Player myself = new Player();
List<Player> players = new ArrayList<>();

public static void main (String[] s){
    new Wheeler().play(s);
}

private void play(String[] s){
    paramString = s[0];
    reset();
    System.out.println(action());
}

private int rotateNext(){
    int flip, unflip, nflip, nunflip;
    flip = players.get(0).getFlip();
    unflip = players.get(0).getUnflip();
    for (int i = 0; i < players.size(); i++){
        int next = i + 1 <= players.size() - 1 ? i + 1 : 0;
        nflip = players.get(next).getFlip();
        nunflip = players.get(next).getUnflip();
        players.get(next).setFlip(flip);
        players.get(next).setUnflip(unflip);
        players.get(next).setPoints(players.get(next).getPoints() + 2 * flip - unflip);
        flip = nflip;
        unflip = nunflip;
    }
    return myself.getPoints();
}

private int rotatePrev(){
    int flip, unflip,  nflip, nunflip;
    flip = players.get(players.size() -1).getFlip();
    unflip = players.get(players.size() -1).getUnflip();
    for (int i = players.size() -1; i > 0; i--){
        int prev = i - 1 >= 0 ? i - 1 : players.size() - 1;
        nflip = players.get(prev).getFlip();
        nunflip = players.get(prev).getUnflip();
        players.get(prev).setFlip(flip);
        players.get(prev).setUnflip(unflip);
        players.get(prev).setPoints(players.get(prev).getPoints() + 2 * flip - unflip);
        flip = nflip;
        unflip = nunflip;
    }
    return myself.getPoints();
}

private String action() {
    int maxPoints = myself.getPoints();
    String action = "1F2";
    for (String s : actions){
        int cPoints = 0;
        for (char c : s.toCharArray()){
            if (c == 'T'){
                cPoints += rotateNext();
            } else {
                cPoints += rotatePrev();
            }
        }
        if (cPoints > maxPoints){
            action = s;
        }
        reset();
    }
    return action;
}

private void reset(){
    players = new ArrayList<>();
    String[] ps = paramString.split(";");
    round = Integer.parseInt(ps[0]);
    myself.setId(Integer.parseInt(ps[1]));
    coins = round = Integer.parseInt(ps[2]);
    for (int i = 3; i < ps.length; i++){
        String[] sp2 = ps[i].split("_");
        if (Integer.parseInt(sp2[0]) == myself.getId()){
            myself.setPoints(Integer.parseInt(sp2[1]));
            myself.setFlip(Integer.parseInt(sp2[2]));
            myself.setUnflip(Integer.parseInt(sp2[3]));
            players.add(myself);
        } else {
            Player p = new Player();
            p.setId(Integer.parseInt(sp2[0]));
            p.setPoints(Integer.parseInt(sp2[1]));
            p.setFlip(Integer.parseInt(sp2[2]));
            p.setUnflip(Integer.parseInt(sp2[3]));
            players.add(p);
            if (p.getPoints() > otherMaxPoints){
                otherMaxPoints = p.getPoints();
            }
        }
    }
}

}


问:
Traveling on a flat Earth
Coordinates in the flat-Earth world consist of latitude (x) and longitude (y), which are integers in the range 0...9999. Much like Gaussian integers, but they are always written using this notation:

```<code>411S 370E
</code>```

That is, with S or N appended to the latitude, and E or W appended to the longitude, with space(s) between the two components.

Goal

Write a program (not a function) that reads two coordinates, separated by whitespace, and outputs their sum. The first coordinate is a starting point, the second one is a displacement, and the output is the resulting position.

Input/Output

Since this challenge is partially about formatting, I'll try to define the input and output formats unambiguously.

The preferred input format has 1 space between the coordinate components, no leading zeros, and a newline character between the two coordinates. The program must be able to read the preferred format.

The output can contain any amount of whitespace and leading zeros. If it's different from the preferred input format, the program must be able to read this format too.

Just to make it clear, the input cannot (will not) contain any additional formatting characters. Just spaces and newlines where needed.

Scoring

This is an experiment on a new winning condition. I'll choose the winner by accepting an answer in a few weeks. If a better answer appears afterwards, I'll change the accepted answer.

The score for the program is its byte count. The winning program is one that is shorter than 400 bytes, has the fewest byte count, but is written in the most verbose programming language. To determine the winner:

Remove programs with byte count 400 or more (they can participate but cannot win)

Consider only the shortest program for each programming language

The longest program wins

Polyglots compete against programs in all languages in which they are valid (e.g. if a program is valid in both bash and sh, it competes against programs in both languages).

Test cases

In the test cases, the first two lines are the input, and the third line is the output.

```<code>0S 0E
0S 0W
0N 0E
</code>```

(the direction of zero doesn't matter, both in input and output)

```<code>0S 9999E
9999N 9999W
9999N 0E
</code>```

(maximal values)

```<code>42S 314W
42N 2718W
0N 3032W
</code>```

(the direction of zero doesn't matter in the output)

```<code>5555N 8888W
7777S 0E
2222S 8888W
</code>```

(no negative values; change the direction if you need to change the sign)

```<code>0001N        4545W
0999N        5454W
1000N        9999W
</code>```

(if the program outputs leading zeros and several spaces, it must be able to read them; it must also be able to read input that doesn't contain them)

```<code>8888N 8888W
9999N 9999W
</code>```

(invalid input - any behavior is acceptable, including crash and infinite loop)

Title: Traveling on a flat Earth

Body:
JavaScript (ES6), 118 bytes

s=>(g=([i,j,k,l,m,n],[o,p])=>(i=(j>p?-i:+i)+(n>p?-j:+j))<0?-i+o:i+p)(a=s.match(/\d+|\w/g),"SN")+' '+g(a.slice(2),"WE")


答:
Prolog

Factoid

Prolog is one of the first and most popular logic programming language.

Since Prolog is a declarative language based on first-order logic, programs in it can be surprisingly elegant, or devilishly mindbending.

“In Prolog programming (in contrast, perhaps, to life in general) our goal is to fail as quickly as possible.” — The Art of Prolog

Length 1

```<code>X
</code>```

In Prolog, any identifier that starts with an uppercase letter is a variable, which initially has no value. Unlike most programming languages, variables in Prolog can only take a value once (we say that the variable gets unified with something). After unification, a variable cannot be updated (unless backtracking occurs… more on that later). Variables only get a type once they are unified (the type of what they get unified with), therefore a free variable can be unified with anything.

Length 2

```<code>X.
</code>```

This is a valid query in Prolog. Unlike most languages, in prolog you run queries (like in SQL), and the Prolog execution engine will attempt to satisfy that query. In particular, it will unify variables along the way if those unifications make the query true. Each query ends with a period.

Here however, the query is not really meaningful, since we are asking Prolog to check that a free variable X is true, and it is for an infinite number of different unifications (any integer for instance would make this true). Therefore, here is what SWI-Prolog answers to that query:

```<code>% ... 1,000,000 ............ 10,000,000 years later
%
%       >> 42 << (last release gives the question)
</code>```

Length 3

```<code>nl.
</code>```

In Prolog, any identifier that starts with a lowercase letter is called an atom. They can be used to name predicates, facts, or simply as string-like objects. Here, nl/0 is a predicate which has 0 arguments (hence the /0 notation) and which is a built-in in Prolog. This predicate simply prints a line break to STDOUT:

```<code>?- nl.

true.
</code>```

You can see that Prolog really likes to print true. when it manages to satisfy your query (or false. when it doesn't).

Length 4

```<code>X=0.
</code>```

In Prolog, = is unification. Prolog will satisty this query by unifying X with 0, which is the only possible way of satisfying it.

Length 5

```<code>X=[].
</code>```

In Prolog, the list is a central data structure that you will use constantly. All lists are written in square brackets. A special list that will show up very often (particularly when writing your recursion termination condition) is the empty list, noted [].

Length 6

```<code>X=3+B.
</code>```

Prolog is homoiconic, and as such the above query is perfectly valid. The REPL returns the following:

```<code>X = 3+B.
</code>```

In short, we are unifying variable X with the expression 3+B (which does not get evaluated in any way). If we now unify B with something, this will be reflected in X:

```<code>?- X=3+B, B=5.
X = 3+5,
B = 5.
</code>```

(As you can see, X is not evaluated to 8)

Length 7

```<code>X*X#=4
</code>```

Here I am cheating slightly. To make the above work, you must first run the following query: use_module(library(clpfd)).. This is the constraint logic programming in finite domains (CLPFD) library, which allows us to do very powerful things: for instance, the REPL will return the following for the above query:

```<code>X in -2\/2.
</code>```

\/ represents the union of two domains. Therefore, what Prolog is telling use here is that for X to satisfy X*X = 4 (the # in the query is CLPFD's syntax for constraints), X must be either -2 or 2.

This is a very powerful mechanism that allows to write constraints on variables, without specifying how to find the values that satisfy them. Writing something like a sudoku solver with this library is thus extremely easy: you only have to describe the constraints between cells, and the starting clues. Prolog will then find solutions for you!

Length 8

```<code>X=2;X=9.
</code>```

Prolog is a logic programming language, and as such you expect to be able to use disjunctions. This is exactly what ; (Or) does: X unifies with 2 OR X unifies with 5. When running this in Prolog's REPL, we get the following:

```<code>?- X=3;X=9.
X = 3
</code>```

The REPL halts after printing you this answer, instead of finishing and waiting for a new query. Indeed, Prolog thinks there are other possible answers (and there is one in this case), and so it is waiting to see if you are interested in those. By pressing ;, it will give you another answer:

```<code>?- X=3;X=9.
X = 3 ;
X = 9.
</code>```

which is what we expected to get. Here, Prolog knows there are no other possible answers for what we queried, so it will finish and wait for another query.

The mechanism behind this is called backtracking: when Prolog choses to unify X with 2, it remembers that it made that choice when in fact there are other possibilities (here, unifying X with 9). When we ask for another answer (or if the query had failed after that choice), it will backtrack to the last choice it made and try another one, until no other choice is available.

Length 9

```<code>a(ax+b).
</code>```

Here is a fact, that constitutes your source code. We can make some interesting queries on that fact, to check out Prolog's pattern matching mechanism (remember that identifiers starting with an uppercase letter are free variables):

```<code>?- a(X).
X = ax+b.
</code>```

Cooler:

```<code>?- a(X+b).
X = ax.
</code>```

Even cooler:

```<code>?- a(X+Y).
X = ax,
Y = b.
</code>```

Length 12

```<code>length(L,3).
</code>```

length/2 is a built-in predicate of Prolog which is true if its first argument is a list of length its second argument. Here, we are setting the second argument as a ground integer, and the first as a variable. Thus, we get the following behavior:

```<code>?- length(L,3).
L = [_G1500, _G1503, _G1506].
</code>```

That is, for that query to be true, L must be a list of 3 elements; those elements are _G1500, _G1503 and _G1506 which are variables (those names are internal variable names).

We can also run that predicate with both arguments as variables, and get the following very powerful behavior:

```<code>?- length(L,M).
L = [],
M = 0 ;
L = [_G1512],
M = 1 ;
L = [_G1512, _G1515],
M = 2 ;
L = [_G1512, _G1515, _G1518],
M = 3 ;
L = [_G1512, _G1515, _G1518, _G1521],
M = 4 ;
…
</code>```

Title: Showcase of Languages

Body:
Notes

This thread is open and unlocked only because the community decided to make an exception. Please do not use this question as evidence that you can ask similar questions here. Please do not create additional showcase questions.

This is no longer a popularity-contest, nor are snippet lengths limited by the vote tally. If you know this thread from before, please make sure you familiarize yourself with the changes.

This thread is dedicated to showing off interesting, useful, obscure, and/or unique features your favorite programming languages have to offer. This is neither a challenge nor a competition, but a collaboration effort to showcase as many programming languages as possible as well as possible.

How this works

All answers should include the name of the programming language at the top of the post, prefixed by a #.

Answers may contain one (and only one) factoid, i.e., a couple of sentences without code that describe the language.

Aside from the factoid, answers should consist of snippets of code, which can (but don't have to be) programs or functions.

The snippets do not need to be related. In fact, snippets that are too related may be redundant.

Since this is not a contest, all programming languages are welcome, whenever they were created.

Answers that contain more than a handful of code snippets should use a Stack Snippet to collapse everything except the factoid and one of the snippets.

Whenever possible, there should be only one answer per programming language. This is a community wiki, so feel free to add snippets to any answer, even if you haven't created it yourself. There is a Stack Snippet for compressing posts, which should mitigate the effect of the 30,000 character limit.

Answers that predate these guidelines should be edited. Please help updating them as needed.

Current answers, sorted alphabetically by language name

$.ajax({type:"GET",url:"https://api.stackexchange.com/2.2/questions/44680/answers?site=codegolf&filter=withbody",success:function(data){for(var i=0;i<data.items.length;i++){var temp=document.createElement('p');temp.innerHTML = data.items[i].body.split("\n")[0];$('#list').append('
' + temp.innerText || temp.textContent + '');}}})```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><base href="http://codegolf.stackexchange.com"><ul id="list"></ul></code>```

Body:
Prolog

Factoid

Prolog is one of the first and most popular logic programming language.

Since Prolog is a declarative language based on first-order logic, programs in it can be surprisingly elegant, or devilishly mindbending.

“In Prolog programming (in contrast, perhaps, to life in general) our goal is to fail as quickly as possible.” — The Art of Prolog

Length 1

X

In Prolog, any identifier that starts with an uppercase letter is a variable, which initially has no value. Unlike most programming languages, variables in Prolog can only take a value once (we say that the variable gets unified with something). After unification, a variable cannot be updated (unless backtracking occurs… more on that later). Variables only get a type once they are unified (the type of what they get unified with), therefore a free variable can be unified with anything.

Length 2

X.

This is a valid query in Prolog. Unlike most languages, in prolog you run queries (like in SQL), and the Prolog execution engine will attempt to satisfy that query. In particular, it will unify variables along the way if those unifications make the query true. Each query ends with a period.

Here however, the query is not really meaningful, since we are asking Prolog to check that a free variable X is true, and it is for an infinite number of different unifications (any integer for instance would make this true). Therefore, here is what SWI-Prolog answers to that query:

% ... 1,000,000 ............ 10,000,000 years later
%
%       >> 42 << (last release gives the question)

Length 3

nl.

In Prolog, any identifier that starts with a lowercase letter is called an atom. They can be used to name predicates, facts, or simply as string-like objects. Here, nl/0 is a predicate which has 0 arguments (hence the /0 notation) and which is a built-in in Prolog. This predicate simply prints a line break to STDOUT:

?- nl.

true.

You can see that Prolog really likes to print true. when it manages to satisfy your query (or false. when it doesn't).

Length 4

X=0.

In Prolog, = is unification. Prolog will satisty this query by unifying X with 0, which is the only possible way of satisfying it.

Length 5

X=[].

In Prolog, the list is a central data structure that you will use constantly. All lists are written in square brackets. A special list that will show up very often (particularly when writing your recursion termination condition) is the empty list, noted [].

Length 6

X=3+B.

Prolog is homoiconic, and as such the above query is perfectly valid. The REPL returns the following:

X = 3+B.

In short, we are unifying variable X with the expression 3+B (which does not get evaluated in any way). If we now unify B with something, this will be reflected in X:

?- X=3+B, B=5.
X = 3+5,
B = 5.

(As you can see, X is not evaluated to 8)

Length 7

X*X#=4

Here I am cheating slightly. To make the above work, you must first run the following query: use_module(library(clpfd)).. This is the constraint logic programming in finite domains (CLPFD) library, which allows us to do very powerful things: for instance, the REPL will return the following for the above query:

X in -2\/2.

\/ represents the union of two domains. Therefore, what Prolog is telling use here is that for X to satisfy X*X = 4 (the # in the query is CLPFD's syntax for constraints), X must be either -2 or 2.

This is a very powerful mechanism that allows to write constraints on variables, without specifying how to find the values that satisfy them. Writing something like a sudoku solver with this library is thus extremely easy: you only have to describe the constraints between cells, and the starting clues. Prolog will then find solutions for you!

Length 8

X=2;X=9.

Prolog is a logic programming language, and as such you expect to be able to use disjunctions. This is exactly what ; (Or) does: X unifies with 2 OR X unifies with 5. When running this in Prolog's REPL, we get the following:

?- X=3;X=9.
X = 3

The REPL halts after printing you this answer, instead of finishing and waiting for a new query. Indeed, Prolog thinks there are other possible answers (and there is one in this case), and so it is waiting to see if you are interested in those. By pressing ;, it will give you another answer:

?- X=3;X=9.
X = 3 ;
X = 9.

which is what we expected to get. Here, Prolog knows there are no other possible answers for what we queried, so it will finish and wait for another query.

The mechanism behind this is called backtracking: when Prolog choses to unify X with 2, it remembers that it made that choice when in fact there are other possibilities (here, unifying X with 9). When we ask for another answer (or if the query had failed after that choice), it will backtrack to the last choice it made and try another one, until no other choice is available.

Length 9

a(ax+b).

Here is a fact, that constitutes your source code. We can make some interesting queries on that fact, to check out Prolog's pattern matching mechanism (remember that identifiers starting with an uppercase letter are free variables):

?- a(X).
X = ax+b.

Cooler:

?- a(X+b).
X = ax.

Even cooler:

?- a(X+Y).
X = ax,
Y = b.

Length 12

length(L,3).

length/2 is a built-in predicate of Prolog which is true if its first argument is a list of length its second argument. Here, we are setting the second argument as a ground integer, and the first as a variable. Thus, we get the following behavior:

?- length(L,3).
L = [_G1500, _G1503, _G1506].

That is, for that query to be true, L must be a list of 3 elements; those elements are _G1500, _G1503 and _G1506 which are variables (those names are internal variable names).

We can also run that predicate with both arguments as variables, and get the following very powerful behavior:

?- length(L,M).
L = [],
M = 0 ;
L = [_G1512],
M = 1 ;
L = [_G1512, _G1515],
M = 2 ;
L = [_G1512, _G1515, _G1518],
M = 3 ;
L = [_G1512, _G1515, _G1518, _G1521],
M = 4 ;
…


问:
Compute the Adler-32 checksum

Background

Adler-32 is a 32-bit checksum invented by Mark Adler in 1995 which is part of the widely used zlib library (also developed by Adler). Adler-32 is not as reliable as a 32-bit cyclic redundancy check, but – at least in software  – it is much faster and easier to implement.

Definition

Let B = [b1, ⋯, bn] be a byte array.

The Adler-32 checksum of B is defined as the result of low + 65536 × high, where:

low := ((1 + b1 + ⋯ + bn) mod 65521)

high := (((1 + b1) + (1 + b1 + b2) + ⋯ (1 + b1 + ⋯ + bn)) mod 65521)

Task

Given a byte array as input, compute and return its Adler-32 checksum, abiding to the following.

You can take the input as an array of bytes or integers, or as a string.

In both cases, only bytes corresponding to printable ASCII characters will occur in the input.

You may assume that the length of the input will satisfy 0 < length ≤ 4096.

If you choose to print the output, you may use any positive base up to and including 256.

If you choose unary, make sure interpreter can handle up to 232 - 983056 bytes of output on a machine with 16 GiB of RAM.

Built-ins that compute the Adler-32 checksum are forbidden.

Standard code-golf rules apply.

Test cases

```<code>String:     "Eagles are great!"
Byte array: [69, 97, 103, 108, 101, 115, 32, 97, 114, 101, 32, 103, 114, 101, 97, 116, 33]
Checksum:   918816254

String:     "Programming Puzzles & Code Golf"
Byte array: [80, 114, 111, 103, 114, 97, 109, 109, 105, 110, 103, 32, 80, 117, 122, 122, 108, 101, 115, 32, 38, 32, 67, 111, 100, 101, 32, 71, 111, 108, 102]
Checksum:   3133147946

String:     "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
Byte array: [126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126]
Checksum:   68095937

String:     <1040 question marks>
Byte array: <1040 copies of 63>
Checksum:   2181038080
</code>```

答:
ABAP, 118 bytes

```<code>FORM a TABLES t USING l h.l = 1.LOOP AT t.ADD:t TO l,l TO h.ENDLOOP.l = l MOD 65521 + 65536 * ( h MOD 65521 ).ENDFORM.
</code>```

Ungolfed

```<code>FORM a TABLES t USING l h.
  l = 1.
  LOOP AT t.
    ADD: t TO l,
         l TO h.
  ENDLOOP.
  l = l MOD 65521 + 65536 * ( h MOD 65521 ).
ENDFORM.
</code>```

This is my first try at code golfing, if I did anything wrong please let me know! I used ABAP because that's my main programming language. Now for the explanation:

```<code>FORM a TABLES t USING l h.
  ...
ENDFORM.
</code>```

This declares the function "a" with the inputs t, l and h. I defined t as a table of integers and filled it with the different numbers from the original post (for test purposes). l and h are defined as DEC variables with length 31 (highest it can go in ABAP). l is also used as the returning variable for the function so I don't have to use an additional variable.

```<code>  LOOP AT t.
    ...
  ENDLOOP.
</code>```

This is a loop over the table t, which is defined as a table with header-line. This means that the table has a header-line which acts as a variable ("t") and it also has a table body ("t[ ]") at the same time. So "LOOP AT t" reads the rows in the table t[ ] (in order) into the header-line t. Header-lines are obsolete but they save quite a bit of bytes over the now used "LOOP AT table INTO variable.".

```<code>    ADD: t TO l,
         l TO h.
</code>```

Within the loop I'm starting a slightly modified version (pretty much just rearranged) of the calculation that Dennis has in his original post. l = low, h = high. I'm adding the current value in the table to the variable l (which i define to start at 1 in the line "l = 1."). Each step in the loop I'm also adding l to h.
I use "ADD" because ABAP doesn't have "l += t" and using the code above is shorter than:

```<code>l = l + t.
h = h + l.
</code>```

After the loop we have the following:

l = (1 + b1 + ⋯ + bn)

h = ((1 + b1) + (1 + b1 + b2) + ⋯ (1 + b1 + ⋯ + bn))

At the end I'm doing the final calculation:

```<code>  l = l MOD 65521 + 65536 * ( h MOD 65521 ).
</code>```

Sadly you need spaces between the operators and numbers/variables because ABAP uses the operators without spaces for different things. For example:

```<code>char+4 = 'A'.
</code>```

This sets the 5th character (because the offset is set as "4") of the character variable "char" as 'A'. So if "char" was "BBBBB" before that line, it would be "BBBBA" after.

I hope this explanation isn't too long (which I think it is, since the code is really straight forward). ABAP doesn't have bitwise operations AFAIK so I couldn't use a shorter algorithm but I think 118 bytes is still pretty good.

Here's the full program in case anyone can and wants to test it:

```<code>REPORT z_adler_checksum.

DATA:
  lt_i TYPE TABLE OF i WITH HEADER LINE, "Input table
  l_l  TYPE zz, "Calculation and return variable
  l_h  TYPE zz. "Calculation variable

DO 1040 TIMES. "Filling the table for the last test case in the original post
  APPEND 63 TO lt_i.
ENDDO.

PERFORM a TABLES lt_i USING l_l l_h. "Calling the function

WRITE l_l. "Output of the result

FORM a TABLES t USING l h.
  l = 1.
  LOOP AT t.
    ADD: t TO l,
         l TO h.
  ENDLOOP.
  l = l MOD 65521 + 65536 * ( h MOD 65521 ).
ENDFORM.
</code>```

Title: Compute the Adler-32 checksum

Body:
ABAP, 118 bytes

FORM a TABLES t USING l h.l = 1.LOOP AT t.ADD:t TO l,l TO h.ENDLOOP.l = l MOD 65521 + 65536 * ( h MOD 65521 ).ENDFORM.

Ungolfed

FORM a TABLES t USING l h.
  l = 1.
  LOOP AT t.
    ADD: t TO l,
         l TO h.
  ENDLOOP.
  l = l MOD 65521 + 65536 * ( h MOD 65521 ).
ENDFORM.

This is my first try at code golfing, if I did anything wrong please let me know! I used ABAP because that's my main programming language. Now for the explanation:

FORM a TABLES t USING l h.
  ...
ENDFORM.

This declares the function "a" with the inputs t, l and h. I defined t as a table of integers and filled it with the different numbers from the original post (for test purposes). l and h are defined as DEC variables with length 31 (highest it can go in ABAP). l is also used as the returning variable for the function so I don't have to use an additional variable.

  LOOP AT t.
    ...
  ENDLOOP.

This is a loop over the table t, which is defined as a table with header-line. This means that the table has a header-line which acts as a variable ("t") and it also has a table body ("t[ ]") at the same time. So "LOOP AT t" reads the rows in the table t[ ] (in order) into the header-line t. Header-lines are obsolete but they save quite a bit of bytes over the now used "LOOP AT table INTO variable.".

    ADD: t TO l,
         l TO h.

Within the loop I'm starting a slightly modified version (pretty much just rearranged) of the calculation that Dennis has in his original post. l = low, h = high. I'm adding the current value in the table to the variable l (which i define to start at 1 in the line "l = 1."). Each step in the loop I'm also adding l to h.
I use "ADD" because ABAP doesn't have "l += t" and using the code above is shorter than:

l = l + t.
h = h + l.

After the loop we have the following:

l = (1 + b1 + ⋯ + bn)

h = ((1 + b1) + (1 + b1 + b2) + ⋯ (1 + b1 + ⋯ + bn))

At the end I'm doing the final calculation:

  l = l MOD 65521 + 65536 * ( h MOD 65521 ).

Sadly you need spaces between the operators and numbers/variables because ABAP uses the operators without spaces for different things. For example:

char+4 = 'A'.

This sets the 5th character (because the offset is set as "4") of the character variable "char" as 'A'. So if "char" was "BBBBB" before that line, it would be "BBBBA" after.

I hope this explanation isn't too long (which I think it is, since the code is really straight forward). ABAP doesn't have bitwise operations AFAIK so I couldn't use a shorter algorithm but I think 118 bytes is still pretty good.

Here's the full program in case anyone can and wants to test it:

REPORT z_adler_checksum.

DATA:
  lt_i TYPE TABLE OF i WITH HEADER LINE, "Input table
  l_l  TYPE zz, "Calculation and return variable
  l_h  TYPE zz. "Calculation variable

DO 1040 TIMES. "Filling the table for the last test case in the original post
  APPEND 63 TO lt_i.
ENDDO.

PERFORM a TABLES lt_i USING l_l l_h. "Calling the function

WRITE l_l. "Output of the result

FORM a TABLES t USING l h.
  l = 1.
  LOOP AT t.
    ADD: t TO l,
         l TO h.
  ENDLOOP.
  l = l MOD 65521 + 65536 * ( h MOD 65521 ).
ENDFORM.


问:
Find the remaining side of the tangential quadrilateral
(Taken from https://en.wikipedia.org/wiki/File:Tangential_quadrilateral.svg)

A tangential quadrilateral (see example above) is a quadrilateral in which a circle can be inscribed.

Your task is to find the possible value of d given a, b, and c.

Specs

a, b, c will all be positive integers.

If no possible value of d exists, output 0.

Scoring

This is code-golf. Shortest solution in bytes wins.

Testcases

```<code>a b c d
3 4 4 3
1 2 3 2
1 5 3 0
</code>```

答:
Jelly, 5 bytes

```<code>_@/»0
</code>```

Try it online! or verify all test cases.

How it works

```<code>_@/»0    Main link. Argument: [a, b, c]

_@/      Reduce by swapped subtraction.
         This computes (a _@ b) _@ c = c - (b - a) = c - b + a.
   »0    Take the maximum of 0 and c - b + a.
</code>```

Body:
Jelly, 5 bytes

_@/»0

Try it online! or verify all test cases.

How it works

_@/»0    Main link. Argument: [a, b, c]

_@/      Reduce by swapped subtraction.
         This computes (a _@ b) _@ c = c - (b - a) = c - b + a.
   »0    Take the maximum of 0 and c - b + a.


问:
Between the Lines

While doodling around on square-ruled paper the other day, I came up with the above negative-space font for digits. In case you haven't spotted it yet, the spaces between the above shapes yield the golden ratio 1.618033988749. In this challenge, your task is to take a number as input and render it exactly as the example above shows.

Here is how these are created: all lines will be on a regular grid, so that the individual digits are made up of a small number of grid cells. Here are the shapes of the 10 digits (we'll ignore the decimal point for this challenge):

Yes, the 7 differs from the golden ratio example at the top. I kinda messed that up. We'll be going with this one.

Notice that each digit is five cells tall, and three cells wide. To render a number, you can imagine placing all its digits next to each other, such that there is exactly one empty column between each pair of digits. For example, taking 319 as input, we'd write:

Notice that we add one leading and trailing empty column. Now we invert the cells:

The output should then be the boundaries of the resulting polygons:

Of course you may generate the result in any other way, as long as the rendered output looks the same.

Input

You may write a program or function, taking input via STDIN (or closest alternative), command-line argument or function argument, as a string, or list of digits. (You can't take a number as that wouldn't allow you to support leading zeros.)

You may assume that there will be no more than 16 digits in the input.

Output

Output may either be displayed on screen or written to a file in a common image format.

You may use both raster and vector graphics.

In either case, the aspect ratio of the cells of the underlying grid needs to be 1 (that is, the cells should be squares).

In the case of raster graphics, each cell should cover at least 20 by 20 pixels.

The lines must be no wider than 10% of the cell size. I'm willing to give one or two pixels leeway due to aliasing here.

Lines and background can be any two clearly distinguishable colours, but the shapes created by the lines must not be filled (that is the insides should be the background colour as well).

There must be no gaps within each closed loop.

Of course, the entire result must be visible.

Test Cases

Here are 10 inputs, which together cover all possible pairs of adjacent digits, as well as every possible leading and trailing digit:

```<code>07299361548
19887620534
21456837709
39284106657
49085527316
59178604432
69471338025
79581224630
89674235011
97518264003
</code>```

And here are the expected results for those:

Make sure that your code also works when given a single digit (I don't want to include the expected results here, because they should be obvious, and the test case section is bloated enough as it is).

答:
Html+JavaScript ES6, 352

Test running the snippet below

<canvas id=C></canvas>```
</div>
</div>
</p>

<p><em>Less golfed</em></p>

<pre class="lang-js prettyprint-override"><code>s=prompt(),C.width=-~s.length*80,c=C.getContext("2d"),
w=a=>{
  a=parseInt("vhvivgtlnllv74vnltvlt11vvlvnlv0"[i],36)*2+1
  for(p=1,y=100,i=32;i;p=b,y-=20,i>>=1)
    c.moveTo(x+20,y),
    b=a&i?1:0,
    c[b-p?'lineTo':'moveTo'](x,y),
    (a^q)&i&&c.lineTo(x,y-20)
  q=a
  x+=20
},
[...s].map(d=>[30,d*=3,++d,++d].map(w),q=63,x=0),
w(30),w(0)
c.stroke()
</code>```

ContentLicense: CC BY-SA 4.0

Title: Between the Lines

Body:
Html+JavaScript ES6, 352

Test running the snippet below

<canvas id=C></canvas><script>s=prompt(),C.width=-~s.length*80,c=C.getContext("2d"),[...s].map(d=>[30,d*=3,++d,++d].map(w=a=>{for(a=parseInt("vhvivgtlnllv74vnltvlt11vvlvnlv0"[a],36)*2+1,p=1,y=100,i=64;i>>=1;p=b,y-=20)c.moveTo(x+20,y),b=a&i?1:0,c[b-p?'lineTo':'moveTo'](x,y),(a^q)&i&&c.lineTo(x,y-20);q=a,x+=20}),q=63,x=0),w(30),w(0),c.stroke()</script>

Less golfed

s=prompt(),C.width=-~s.length*80,c=C.getContext("2d"),
w=a=>{
  a=parseInt("vhvivgtlnllv74vnltvlt11vvlvnlv0"[i],36)*2+1
  for(p=1,y=100,i=32;i;p=b,y-=20,i>>=1)
    c.moveTo(x+20,y),
    b=a&i?1:0,
    c[b-p?'lineTo':'moveTo'](x,y),
    (a^q)&i&&c.lineTo(x,y-20)
  q=a
  x+=20
},
[...s].map(d=>[30,d*=3,++d,++d].map(w),q=63,x=0),
w(30),w(0)
c.stroke()


答:
PowerShell, <s>41</s> 38 bytes

```<code>param($a,$b,$c)[math]::Max(0,$a+$c-$b)
</code>```

Pretty straightforward implementation of the Pitot theorem (thanks to Martin for remembering the name of it).

Saved 3 bytes by using the .NET [math]::Max() function.

Title: Find the remaining side of the tangential quadrilateral

Body:
(Taken from https://en.wikipedia.org/wiki/File:Tangential_quadrilateral.svg)

A tangential quadrilateral (see example above) is a quadrilateral in which a circle can be inscribed.

Your task is to find the possible value of d given a, b, and c.

Specs

a, b, c will all be positive integers.

If no possible value of d exists, output 0.

Scoring

This is code-golf. Shortest solution in bytes wins.

Testcases

```<code>a b c d
3 4 4 3
1 2 3 2
1 5 3 0
</code>```

Body:
PowerShell, <s>41</s> 38 bytes

param($a,$b,$c)[math]::Max(0,$a+$c-$b)

Pretty straightforward implementation of the Pitot theorem (thanks to Martin for remembering the name of it).

Saved 3 bytes by using the .NET [math]::Max() function.


答:
05AB1E, <s>5</s> 4 bytes

Input is taken as:

```<code>b
a
c
</code>```

Code:

```<code>-+0M
</code>```

Explanation:

```<code>      # Inputs: b, a, c
-     # Substract, (a - b).
 +    # Add with implicit input, (a - b + c).
  0   # Push zero on top of the stack.
   M  # Get the largest number that exists in the stack and implicitly print that value.
</code>```

Try it online!

Body:
05AB1E, <s>5</s> 4 bytes

Input is taken as:

b
a
c

Code:

-+0M

Explanation:

      # Inputs: b, a, c
-     # Substract, (a - b).
 +    # Add with implicit input, (a - b + c).
  0   # Push zero on top of the stack.
   M  # Get the largest number that exists in the stack and implicitly print that value.

Try it online!


答:
Lua, <s>333</s> 328 bytes

Features high-level invalid input system and absolutely innovative infinite loop for repeated use.

```<code>m=math.abs p=print::e::c={}for i=1,2 do for s in io.read():gmatch'%S+'do c[#c+1]=s end end for i=1,4 do n=c[i]:sub(1,-2)d=c[i]:sub(-1,-1)c[i]=d==("N"or"E")and n or-n end x=c[2]+c[4]y=c[1]+c[3]a=m(x)b=m(y)if(a or b)>9999 then p'Invalid input\n'goto e end x=x<0 and a.."W"or a.."E"y=y<0 and b.."S"or b.."N"p(y.." "..x.."\n")goto e
</code>```

Enjoy ;)

Edit: saved 5 bytes from renaming math.abs as m and print as p

Title: Traveling on a flat Earth

Body:
Coordinates in the flat-Earth world consist of latitude (x) and longitude (y), which are integers in the range 0...9999. Much like Gaussian integers, but they are always written using this notation:

```<code>411S 370E
</code>```

That is, with S or N appended to the latitude, and E or W appended to the longitude, with space(s) between the two components.

Goal

Write a program (not a function) that reads two coordinates, separated by whitespace, and outputs their sum. The first coordinate is a starting point, the second one is a displacement, and the output is the resulting position.

Input/Output

Since this challenge is partially about formatting, I'll try to define the input and output formats unambiguously.

The preferred input format has 1 space between the coordinate components, no leading zeros, and a newline character between the two coordinates. The program must be able to read the preferred format.

The output can contain any amount of whitespace and leading zeros. If it's different from the preferred input format, the program must be able to read this format too.

Just to make it clear, the input cannot (will not) contain any additional formatting characters. Just spaces and newlines where needed.

Scoring

This is an experiment on a new winning condition. I'll choose the winner by accepting an answer in a few weeks. If a better answer appears afterwards, I'll change the accepted answer.

The score for the program is its byte count. The winning program is one that is shorter than 400 bytes, has the fewest byte count, but is written in the most verbose programming language. To determine the winner:

Remove programs with byte count 400 or more (they can participate but cannot win)

Consider only the shortest program for each programming language

The longest program wins

Polyglots compete against programs in all languages in which they are valid (e.g. if a program is valid in both bash and sh, it competes against programs in both languages).

Test cases

In the test cases, the first two lines are the input, and the third line is the output.

```<code>0S 0E
0S 0W
0N 0E
</code>```

(the direction of zero doesn't matter, both in input and output)

```<code>0S 9999E
9999N 9999W
9999N 0E
</code>```

(maximal values)

```<code>42S 314W
42N 2718W
0N 3032W
</code>```

(the direction of zero doesn't matter in the output)

```<code>5555N 8888W
7777S 0E
2222S 8888W
</code>```

(no negative values; change the direction if you need to change the sign)

```<code>0001N        4545W
0999N        5454W
1000N        9999W
</code>```

(if the program outputs leading zeros and several spaces, it must be able to read them; it must also be able to read input that doesn't contain them)

```<code>8888N 8888W
9999N 9999W
</code>```

(invalid input - any behavior is acceptable, including crash and infinite loop)

Body:
Lua, <s>333</s> 328 bytes

Features high-level invalid input system and absolutely innovative infinite loop for repeated use.

m=math.abs p=print::e::c={}for i=1,2 do for s in io.read():gmatch'%S+'do c[#c+1]=s end end for i=1,4 do n=c[i]:sub(1,-2)d=c[i]:sub(-1,-1)c[i]=d==("N"or"E")and n or-n end x=c[2]+c[4]y=c[1]+c[3]a=m(x)b=m(y)if(a or b)>9999 then p'Invalid input\n'goto e end x=x<0 and a.."W"or a.."E"y=y<0 and b.."S"or b.."N"p(y.." "..x.."\n")goto e

Enjoy ;)

Edit: saved 5 bytes from renaming math.abs as m and print as p


答:
Dyalog APL, 4 bytes

```<code>0⌈-/
</code>```

Try it online!

How it works

```<code>0⌈-/  Monadic function train. Argument: (a b c)

  -/  Reduce by subtraction.
      APL evaluates everything from right to left, so this computes
      a - b - c = a - (b - c) = a - b + c.
0⌈    Take the maximum of 0 and a - b + c.
</code>```

Body:
Dyalog APL, 4 bytes

0⌈-/

Try it online!

How it works

0⌈-/  Monadic function train. Argument: (a b c)

  -/  Reduce by subtraction.
      APL evaluates everything from right to left, so this computes
      a - b - c = a - (b - c) = a - b + c.
0⌈    Take the maximum of 0 and a - b + c.


Title: Build a triangle without any triangles

Body:
As a little kid, I liked to play with these toys a lot:

They probably intended for these to be used for art, but I always used them for math! Fractals, patterns, etc. One time, I was given this challenge:

Build a triangle without using any of the green triangle tiles.

This challenge stumped me for the longest time, until I stumbled upon a really beautiful and simple way to do it with just 3 trapezoids:

```<code>  /\
 /_/\
/__\_\
</code>```

Now, take this triangle, and rotate it:

```<code>______
\ \__/
 \/ /
  \/
</code>```

Using these two triangles, we can construct larger triangles out of them. Here is a triangle of height 2:

```<code>     /\
    /_/\
   /__\_\
  /\ \__/\
 /_/\/ /_/\
/__\_\/__\_\
</code>```

And here are triangles of height 3-7:

```<code>#3
        /\
       /_/\
      /__\_\
     /\ \__/\
    /_/\/ /_/\
   /__\_\/__\_\
  /\ \__/\ \__/\
 /_/\/ /_/\/ /_/\
/__\_\/__\_\/__\_\

#4
           /\
          /_/\
         /__\_\
        /\ \__/\
       /_/\/ /_/\
      /__\_\/__\_\
     /\ \__/\ \__/\
    /_/\/ /_/\/ /_/\
   /__\_\/__\_\/__\_\
  /\ \__/\ \__/\ \__/\
 /_/\/ /_/\/ /_/\/ /_/\
/__\_\/__\_\/__\_\/__\_\

#5
              /\
             /_/\
            /__\_\
           /\ \__/\
          /_/\/ /_/\
         /__\_\/__\_\
        /\ \__/\ \__/\
       /_/\/ /_/\/ /_/\
      /__\_\/__\_\/__\_\
     /\ \__/\ \__/\ \__/\
    /_/\/ /_/\/ /_/\/ /_/\
   /__\_\/__\_\/__\_\/__\_\
  /\ \__/\ \__/\ \__/\ \__/\
 /_/\/ /_/\/ /_/\/ /_/\/ /_/\
/__\_\/__\_\/__\_\/__\_\/__\_\

#6
                 /\
                /_/\
               /__\_\
              /\ \__/\
             /_/\/ /_/\
            /__\_\/__\_\
           /\ \__/\ \__/\
          /_/\/ /_/\/ /_/\
         /__\_\/__\_\/__\_\
        /\ \__/\ \__/\ \__/\
       /_/\/ /_/\/ /_/\/ /_/\
      /__\_\/__\_\/__\_\/__\_\
     /\ \__/\ \__/\ \__/\ \__/\
    /_/\/ /_/\/ /_/\/ /_/\/ /_/\
   /__\_\/__\_\/__\_\/__\_\/__\_\
  /\ \__/\ \__/\ \__/\ \__/\ \__/\
 /_/\/ /_/\/ /_/\/ /_/\/ /_/\/ /_/\
/__\_\/__\_\/__\_\/__\_\/__\_\/__\_\

#7
                    /\
                   /_/\
                  /__\_\
                 /\ \__/\
                /_/\/ /_/\
               /__\_\/__\_\
              /\ \__/\ \__/\
             /_/\/ /_/\/ /_/\
            /__\_\/__\_\/__\_\
           /\ \__/\ \__/\ \__/\
          /_/\/ /_/\/ /_/\/ /_/\
         /__\_\/__\_\/__\_\/__\_\
        /\ \__/\ \__/\ \__/\ \__/\
       /_/\/ /_/\/ /_/\/ /_/\/ /_/\
      /__\_\/__\_\/__\_\/__\_\/__\_\
     /\ \__/\ \__/\ \__/\ \__/\ \__/\
    /_/\/ /_/\/ /_/\/ /_/\/ /_/\/ /_/\
   /__\_\/__\_\/__\_\/__\_\/__\_\/__\_\
  /\ \__/\ \__/\ \__/\ \__/\ \__/\ \__/\
 /_/\/ /_/\/ /_/\/ /_/\/ /_/\/ /_/\/ /_/\
/__\_\/__\_\/__\_\/__\_\/__\_\/__\_\/__\_\
</code>```

The Challenge

Write a program or function that takes a number n and prints a triangle-less triangle of height n. Trailing spaces on each line is acceptable, and up to one trailing or leading newline is also acceptable. IO can be in any reasonable format. The input is guarenteed to be a positive integer, so you don't have to worry about negative numbers, decimals, non-numbers etc.

Shortest answer in bytes wins!

Body:
Pyth, 66 bytes

jmj+L**3-Qhd\ [+*2;j" \\__"*Jhd]"/\\"+;j"/ "*J]"/_/\\"*J"/__\\_\\"

Try it online!


答:
J, <s>12</s> <s>9</s> <s>8</s> 5 bytes

Input is given as a, b, c. Saved a byte inspired by using Dennis's subtraction method.

```<code>0>.-/
</code>```

Explanation

```<code>0>.-/
   -/   reduce argument over subtraction
0>.     greater of the reduction and 0
</code>```

Test cases

```<code>   rem =: 0>.-/
   rem 3 3 4
4
   rem 1 2 3
2
   rem 1 5 3
0
   rem"1 > (3 3 4 ; 1 2 3 ; 1 5 3)
4 2 0
</code>```

Previously: (a,c,b input) +/@}:-{:), +/@(}:,-@{:)

Body:
J, <s>12</s> <s>9</s> <s>8</s> 5 bytes

Input is given as a, b, c. Saved a byte inspired by using Dennis's subtraction method.

0>.-/

Explanation

0>.-/
   -/   reduce argument over subtraction
0>.     greater of the reduction and 0

Test cases

   rem =: 0>.-/
   rem 3 3 4
4
   rem 1 2 3
2
   rem 1 5 3
0
   rem"1 > (3 3 4 ; 1 2 3 ; 1 5 3)
4 2 0

Previously: (a,c,b input) +/@}:-{:), +/@(}:,-@{:)


问:
Toilet Paper Mysteries
Today you need to solve a very practical problem: How many loops do you need to have a certain number of sheets on your toilet paper roll? Let's look at some facts:

The diameter of a bare toilet paper cylinder is 3.8cm

The length of one sheet of toilet paper is 10cm.

The thickness of one sheet of toilet paper is 1mm.

Before you wrap around the cylinder the first time, it has a circumference in cm of 3.8*pi. Every time you wrap a sheet around the cylinder its radius increases by .1, therefore its circumference increases by .2*PI. Use this information to find out how many loops it takes to fit n sheets of toilet paper. (Note: Use an approximation of Pi that is at least as accurate as 3.14159).

Test Cases:

n=1:

10/(3.8*pi) = .838 loops

n=2:

(How many full loops can we make?) 1 full loop = 3.8*pi = 11.938.

(How much do we have left after the 1st loop?) 20 - 11.938 = 8.062

(How much of a 2nd loop does the remaining piece make?) 8.062/(4*pi) = .642 loops

Answer: 1.642 loops

n=3:

1st full loop = 3.8*pi = 11.938, 2nd full loop = 4*pi = 12.566

30 - 11.938 - 12.566 = 5.496

5.496/(4.2*pi) = .417

Answer: 2.417 loops

n=100 => 40.874

答:
Python 3, <s>114</s> <s>109</s> 99 bytes

This function tracks the circumference of each layer until the sum of the circumferences is greater than the length of the number of sheets. Once this happens the answer is:

One less than the number of calculated layers + length of leftover sheets / circumference of most recent layer

def f(n):
    l,s=0,[]
    while sum(s)<n:s+=[.062832*(l+19)];l+=1
    return len(s)-1+(n-sum(s[:-1]))/s[-1]
```

Update

-10 [16-05-09] Optimized my math-ing

-5 [16-05-04] Minimized number of lines

Title: Toilet Paper Mysteries

Body:
Python 3, <s>114</s> <s>109</s> 99 bytes

This function tracks the circumference of each layer until the sum of the circumferences is greater than the length of the number of sheets. Once this happens the answer is:

One less than the number of calculated layers + length of leftover sheets / circumference of most recent layer

def f(n):
    l,s=0,[]
    while sum(s)<n:s+=[.062832*(l+19)];l+=1
    return len(s)-1+(n-sum(s[:-1]))/s[-1]

Update

-10 [16-05-09] Optimized my math-ing

-5 [16-05-04] Minimized number of lines


答:
Piet, 32 Codels

Codelsize 20:

Notes

Pretty straightforward. Could be 7x3=21 Codels if it wasn't for the termination, but it seems like thats required by default.

Npiet trace images

Valid input [1, 2, 3]

Invalid input [1, 5, 3]