问:
Prime Wednesdays

Prime Wednesdays

Your task is to count the number of Wednesdays that fall on a prime day of the month in a particular year. For instance, 7-13-16 is a prime Wednesday. For consistency use the Gregorian calendar for all dates.

Input

The input to your program/function will be a year (eg 2016) and is flexible. The year will be an integer between 1912 and 2233 inclusive.

Output

The output is also flexible and should be the number of prime Wednesdays (eg 18).

Scoring

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

Test Cases

input     -> output

  --------------------

  1912  ->   19

  1914  ->   16

  1984  ->   17

  1996  ->   19

  2063  ->   19

  2150  ->   16

  2199  ->   18

  2233  ->   18

答:
J, 44 bytes

```<code>+/@(valdate*3=weekday)@,.&(,/(>:,"0/p:)i.12)
</code>```

I just discovered that J has builtins for date manipulation.

Usage

Extra commands are used for formatting multiple input/output.

```<code>   f =: +/@(valdate*3=weekday)@,.&(,/(>:,"0/p:)i.12)
   (,.f"0) 1912 1914 1984 1996 2063 2150 2199 2233
1912 19
1914 16
1984 17
1996 19
2063 19
2150 16
2199 18
2233 18
</code>```

Explanation

```<code>+/@(valdate*3=weekday)@,.&(,/(>:,"0/p:)i.12)  Input: year
                                       i.12   The range [0, ..., 11]
                              >:              Increment each to get the months [1, ..., 12]
                                    p:        Get the first 12 primes [2, ..., 37]
                                ,"0/          Make a table between each month and prime
                           ,/                 Join the rows
                       ,.&                    Prepend the year to each
                                              The date format is YYYY MM DD
            3=weekday                         Check if each date occurs on Wednesday
    valdate*                                  and is a valid date
+/@                                           Count the number of true values and return
</code>```

Title: Prime Wednesdays

Body:
J, 44 bytes

+/@(valdate*3=weekday)@,.&(,/(>:,"0/p:)i.12)

I just discovered that J has builtins for date manipulation.

Usage

Extra commands are used for formatting multiple input/output.

   f =: +/@(valdate*3=weekday)@,.&(,/(>:,"0/p:)i.12)
   (,.f"0) 1912 1914 1984 1996 2063 2150 2199 2233
1912 19
1914 16
1984 17
1996 19
2063 19
2150 16
2199 18
2233 18

Explanation

+/@(valdate*3=weekday)@,.&(,/(>:,"0/p:)i.12)  Input: year
                                       i.12   The range [0, ..., 11]
                              >:              Increment each to get the months [1, ..., 12]
                                    p:        Get the first 12 primes [2, ..., 37]
                                ,"0/          Make a table between each month and prime
                           ,/                 Join the rows
                       ,.&                    Prepend the year to each
                                              The date format is YYYY MM DD
            3=weekday                         Check if each date occurs on Wednesday
    valdate*                                  and is a valid date
+/@                                           Count the number of true values and return


问:
Linear combination of two vectors

Executive summary

Given input representing two vectors and their respective "weights", produce output that also represents the weighted sum of those vectors.

Challenge

The input will consist of one or more lines of the following characters:

exactly one occurrence of the digit 0, which represents the origin in a two-dimensional plane;

exactly two other digits (1-9; may or may not be the same digit), whose positions relative to the origin represent vectors, and whose values represent the weights attached to thse vectors;

some number of "background characters". The solver may choose a specific background character; for example, I will choose "." (mostly for human readability). Alternately, the background characters can be anything that look like blank space.

(The solver can choose whether the input is a single multi-line string or an array of one-line strings.)

For example, the input

```<code>....2
.0...
...3.
</code>```

represents a vector at coordinates (3,1) with weight 2, and a vector at coordinates (2,-1) with weight 3.

The output should be almost the same as the input, with the following changes:

a "result character", chosen by the solver, to be added at the position specified by weighted sum of the input vectors (equivalently, at the position that is the appropriate linear combination of the input vectors);

as many background characters as are needed to fit the origin, the two input vectors, and the output vector in the same picture. Extra background characters can be included if desired; the only constraint is that, if the background character is a visible character, then the entire output must be rectangular in shape and every character not representing a vector must be the background character. (If blank space is used as background characters, then these constraints don't need to be enforced.)

(In general, if we have one vector (v,w) with weight a and second vector (x,y) with weight b, their weighted sum is a(v,w)+b(x,y) = (av+bx,aw+by).)

In the previous example, the appropriate linear combination is 2*(3,1) + 3*(2,-1) = (12,-1). If we use "X" as the result character, then the output could look like

```<code>....2.........
.0............
...3.........X
</code>```

or

```<code>................
...2............
0...............
..3.........X...
................
................
</code>```

Usual code-golf scoring: the shortest answer, in bytes, wins.

Example input and output

If blank space is used, the above input would look like

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

and the output would look like

```<code>    2
 0
   3         X
</code>```

Leading/trailing whitespace characters/lines are irrelevant; if they're invisible to the reader, it's fine. (That being said, for the rest of the examples I'll go back to using "." for the background character, to make it easier to read.)

If both vectors have weight 1, then the result will look like a parallelogram: the input

```<code>.1.
...
1.0
</code>```

leads to the output

```<code>X.1.
....
.1.0
</code>```

Note this parallelogram can be degenerate if the input vectors are collinear: the input

```<code>0.1..1
</code>```

leads to the output

```<code>0.1..1.X
</code>```

It is possible for the result vector to equal one of the input vectors or the origin; in this case, it simply overwrites the input character. For example, the input

```<code>..2.0.1...
</code>```

yields the output

```<code>....2.........
.0............
...3.........X
</code>```0

(where in input and/or output, the leading and trailing periods could be deleted). The input

```<code>....2.........
.0............
...3.........X
</code>```1

yields the output

```<code>....2.........
.0............
...3.........X
</code>```2

Finally, the input

```<code>90
.8
</code>```

yields the output

```<code>........90
.........8
..........
..........
..........
..........
..........
..........
X.........
</code>```

答:
JavaScript, 534 528 502 bytes

```<code>n="indexOf"
J="join"
B=X=>X.split(O)
O='\n'
w=i[n](O)+1
h=B(i).length
Z=(X,Y,R)=>{C[R]+=X-1;return Array(X)[J](Y)}
C=[0,0,0]
G=(X,E,T,U,R)=>X>0&E>=0?Z(X+E+1+T,U,R):""
o=i[n]("0")
L=X=>Math.floor(X/(w-1))
l=L(o)
c=o%w
x=y=0
j=i
for(z="1";z<="9";z++){while(p=~j[n](z)){j=j.replace(z," ")
x+=~p%w-l
y+=L(~p)-c}}
I=B(i).map(X=>G(-x,-l,0," ",0)+X+G(x,l-w+2,0," ",2))
N=Z(I[0].length+1," ",2)
A=B(G(-y,-c,0,N+O,1)+I[J](O)+G(y,c-h,1,O+N,2))
M=y+c+C[1]
O=""
m=B(A[M])
m[x+l+C[0]/h]="x"
A[M]=m[J]("")
A[J]("\n")
</code>```

Note that the padding is optimal. This program assumes that i contains the raw string, with the lines separated by \n characters. The padding is done with spaces, and the result character is a lowercase x.

This is my first attempt at code-golfing.

Technical stuff:
- The program's size roughly doubled (and its complexity went up dramatically) to just take into account the result character, mostly because JavaScript strings are immutable.

Line by line explanation:

```<code>n="indexOf"
J="join"
B=X=>X.split(O)
</code>```

I use those a lot, so storing them in strings saved me some space. You can see below that for the split function, I have simply created an alias; this is because I only needed one argument, the other one being constant. For indexOf and join, it would however have been longer.

```<code>O='\n'
w=i[n](O)+1
h=B(i).length
</code>```

Nothing complicated here, I'm reading the width and height of the initial array. Note the use of i[n] to access indexOf, while split is handled differently.

```<code>Z=(X,Y,R)=>{C[R]+=X-1;return Array(X)[J](Y)}
</code>```

This is getting interesting. This function basically creates concatenates J-1 times the string X and returns it. This is used to generate strings of spaces for the padding.

```<code>C=[0,0,0]
</code>```

This array will contain the number of lines and columns added by the padding (off by a factor h in the first case). The last cell is a junk one, and prevents me from having an additional argument in the function below.

```<code>G=(X,E,T,U,R)=>X>0&E>=0?Z(X+E+1+T,U,R):""
</code>```

This function alone handles the padding (both lines and columns); it determines, based on a coordinate of the result vector (X), and the number of lines/columns to generate (E), whether it is necessary to create one. the X+E+1+T is just a trick to save some space, U is the filling string (a space for columns, and an entire line for lines), and we'll come back to R. This function basically returns, in the case of a line, the padding required at the beginning or the end of said line, and, in the case of a column, it returns the padding lines required either before or after the original lines.

```<code>o=i[n]("0")
L=X=>Math.floor(X/(w-1))
l=L(o)
c=o%w
</code>```

Here we read the position of the origin, and we retrieve its coordinates. L is a function to convert an index into a line number.

```<code>x=y=0
j=i
for(z="1";z<="9";z++){
    while(p=~j[n](z)){
        j=j.replace(z," ")
        x+=~p%w-l
        y+=L(~p)-c
    }
}
</code>```

I added some whitespace to make this easier to read. What happens here is that for each possible number, we keep looking for it in the original string. The ~ trick is relatively common in Javascript; it is the bitwise NOT operator, but all that matters here is that ~-1==0, which allows me to test for the end of the loop. I then erase the character in the string (which is why I made a copy), this allowing me to continue the search as long as needed. I then add the coordinates of the vector to (x, y), using a simple substraction.

```<code>I=B(i).map(X=>G(-x,-l,0," ",0)+X+G(x,l-w+2,0," ",2))
</code>```

I here split the original string into lines, and for each line, I call G which will generate the padding before and after the lines. The l-w+2 and so on come from a simple index calculation which allows me to test whether I need to add padding or not. For example, if x>0 and x+l-w+1>0, then (x+l-w+1)+1 spaces must be added after the line. The +x is being removed due to it being the first parameter, and the X+E+1+T used in the definition of G.

A similar thing is done for the first characters, and then for the columns. There is a lot of factorization here allowing me to use only one function. Note the last parameter; in the first case, I want to write to C[0] to be able to know later how many columns I added at the beginning of each line; this allows me to retrieve the final position of the result character. I do however not care about the columns added after the original line, which is why the second call to G writes to the junk cell C[2] which is unused.

```<code>N=Z(I[0].length+1," ",2)
</code>```

Here I simply read the new length of the lines, and create a line of spaces from it. This will be used to create the vertical padding.

```<code>A=B(G(-y,-c,0,N+O,1)+I[J](O)+G(y,c-h,1,O+N,2))
</code>```

This is exactly the same as two lines above. The only difference is writing to C[1] this time, and using the separators N+O and O+N. Remember that O is a newline, and N is a line of spaces. I then apply B on the result to split it again (I need to retrieve the line containing the result character to edit it).

```<code>M=y+c+C[1]
</code>```

This is the vertical index of the resulting character.

```<code>O=""
m=B(A[M])
m[x+l+C[0]/h]="x"
</code>```

Here I am forced to modify O to be able to split the appropriate line into an array of characters. This is because JavaScript strings are immutable; the only way to edit a string is to convert it into an array (which is what I'm doing here), edit at the right position, and join the string again. Also note the h factor, which is because the G function was called once per initial line.

```<code>A[M]=m[J]("")
A[J]("\n")
</code>```

I finally replace the new string in the array, and join it again into a string. Woohoo!

ContentLicense: CC BY-SA 3.0

Title: Linear combination of two vectors

Body:
JavaScript, 534 528 502 bytes

n="indexOf"
J="join"
B=X=>X.split(O)
O='\n'
w=i[n](O)+1
h=B(i).length
Z=(X,Y,R)=>{C[R]+=X-1;return Array(X)[J](Y)}
C=[0,0,0]
G=(X,E,T,U,R)=>X>0&E>=0?Z(X+E+1+T,U,R):""
o=i[n]("0")
L=X=>Math.floor(X/(w-1))
l=L(o)
c=o%w
x=y=0
j=i
for(z="1";z<="9";z++){while(p=~j[n](z)){j=j.replace(z," ")
x+=~p%w-l
y+=L(~p)-c}}
I=B(i).map(X=>G(-x,-l,0," ",0)+X+G(x,l-w+2,0," ",2))
N=Z(I[0].length+1," ",2)
A=B(G(-y,-c,0,N+O,1)+I[J](O)+G(y,c-h,1,O+N,2))
M=y+c+C[1]
O=""
m=B(A[M])
m[x+l+C[0]/h]="x"
A[M]=m[J]("")
A[J]("\n")

Note that the padding is optimal. This program assumes that i contains the raw string, with the lines separated by \n characters. The padding is done with spaces, and the result character is a lowercase x.

This is my first attempt at code-golfing.

Technical stuff:
- The program's size roughly doubled (and its complexity went up dramatically) to just take into account the result character, mostly because JavaScript strings are immutable.

Line by line explanation:

n="indexOf"
J="join"
B=X=>X.split(O)

I use those a lot, so storing them in strings saved me some space. You can see below that for the split function, I have simply created an alias; this is because I only needed one argument, the other one being constant. For indexOf and join, it would however have been longer.

O='\n'
w=i[n](O)+1
h=B(i).length

Nothing complicated here, I'm reading the width and height of the initial array. Note the use of i[n] to access indexOf, while split is handled differently.

Z=(X,Y,R)=>{C[R]+=X-1;return Array(X)[J](Y)}

This is getting interesting. This function basically creates concatenates J-1 times the string X and returns it. This is used to generate strings of spaces for the padding.

C=[0,0,0]

This array will contain the number of lines and columns added by the padding (off by a factor h in the first case). The last cell is a junk one, and prevents me from having an additional argument in the function below.

G=(X,E,T,U,R)=>X>0&E>=0?Z(X+E+1+T,U,R):""

This function alone handles the padding (both lines and columns); it determines, based on a coordinate of the result vector (X), and the number of lines/columns to generate (E), whether it is necessary to create one. the X+E+1+T is just a trick to save some space, U is the filling string (a space for columns, and an entire line for lines), and we'll come back to R. This function basically returns, in the case of a line, the padding required at the beginning or the end of said line, and, in the case of a column, it returns the padding lines required either before or after the original lines.

o=i[n]("0")
L=X=>Math.floor(X/(w-1))
l=L(o)
c=o%w

Here we read the position of the origin, and we retrieve its coordinates. L is a function to convert an index into a line number.

x=y=0
j=i
for(z="1";z<="9";z++){
    while(p=~j[n](z)){
        j=j.replace(z," ")
        x+=~p%w-l
        y+=L(~p)-c
    }
}

I added some whitespace to make this easier to read. What happens here is that for each possible number, we keep looking for it in the original string. The ~ trick is relatively common in Javascript; it is the bitwise NOT operator, but all that matters here is that ~-1==0, which allows me to test for the end of the loop. I then erase the character in the string (which is why I made a copy), this allowing me to continue the search as long as needed. I then add the coordinates of the vector to (x, y), using a simple substraction.

I=B(i).map(X=>G(-x,-l,0," ",0)+X+G(x,l-w+2,0," ",2))

I here split the original string into lines, and for each line, I call G which will generate the padding before and after the lines. The l-w+2 and so on come from a simple index calculation which allows me to test whether I need to add padding or not. For example, if x>0 and x+l-w+1>0, then (x+l-w+1)+1 spaces must be added after the line. The +x is being removed due to it being the first parameter, and the X+E+1+T used in the definition of G.

A similar thing is done for the first characters, and then for the columns. There is a lot of factorization here allowing me to use only one function. Note the last parameter; in the first case, I want to write to C[0] to be able to know later how many columns I added at the beginning of each line; this allows me to retrieve the final position of the result character. I do however not care about the columns added after the original line, which is why the second call to G writes to the junk cell C[2] which is unused.

N=Z(I[0].length+1," ",2)

Here I simply read the new length of the lines, and create a line of spaces from it. This will be used to create the vertical padding.

A=B(G(-y,-c,0,N+O,1)+I[J](O)+G(y,c-h,1,O+N,2))

This is exactly the same as two lines above. The only difference is writing to C[1] this time, and using the separators N+O and O+N. Remember that O is a newline, and N is a line of spaces. I then apply B on the result to split it again (I need to retrieve the line containing the result character to edit it).

M=y+c+C[1]

This is the vertical index of the resulting character.

O=""
m=B(A[M])
m[x+l+C[0]/h]="x"

Here I am forced to modify O to be able to split the appropriate line into an array of characters. This is because JavaScript strings are immutable; the only way to edit a string is to convert it into an array (which is what I'm doing here), edit at the right position, and join the string again. Also note the h factor, which is because the G function was called once per initial line.

A[M]=m[J]("")
A[J]("\n")

I finally replace the new string in the array, and join it again into a string. Woohoo!

ContentLicense: CC BY-SA 4.0


问:
Big or Little Endian
Write a program or function that outputs an L if run on a little endian architecture or a B if run on a big endian architecture. Lower case output l or b is also acceptable.

There is no input.

Scoring is code golf, so the code with the fewest bytes wins.

Edit: As per the comments below, I am clarifying that the entry must be able to run on either architecture.

I believe that there is only one answer that this affects, and that answer has clearly indicated that this is the case.

答:
K,  15 bytes

```<code>    ("bl")@*6h$-8!`
    ,"l"
</code>```

Explanation;

```<code>    From right to left;
    -8!`       /serialises the back tick and returns (0x010000000a000000f500)
    6h$-8!`    /This casts the result to `int which is type 6h(could have used `int$-8!`) - the result is (1 0 0 0 10 0 0 0 245 0i)
    *6h$-8!`   /* means first, we take the first item which is 1. Since it will be either 1 or 0, we can use it to index (@) into the two element list on the left i.e. ("bl")1 returns "l" and ("bl")0 returns b

</code>```

Title: Big or Little Endian

Body:
K,  15 bytes

    ("bl")@*6h$-8!`
    ,"l"

Explanation;

    From right to left;
    -8!`       /serialises the back tick and returns (0x010000000a000000f500)
    6h$-8!`    /This casts the result to `int which is type 6h(could have used `int$-8!`) - the result is (1 0 0 0 10 0 0 0 245 0i)
    *6h$-8!`   /* means first, we take the first item which is 1. Since it will be either 1 or 0, we can use it to index (@) into the two element list on the left i.e. ("bl")1 returns "l" and ("bl")0 returns b


问:
Print this diamond
This question has been spreading like a virus in my office. There are quite a variety of approaches:

Print the following:

```<code>        1
       121
      12321
     1234321
    123454321
   12345654321
  1234567654321
 123456787654321
12345678987654321
 123456787654321
  1234567654321
   12345654321
    123454321
     1234321
      12321
       121
        1
</code>```

Answers are scored in characters with fewer characters being better.

答:
APL (<s>33</s> 31)

```<code>A⍪1↓⊖A←A,0 1↓⌽A←⌽↑⌽¨⍴∘(1↓⎕D)¨⍳9
</code>```

If spaces separating the numbers are allowed (as in the Mathematica entry), it can be shortened to <s>28</s> 26:

```<code>A⍪1↓⊖A←A,0 1↓⌽A←⌽↑⌽∘⍕∘⍳¨⍳9
</code>```

Explanation:

(Long program:)

⍳9: a list of the numbers 1 to 9

1↓⎕D: ⎕D is the string '0123456789', 1↓ removes the first element

⍴∘(1↓⎕D)¨⍳9: for each element N of ⍳9, take the first N elements from 1↓⎕D. This gives a list: ["1", "12", "123", ... "123456789"] as strings

⌽¨: reverse each element of this list. ["1", "21", "321"...]

(Short program:)

⍳¨⍳9: the list of 1 to N, for N [1..9]. This gives a list [[1], [1,2], [1,2,3] ... [1,2,3,4,5,6,7,8,9]] as numbers.

⌽∘⍕∘: the reverse of string representation of each of these lists. ["1", "2 1"...]

(The same from now on:)

A←⌽↑: makes a matrix from the list of lists, padding on the right with spaces, and then reverse that. This gives the upper quadrant of the diamond. It is stored in A.

A←A,0 1↑⌽A: A, with the reverse of A minus its first column attached to the right. This gives the upper half of the rectangle. This is then stored in A again.

A⍪1↓⊖A: ⊖A is A mirrored vertically (giving the lower half), 1↓ removes the top row of the lower half and A⍪ is the upper half on top of 1↓⊖A.

Title: Print this diamond

Body:
APL (<s>33</s> 31)

A⍪1↓⊖A←A,0 1↓⌽A←⌽↑⌽¨⍴∘(1↓⎕D)¨⍳9

If spaces separating the numbers are allowed (as in the Mathematica entry), it can be shortened to <s>28</s> 26:

A⍪1↓⊖A←A,0 1↓⌽A←⌽↑⌽∘⍕∘⍳¨⍳9

Explanation:

(Long program:)

⍳9: a list of the numbers 1 to 9

1↓⎕D: ⎕D is the string '0123456789', 1↓ removes the first element

⍴∘(1↓⎕D)¨⍳9: for each element N of ⍳9, take the first N elements from 1↓⎕D. This gives a list: ["1", "12", "123", ... "123456789"] as strings

⌽¨: reverse each element of this list. ["1", "21", "321"...]

(Short program:)

⍳¨⍳9: the list of 1 to N, for N [1..9]. This gives a list [[1], [1,2], [1,2,3] ... [1,2,3,4,5,6,7,8,9]] as numbers.

⌽∘⍕∘: the reverse of string representation of each of these lists. ["1", "2 1"...]

(The same from now on:)

A←⌽↑: makes a matrix from the list of lists, padding on the right with spaces, and then reverse that. This gives the upper quadrant of the diamond. It is stored in A.

A←A,0 1↑⌽A: A, with the reverse of A minus its first column attached to the right. This gives the upper half of the rectangle. This is then stored in A again.

A⍪1↓⊖A: ⊖A is A mirrored vertically (giving the lower half), 1↓ removes the top row of the lower half and A⍪ is the upper half on top of 1↓⊖A.


问:
Detriplicate a string
A lot of languages have built-in ways to get rid of duplicates, or "deduplicate" or "uniquify" a list or string. A less common task is to "detriplicate" a string. That is, for every character that appears, the first two occurrences are kept.

Here is an example where the characters that should be deleted are labelled with ^:

```<code>aaabcbccdbabdcd
  ^    ^ ^^^ ^^
aabcbcdd
</code>```

Your task is to implement exactly this operation.

Rules

Input is a single, possibly empty, string. You may assume that it only contains lowercase letters in the ASCII range.

Output should be a single string with all characters removed which have already appeared at least twice in the string (so the left-most two occurrences are kept).

Instead of strings you may work with lists of characters (or singleton strings), but the format has to be consistent between input and output.

You may write a program or a function and use any of the our standard methods of receiving input and providing output.

You may use any programming language, but note that these loopholes are forbidden by default.

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

Test Cases

Every pair of lines is one test case, input followed by output.

```<code>

xxxxx
xx
abcabc
abcabc
abcdabcaba
abcdabc
abacbadcba
abacbdc
aaabcbccdbabdcd
aabcbcdd
</code>```

Leaderboard

The Stack Snippet at the bottom of this post generates a leaderboard from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

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

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

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

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

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

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

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

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
K, 18 Bytes

```<code>  g:{x{?x@<x}@,/2#'=x}
  g "abc"
"abc"
  g "aaabcbccdbabdcd"
"aabcbcdd"

  /k4 request test vectors from internet
  R:"GET /raw/ftHe0bpE HTTP/1.0\r\nHost: pastebin.com\r\n\r\n"
  t:+0N 2#t@1_&|\(0=#:)'t:1_"\r\n"\:`:http://pastebin.com:80 R

  /k4 no internet? use a file called "t.txt" in current directory
  t:+0N 2#0:`:t.txt

  /k6?
  t:+0N 2#0:"t.txt"

  /visually inspect test cases
  g't[0]
(();"xx";"abcabc";"abcdabc";"abacbdc";"aabcbcdd")

  /do all tests pass?
  |/ t[1] {$[0=#x;0=#y;x~y]}' g't[0]
1b
</code>```

K4 is available for free download; K6 is in development. If you've downloaded KDB, you can get into K with backslash.

It may be easiest to see this broken apart, but first some syntax: g:x sets g to x. {x+1} is a function which takes an argument x. In K the first argument to a function is x (the second is y and the third is z. Don't need a fourth).

Now:

```<code>x:"aaabcbccdbabdcd"
</code>```

=x means group x, which produces:

```<code>"abcd"!(0 1 2 10;3 5 9 11;4 6 7 13;8 12 14)
</code>```

2#' means two taken(from) each which produces

```<code>"abcd"!(0 1;3 5;4 6;8 12)
</code>```

As you can see, these are the offsets of the first two matches of each character. The 2 could be generalised.

,/ means join each and is often called raze. It's going to get us just the values of our dictionary. Thus, ,/"abcd"!(0 1;3 5;4 6;8 12) produces:

```<code>0 1 3 5 4 6 8 12
</code>```

which we need to sort. {x@<x}@ is an idiom K programmers often see (Q calls it asc), which says x at grade-up x. Breaking it apart:

```<code>  <0 1 3 5 4 6 8 12
0 1 2 4 3 5 6 7
</code>```

returned the indices of the sorted array, which we want taken from the original array. x@y means x at y so this indexes the array with the indices of the sort (if that makes any sense).

```<code>  {x@<x}@0 1 3 5 4 6 8 12
0 1 3 4 5 6 8 12
</code>```

which we simply now index into our original array. We could say x@ here, but K supports a really powerful concept which we can take advantage of here: function application is indexing. That means that a[0] could be looking up the
zeroth slot of a or it could be applying the 0 to the function called a. The reason we needed the @ previously in {x@<x} is because x<y means xs less than ys: Operators in K have a dyadic form (two-argument) and a monadic form (one-argument) that comes from APL. Q doesn't have this "ambivalence".

Title: Detriplicate a string

Body:
K, 18 Bytes

  g:{x{?x@<x}@,/2#'=x}
  g "abc"
"abc"
  g "aaabcbccdbabdcd"
"aabcbcdd"

  /k4 request test vectors from internet
  R:"GET /raw/ftHe0bpE HTTP/1.0\r\nHost: pastebin.com\r\n\r\n"
  t:+0N 2#t@1_&|\(0=#:)'t:1_"\r\n"\:`:http://pastebin.com:80 R

  /k4 no internet? use a file called "t.txt" in current directory
  t:+0N 2#0:`:t.txt

  /k6?
  t:+0N 2#0:"t.txt"

  /visually inspect test cases
  g't[0]
(();"xx";"abcabc";"abcdabc";"abacbdc";"aabcbcdd")

  /do all tests pass?
  |/ t[1] {$[0=#x;0=#y;x~y]}' g't[0]
1b

K4 is available for free download; K6 is in development. If you've downloaded KDB, you can get into K with backslash.

It may be easiest to see this broken apart, but first some syntax: g:x sets g to x. {x+1} is a function which takes an argument x. In K the first argument to a function is x (the second is y and the third is z. Don't need a fourth).

Now:

x:"aaabcbccdbabdcd"

=x means group x, which produces:

"abcd"!(0 1 2 10;3 5 9 11;4 6 7 13;8 12 14)

2#' means two taken(from) each which produces

"abcd"!(0 1;3 5;4 6;8 12)

As you can see, these are the offsets of the first two matches of each character. The 2 could be generalised.

,/ means join each and is often called raze. It's going to get us just the values of our dictionary. Thus, ,/"abcd"!(0 1;3 5;4 6;8 12) produces:

0 1 3 5 4 6 8 12

which we need to sort. {x@<x}@ is an idiom K programmers often see (Q calls it asc), which says x at grade-up x. Breaking it apart:

  <0 1 3 5 4 6 8 12
0 1 2 4 3 5 6 7

returned the indices of the sorted array, which we want taken from the original array. x@y means x at y so this indexes the array with the indices of the sort (if that makes any sense).

  {x@<x}@0 1 3 5 4 6 8 12
0 1 3 4 5 6 8 12

which we simply now index into our original array. We could say x@ here, but K supports a really powerful concept which we can take advantage of here: function application is indexing. That means that a[0] could be looking up the
zeroth slot of a or it could be applying the 0 to the function called a. The reason we needed the @ previously in {x@<x} is because x<y means xs less than ys: Operators in K have a dyadic form (two-argument) and a monadic form (one-argument) that comes from APL. Q doesn't have this "ambivalence".


问:
"Break" a number

Origins

tl;dw (too lazy, didn't write): thought of it right before I fell asleep

Challenge

Breaking a number is defined as the following steps:

Take a number or a parseable data type as input in any allowed way.

Duplicate the first digit (64 -> 664)

Subtract 4 from the last digit (664 -> 660)

If the subtraction gets a negative last digit, move the negative sign (-) to the front of the number (73 -> 773 -> -771)

If the original number was negative, and the last digit becomes negative, remove all negative signs entirely. (-44441 -> 444443)

Output the number in any allowed way.

Here are a few test cases:

```<code>64 -> 660
73 -> -771
thisisnotanumber -> (handle the situation)
432188 -> 4432184
-83213 -> 883211 (two negative signs turn into a positive)
0 -> -4 (0 -> 00 -> 0-4 -> -04 -> -4)
</code>```

Clarifications

Standard loopholes are disallowed.

By "parseable data type", I mean any data type (String, Float, etc) that can be converted into the number type your program/function uses (Integer, Number, etc).

Your answer can be a function or a program. In both cases, provide an explanation of the code.

If it is a function, give a usage of it.

Test cases (or online interpreter) would be a nice plus to your answer.

Preceding 0s (-04) aren't allowed.

Behavior should be exactly replicated from the test cases above.

答:
Batch, 105 bytes

```<code>@set/an=%1,n*=s=n^>^>31^|1
@set n=%n:~0,1%%n%
@cmd/cset/ad=n%%10,e=d-4,t=e^^^>^^^>31^^^|1,(n-d+e*t)*s*t
</code>```

Alternatively the first line can be @set/as=%1^>^>31^|1,n=%1*s, also for 105 bytes. Explanation (without quoting metacharacters):

```<code>set /a n = %1               Get parameter
set /a s = n >> 31 | 1      Get sign of parameter
set /a n *= s               Get absolute value of parameter
set n=%n:~0,1%%n%           Duplicate the first digit
cmd /c                      Cause the final result to be printed
set /a d = n % 10           Get last digit
set /a e = d - 4            Calculate new last digit
set /a t = e >> 31 | 1      Get sign of new last digit
set /a e *= t               Get absolute value of new last digit
set /a (n - d + e) * s * t  Replace last digit and correct sign of result
</code>```

Title: "Break" a number

Body:
Batch, 105 bytes

@set/an=%1,n*=s=n^>^>31^|1
@set n=%n:~0,1%%n%
@cmd/cset/ad=n%%10,e=d-4,t=e^^^>^^^>31^^^|1,(n-d+e*t)*s*t

Alternatively the first line can be @set/as=%1^>^>31^|1,n=%1*s, also for 105 bytes. Explanation (without quoting metacharacters):

set /a n = %1               Get parameter
set /a s = n >> 31 | 1      Get sign of parameter
set /a n *= s               Get absolute value of parameter
set n=%n:~0,1%%n%           Duplicate the first digit
cmd /c                      Cause the final result to be printed
set /a d = n % 10           Get last digit
set /a e = d - 4            Calculate new last digit
set /a t = e >> 31 | 1      Get sign of new last digit
set /a e *= t               Get absolute value of new last digit
set /a (n - d + e) * s * t  Replace last digit and correct sign of result


问:
Is the DAG a transitive reduction?
The goal of this challenge is given a finite directed acyclic graph (DAG), determine if the graph is a transitive reduction.

A brief explanation of what a DAG and transitive reductions are:

A DAG is a graph with directed edges (i.e. you can only travel in one direction on that edge) such that given any starting node on the graph, it is impossible to return to the starting node (i.e. there are no cycles).

Given any starting node, if it is possible to travel to another ending node in the graph via any arbitrary positive number of edges, then that ending node is defined as reachable from the starting node. In a general DAG, there might be multiple paths which can be taken from a starting node to a target ending node. For example, take this diamond graph:

To get to node D from A, you could take the path A->B->D or A->C->D. Thus, D is reachable from A. However, there is no path which can be taken to get to node B starting from node C. Thus, node B is not reachable from node C.

Define the reachability of the graph as the list of reachable nodes for every starting node in the graph. So for the same example diamond graph, the reachability is:

```<code>A: [B, C, D]
B: [D]
C: [D]
D: []
</code>```

Another graph which has the same reachability as the above graph is shown below:

However, this second graph has more edges than the original graph. The transitive reduction of a graph is a graph with the least number of edges and same reachability of the original graph. So the first graph is the transitive reduction of the second one.

For a finite DAG, the transitive reduction is guaranteed to exist and is unique.

Input

The input is a "list of lists", where the external list has the length of the number of vertices, and each internal list is the length of the number of edges leaving the associated node, and contains the indices of destination nodes. For example, one way to describe the first graph above would be (assuming zero based indexing):

```<code>[[1, 2], [3], [3], []]
</code>```

You may begin indexing of the first node at any arbitrary integer value (e.g. 0 or 1 based indexing).

The input may come from any input source desired (stdio, function parameter, etc.). You are free to choose the exact input format as long as no additional information is given. For example, if you want to take input from stdio, you could have each line be a list of edges for the associated node. Ex.:

```<code>1 2
3
3
'' (blank line)
</code>```

The indices in each adjacency list is not necessarily sorted, and there could be multiple edges connecting two nodes (ex.: [[1,1],[]]). You may assume the input graph is weakly connected, and contains no cycles (i.e. it is a DAG).

Output

The output is truthy if the given input DAG is a transitive reduction, and a falsy value otherwise. This may be to any sink desired (stdio, return value, output parameter, etc.)

Examples

All examples use 0-based indexing.

```<code>[[1,2],[3],[3],[]]
true

[[1,2,3],[3],[3],[]]
false

[[1,1],[]]
false

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

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

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

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

[[1,3],[2],[3],[]]
false
</code>```

Scoring

This is code golf; smallest code in bytes wins. Your code should complete in a reasonable amount of time (10 minutes max on whatever hardware you have). Standard loopholes apply. You may use any built-ins desired.

答:
Ruby, <s>101</s> 97 bytes

Simple approach that calculates the reach from each node and considers if a child node can be reached via any of the other nodes. Seemingly fails on cyclic graphs, but the definition of a DAG implies that it shouldn't be cyclic anyways.

Try it online!

```<code>->g{r=->i{i|i.map{|j|r[g[j]||[]]}.inject([],:|)}
g.all?{|e|e==e&e&&e.none?{|i|r[e-[i]].index i}}}
</code>```

Title: Is the DAG a transitive reduction?

Body:
Ruby, <s>101</s> 97 bytes

Simple approach that calculates the reach from each node and considers if a child node can be reached via any of the other nodes. Seemingly fails on cyclic graphs, but the definition of a DAG implies that it shouldn't be cyclic anyways.

Try it online!

->g{r=->i{i|i.map{|j|r[g[j]||[]]}.inject([],:|)}
g.all?{|e|e==e&e&&e.none?{|i|r[e-[i]].index i}}}


答:
Ruby, <s>88</s> 87 + 3 (-n flag) = 90 bytes

Regex approach that reads lines from STDIN. Probably better solved with Perl if it's just regex like this?

Returns a nonsense NoMethodError if the input is not a number, which costs 14 bytes. If there's no need to worry about invalid inputs like that (the spec implied it needed handling) then the first line of the code can be removed.

-2 bytes from @Dada

```<code>+(~/^-?\d+$/)
sub(/\d/){$&*2}
sub(/.$/){$&.to_i-4}
p sub(/(-)?(.+)-/){$1?$2:?-+$2}.to_i
</code>```

Title: "Break" a number

Body:
Origins

tl;dw (too lazy, didn't write): thought of it right before I fell asleep

Challenge

Breaking a number is defined as the following steps:

Take a number or a parseable data type as input in any allowed way.

Duplicate the first digit (64 -> 664)

Subtract 4 from the last digit (664 -> 660)

If the subtraction gets a negative last digit, move the negative sign (-) to the front of the number (73 -> 773 -> -771)

If the original number was negative, and the last digit becomes negative, remove all negative signs entirely. (-44441 -> 444443)

Output the number in any allowed way.

Here are a few test cases:

```<code>64 -> 660
73 -> -771
thisisnotanumber -> (handle the situation)
432188 -> 4432184
-83213 -> 883211 (two negative signs turn into a positive)
0 -> -4 (0 -> 00 -> 0-4 -> -04 -> -4)
</code>```

Clarifications

Standard loopholes are disallowed.

By "parseable data type", I mean any data type (String, Float, etc) that can be converted into the number type your program/function uses (Integer, Number, etc).

Your answer can be a function or a program. In both cases, provide an explanation of the code.

If it is a function, give a usage of it.

Test cases (or online interpreter) would be a nice plus to your answer.

Preceding 0s (-04) aren't allowed.

Behavior should be exactly replicated from the test cases above.

Body:
Ruby, <s>88</s> 87 + 3 (-n flag) = 90 bytes

Regex approach that reads lines from STDIN. Probably better solved with Perl if it's just regex like this?

Returns a nonsense NoMethodError if the input is not a number, which costs 14 bytes. If there's no need to worry about invalid inputs like that (the spec implied it needed handling) then the first line of the code can be removed.

-2 bytes from @Dada

+(~/^-?\d+$/)
sub(/\d/){$&*2}
sub(/.$/){$&.to_i-4}
p sub(/(-)?(.+)-/){$1?$2:?-+$2}.to_i


问:
Print a Tabula Recta!
The Tabula Recta (sometimes called a 'Vigenere Table'), was created by Johannes Trithemius, and has been used in several ciphers, including all variants of Bellaso's Vigenere cipher and the Trithemius cipher. It looks like this:

```<code>ABCDEFGHIJKLMNOPQRSTUVWXYZ
BCDEFGHIJKLMNOPQRSTUVWXYZA
CDEFGHIJKLMNOPQRSTUVWXYZAB
DEFGHIJKLMNOPQRSTUVWXYZABC
EFGHIJKLMNOPQRSTUVWXYZABCD
FGHIJKLMNOPQRSTUVWXYZABCDE
GHIJKLMNOPQRSTUVWXYZABCDEF
HIJKLMNOPQRSTUVWXYZABCDEFG
IJKLMNOPQRSTUVWXYZABCDEFGH
JKLMNOPQRSTUVWXYZABCDEFGHI
KLMNOPQRSTUVWXYZABCDEFGHIJ
LMNOPQRSTUVWXYZABCDEFGHIJK
MNOPQRSTUVWXYZABCDEFGHIJKL
NOPQRSTUVWXYZABCDEFGHIJKLM
OPQRSTUVWXYZABCDEFGHIJKLMN
PQRSTUVWXYZABCDEFGHIJKLMNO
QRSTUVWXYZABCDEFGHIJKLMNOP
RSTUVWXYZABCDEFGHIJKLMNOPQ
STUVWXYZABCDEFGHIJKLMNOPQR
TUVWXYZABCDEFGHIJKLMNOPQRS
UVWXYZABCDEFGHIJKLMNOPQRST
VWXYZABCDEFGHIJKLMNOPQRSTU
WXYZABCDEFGHIJKLMNOPQRSTUV
XYZABCDEFGHIJKLMNOPQRSTUVW
YZABCDEFGHIJKLMNOPQRSTUVWX
ZABCDEFGHIJKLMNOPQRSTUVWXY
</code>```

I frequently need this, but can't find it anywhere on the internet to copy and paste from. Because the square table is so long, and takes frigging ages to type, your code must be as short as possible.

Rules/Requirements

Each submission should be either a full program or function. If it is a function, it must be runnable by only needing to add the function call to the bottom of the program. Anything else (e.g. headers in C), must be included.

If it is possible, provide a link to a site where your program can be tested.

Your program must not write anything to STDERR.

Standard Loopholes are forbidden.

Your program can output in any case, but it must be printed (not an array or similar).

Scoring

Programs are scored according to bytes, in UTF-8 by default or a different character set of your choice.

Eventually, the answer with the least bytes will win.

Submissions

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

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

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

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

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

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

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

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

Leaderboard

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

/* Configuration */

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

/* App */

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

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

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

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

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

getAnswers();

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

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

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

function process() {
  var valid = [];

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

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

  });

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

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

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

    var lang = a.language;
    if (/ b.lang) return 1;
    if (a.lang < b.lang) return -1;
    return 0;
  });

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

}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body { text-align: left !important}

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

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

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
Ruby, <s>42</s> 36 bytes

-3 bytes from @MartinEnder, -3 bytes from @xsot

Try it online!

```<code>a=*?A..?Z
a.map{puts a*'';a.rotate!}
</code>```

Title: Print a Tabula Recta!

Body:
Ruby, <s>42</s> 36 bytes

-3 bytes from @MartinEnder, -3 bytes from @xsot

Try it online!

a=*?A..?Z
a.map{puts a*'';a.rotate!}


答:
///, 220 bytes

```<code>/|/\/\///n/WXY|m/JKL|l/PQRS|k/CDEF|j/ZaNfV|i/MbAeI|h/TUcO|g/GHdB|f/OlTU|e/BkGH|d/ImMbA|c/VnZaN|b/NfVnZ|a/AeImM/ab
ed
kg
DEFgC
EFgCD
FgCDE
gk
HdBkG
de
mi
KLiJ
LiJK
im
ba
fc
lh
QRShP
RShPQ
ShPQR
hl
UcOlT
cf
nj
XYjW
YjWX
jn
</code>```

Try it online!

This was surprisingly non-trivial and I have no clue whether it's optimal.

<s>The only way to golf a problem like this in /// is by extracting common substrings.</s> (Turns out I was wrong.) However, due to the nature of the output it's not at all clear which substrings should best be extracted since you can't actually extract the entire alphabet due to the linebreaks. So you'll need to extract some substrings of the wrapped alphabet, but then there are trade-offs in terms of how long you make the substrings and which ones you choose.

So here's what I did. This is a CJam script which finds all substrings up to length 25 in the given string and for each of them computes how many bytes its extracting would save. Basically if there are N copies of a length-M substring, you'd save (N-1)*(M-1) - 5 substrings, these substrings don't contain slashes. Also, technically, when you've already extract 8 substrings or so, the constant offset at the end reduces to -4, but the script doesn't consider that.

Anyway, here's what I did with the script:

Run the script against the current code (which is initially just the output).

Out of the substrings that yield the largest improvement, pick the shortest one. If there are several, pick the lexicographically smallest (from what I can tell, for the given input this reduces overlaps between substrings).

Replace all occurrences of the chosen substring in the code with an unused lower case letter.

Prepend /x/ABC/ to the code where x is the chosen letter and ABC is the substring.

Repeat until there are no substrings left that would save anything.

At the end, we save a few more bytes by replacing the resulting // with | and prepending /|/\/\// (this is why extracting substrings only costs 4 instead of 5 bytes after the 8th substring or so).

Like I said, I have no clue whether this is optimal and I find the rather irregular-looking result quite interesting. It might be possible to get to a shorter solution by chosing non-optimal (but more) substrings somewhere down the line. I wonder what the complexity class of this problem is...

Title: Print a Tabula Recta!

Body:
The Tabula Recta (sometimes called a 'Vigenere Table'), was created by Johannes Trithemius, and has been used in several ciphers, including all variants of Bellaso's Vigenere cipher and the Trithemius cipher. It looks like this:

```<code>ABCDEFGHIJKLMNOPQRSTUVWXYZ
BCDEFGHIJKLMNOPQRSTUVWXYZA
CDEFGHIJKLMNOPQRSTUVWXYZAB
DEFGHIJKLMNOPQRSTUVWXYZABC
EFGHIJKLMNOPQRSTUVWXYZABCD
FGHIJKLMNOPQRSTUVWXYZABCDE
GHIJKLMNOPQRSTUVWXYZABCDEF
HIJKLMNOPQRSTUVWXYZABCDEFG
IJKLMNOPQRSTUVWXYZABCDEFGH
JKLMNOPQRSTUVWXYZABCDEFGHI
KLMNOPQRSTUVWXYZABCDEFGHIJ
LMNOPQRSTUVWXYZABCDEFGHIJK
MNOPQRSTUVWXYZABCDEFGHIJKL
NOPQRSTUVWXYZABCDEFGHIJKLM
OPQRSTUVWXYZABCDEFGHIJKLMN
PQRSTUVWXYZABCDEFGHIJKLMNO
QRSTUVWXYZABCDEFGHIJKLMNOP
RSTUVWXYZABCDEFGHIJKLMNOPQ
STUVWXYZABCDEFGHIJKLMNOPQR
TUVWXYZABCDEFGHIJKLMNOPQRS
UVWXYZABCDEFGHIJKLMNOPQRST
VWXYZABCDEFGHIJKLMNOPQRSTU
WXYZABCDEFGHIJKLMNOPQRSTUV
XYZABCDEFGHIJKLMNOPQRSTUVW
YZABCDEFGHIJKLMNOPQRSTUVWX
ZABCDEFGHIJKLMNOPQRSTUVWXY
</code>```

I frequently need this, but can't find it anywhere on the internet to copy and paste from. Because the square table is so long, and takes frigging ages to type, your code must be as short as possible.

Rules/Requirements

Each submission should be either a full program or function. If it is a function, it must be runnable by only needing to add the function call to the bottom of the program. Anything else (e.g. headers in C), must be included.

If it is possible, provide a link to a site where your program can be tested.

Your program must not write anything to STDERR.

Standard Loopholes are forbidden.

Your program can output in any case, but it must be printed (not an array or similar).

Scoring

Programs are scored according to bytes, in UTF-8 by default or a different character set of your choice.

Eventually, the answer with the least bytes will win.

Submissions

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

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

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

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

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

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

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

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

Leaderboard

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

/* Configuration */

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

/* App */

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

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

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

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

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

getAnswers();

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

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

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

function process() {
  var valid = [];

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

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

  });

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

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

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

    var lang = a.language;
    if (/ b.lang) return 1;
    if (a.lang < b.lang) return -1;
    return 0;
  });

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

}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body { text-align: left !important}

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

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

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Body:
///, 220 bytes

/|/\/\///n/WXY|m/JKL|l/PQRS|k/CDEF|j/ZaNfV|i/MbAeI|h/TUcO|g/GHdB|f/OlTU|e/BkGH|d/ImMbA|c/VnZaN|b/NfVnZ|a/AeImM/ab
ed
kg
DEFgC
EFgCD
FgCDE
gk
HdBkG
de
mi
KLiJ
LiJK
im
ba
fc
lh
QRShP
RShPQ
ShPQR
hl
UcOlT
cf
nj
XYjW
YjWX
jn

Try it online!

This was surprisingly non-trivial and I have no clue whether it's optimal.

<s>The only way to golf a problem like this in /// is by extracting common substrings.</s> (Turns out I was wrong.) However, due to the nature of the output it's not at all clear which substrings should best be extracted since you can't actually extract the entire alphabet due to the linebreaks. So you'll need to extract some substrings of the wrapped alphabet, but then there are trade-offs in terms of how long you make the substrings and which ones you choose.

So here's what I did. <a href="http://cjam.tryitonline.net/#code=MjYsMj5xZmV3On4kZWB7fl8sKEAoKjUtW1xdfSUkVyVTZipOKg&input=QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVoKQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWkEKQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaQUIKREVGR0hJSktMTU5PUFFSU1RVVldYWVpBQkMKRUZHSElKS0xNTk9QUVJTVFVWV1hZWkFCQ0QKRkdISUpLTE1OT1BRUlNUVVZXWFlaQUJDREUKR0hJSktMTU5PUFFSU1RVVldYWVpBQkNERUYKSElKS0xNTk9QUVJTVFVWV1hZWkFCQ0RFRkcKSUpLTE1OT1BRUlNUVVZXWFlaQUJDREVGR0gKSktMTU5PUFFSU1RVVldYWVpBQkNERUZHSEkKS0xNTk9QUVJTVFVWV1hZWkFCQ0RFRkdISUoKTE1OT1BRUlNUVVZXWFlaQUJDREVGR0hJSksKTU5PUFFSU1RVVldYWVpBQkNERUZHSElKS0wKTk9QUVJTVFVWV1hZWkFCQ0RFRkdISUpLTE0KT1BRUlNUVVZXWFlaQUJDREVGR0hJSktMTU4KUFFSU1RVVldYWVpBQkNERUZHSElKS0xNTk8KUVJTVFVWV1hZWkFCQ0RFRkdISUpLTE1OT1AKUlNUVVZXWFlaQUJDREVGR0hJSktMTU5PUFEKU1RVVldYWVpBQkNERUZHSElKS0xNTk9QUVIKVFVWV1hZWkFCQ0RFRkdISUpLTE1OT1BRUlMKVVZXWFlaQUJDREVGR0hJSktMTU5PUFFSU1QKVldYWVpBQkNERUZHSElKS0xNTk9QUVJTVFUKV1hZWkFCQ0RFRkdISUpLTE1OT1BRUlNUVVYKWFlaQUJDREVGR0hJSktMTU5PUFFSU1RVVlcKWVpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1gKWkFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFk" rel="noreferrer">This is a CJam script which finds all substrings up to length 25 in the given string and for each of them computes how many bytes its extracting would save. Basically if there are N copies of a length-M substring, you'd save (N-1)*(M-1) - 5 substrings, these substrings don't contain slashes. Also, technically, when you've already extract 8 substrings or so, the constant offset at the end reduces to -4, but the script doesn't consider that.

Anyway, here's what I did with the script:

Run the script against the current code (which is initially just the output).

Out of the substrings that yield the largest improvement, pick the shortest one. If there are several, pick the lexicographically smallest (from what I can tell, for the given input this reduces overlaps between substrings).

Replace all occurrences of the chosen substring in the code with an unused lower case letter.

Prepend /x/ABC/ to the code where x is the chosen letter and ABC is the substring.

Repeat until there are no substrings left that would save anything.

At the end, we save a few more bytes by replacing the resulting // with | and prepending /|/\/\// (this is why extracting substrings only costs 4 instead of 5 bytes after the 8th substring or so).

Like I said, I have no clue whether this is optimal and I find the rather irregular-looking result quite interesting. It might be possible to get to a shorter solution by chosing non-optimal (but more) substrings somewhere down the line. I wonder what the complexity class of this problem is...


答:
Python, <s>79</s> 78 Bytes

```<code>lambda x:"+-"[(int(x)<0)!=(int(x[-1])-4<0)]+x[1]+x[1:-1]+str(int(x[-1])-4)[-1]
</code>```

anonymous lambda function, does all of the four parts, then adds them together. Expects input as a string with explicit sign e.g. "+64", output is of the same form. Throws ValueError if the string cannot be converted to an int.

Title: "Break" a number

Body:
Python, <s>79</s> 78 Bytes

lambda x:"+-"[(int(x)<0)!=(int(x[-1])-4<0)]+x[1]+x[1:-1]+str(int(x[-1])-4)[-1]

anonymous lambda function, does all of the four parts, then adds them together. Expects input as a string with explicit sign e.g. "+64", output is of the same form. Throws ValueError if the string cannot be converted to an int.


问:
Count sum of all digits
This challenge is to write a program or script which counts the sum of all digits within the integers from 1 up to and including a given number.

Input, one positive integer.
Output, the sum of digits in that number and all smaller numbers.

Examples:

```<code>Input: 5
Integer Sequence: 1, 2, 3, 4, 5
Sum of Digits: 1 + 2 + 3 + 4 + 5 = 15

Input: 12
Integer Sequence: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
Sum of Digits: 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 1 + 0 + 1 + 1 + 1 + 2 = 51
</code>```

To be clear, this is to count a sum of the digits - not the integers. For single-digit inputs, this will be the same. However, inputs larger than 10 will have different responses. This would be an incorrect response:

```<code>Input: 12
Output: 78
</code>```

Another example, to show the difference:

```<code>Input: 10

Integer Sequence: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Sum of Integers (INCORRECT RESPONSE): 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55

Digit Sequence: 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 0
Sum of Digits (CORRECT RESPONSE): 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 1 + 0 = 46
</code>```

A larger test case (CORRECT RESPONSE):

```<code>Input: 1000000
Output: 27000001
</code>```

Rules & Guidelines:

Submitted code must be a complete program or script - not just a function. If the code requires includes, imports, etc., they must be included in the posted code.

The number must be input by the user - not hard-coded. Input may be received as a command-line argument, file, stdin, or any other means by which your language can take user input.

The code must be able to properly handle inputs at least up to (2^64)-1.

The code should only output the sum.

Submitted programs & scripts should be user-friendly and not wasteful of computer resources (e.g.: they should not declare insanely-large arrays to hold every character). There is no strict bonus or penalty for this, but please be good programmers.

Scoring:

Primary scoring mechanism is by code length. Lower scores are better. The following bonuses and penalties also apply:

-25 Bonus if your code can handle all positive numbers, for example: 1234567891234567891234564789087414984894900000000

-50 Bonus if your code can handle simple expressions, for example 55*96-12. To qualify for this bonus, the code should handle + - / * (addition, subtraction, division, multiplication) operators and enforce order of operations. Division is regular integer division.

The given example (55*96-12) evaluates to 5268. Your code should return the same for either of those inputs - correct answer is 81393.

-10 Bonus if your code qualifies for the -50 bonus and can handle the ^ (exponent) operator.

-100 Bonus if your code qualifies for the -50 bonus and does not use eval or similar to handle expressions.

+300 Penalty if your code relies upon any web resources.

Title: Count sum of all digits

Body:
C, 70 bytes

i,s;t(n){for(i=n;i;)for(n=i--;n;n=(n-n%10)/10)s+=n%10;printf("%d",s);}


问:
Write an interactive Deadfish interpreter
Deadfish is a joke "programming language" with four commands. Because the Esolang page is a bit contradictory and the interpreters on that page don't all work exactly the same, you should implement the following variation:

Specification

There is an accumulator which is at least 16 bits in size, more is allowed but less is not. Negative numbers do not need to be supported. The accumulator is 0 when the program starts.

There are the following two sets of four commands, and your program must support both at the same time.
```
  Standard Deadfish    │   XKCD Variant   │    Meaning
  ─────────────────────┼──────────────────┼────────────────────────────────────
        i              │        x         │    Increment accumulator
        d              │        d         │    Decrement accumulator
        s              │        k         │    Square ( acc = acc * acc )
        o              │        c         │    Output accumulator, as a number
```

If, after executing a command, the accumulator is either -1 or 256, the accumulator must be reset to zero. Note that this is not normal wrap-around. If, say, the accumulator is 20, and the s command is run, the accumulator should be 400 afterward. Similarly, if the accumulator is 257 and the d command is run, the accumulator should become 0.

Any input that isn't one of these commands should be ignored.

Test programs

xiskso should output 0

xiskisc should output 289

I/O

Your program should display a prompt: >>. The prompt must be at the beginning of a new line. It should then read a line of user input, and run the given commands left-to-right. When outputing numbers, the numbers must be separated. I.e., 12 34 is OK, 12,34 is OK,

```<code>12
34
</code>```

is OK, but 1234 is not.

Your program should keep doing this in a loop, at least until EOF is reached.

Example session:

```<code>>> xiskso
0
>> xiskisc
289
>> ddddo ddddo
285
281
>> ddddo ddddo
277
273
>> dddddddo
266
>> dddddddddo
257
>> do
0
>> do
0
>> io
1
>>
</code>```

答:
K, 77 bytes

```<code>  {1">>";0{x*2=-1 256?x:y@x}/("xkcdiso"!7#(1+;{x*x};{-1@$x;x};-1+))@0:0;.z.s`}`
>>xiskso
0
>>xiskisc
289
</code>```

Note this is K4. A K6 solution is slightly longer because the IO verbs are longer, even if everything else is better:

```<code>{""0:">>";0{x*^-1 256?x:y@x}/("xkcdiso"!7#(1+;{x*x};{""0:,$x;x};-1+))@0:"";o`}`
</code>```

""0: prints and returns its argument. Note in K4 we simply apply to 1.

0 f/ args demonstrates reduce with an initial value, i.e. f[f[0;first arg];second arg]…

{x*2=-1 256?x… classifies x into the 0 (for -1), 1 (for 256) and 2 for all other values. 2= means we get 1 for unclassified values and 0 otherwise, multiplying by x is shorter than a conditional. In K6 we can do a little better because {x*^-1 256?x:y@x} relies on the fact that -1 256?x returns 0N (null) and ^ detects nulls.

The "parser" is the map "xkcdiso" instead of the suggested order because 7# will wrap around the four arguments i.e. 7#"abcd" returns "abcdabc" which keeps our table smaller

The map translates "x" and "i" to the projection 1+ which is equivalent to the function {1+x} but shorter.

The map translates "d" to the projection -1+ which is equivalent to the function {-1+x} but shorter.

The map translates "k" and "s" to the function {x*x}

The map translates "c" and "o" to the output function {-1@$x;x} which again in K6 is slightly longer: {""0:,$x;x} but both print its output followed by a newline, and then returns the argument.

.z.s is self-recursion. In K6 we can simply say o` which is shorter.

Body:
K, 77 bytes

  {1">>";0{x*2=-1 256?x:y@x}/("xkcdiso"!7#(1+;{x*x};{-1@$x;x};-1+))@0:0;.z.s`}`
>>xiskso
0
>>xiskisc
289

Note this is K4. A K6 solution is slightly longer because the IO verbs are longer, even if everything else is better:

{""0:">>";0{x*^-1 256?x:y@x}/("xkcdiso"!7#(1+;{x*x};{""0:,$x;x};-1+))@0:"";o`}`

""0: prints and returns its argument. Note in K4 we simply apply to 1.

0 f/ args demonstrates reduce with an initial value, i.e. f[f[0;first arg];second arg]…

{x*2=-1 256?x… classifies x into the 0 (for -1), 1 (for 256) and 2 for all other values. 2= means we get 1 for unclassified values and 0 otherwise, multiplying by x is shorter than a conditional. In K6 we can do a little better because {x*^-1 256?x:y@x} relies on the fact that -1 256?x returns 0N (null) and ^ detects nulls.

The "parser" is the map "xkcdiso" instead of the suggested order because 7# will wrap around the four arguments i.e. 7#"abcd" returns "abcdabc" which keeps our table smaller

The map translates "x" and "i" to the projection 1+ which is equivalent to the function {1+x} but shorter.

The map translates "d" to the projection -1+ which is equivalent to the function {-1+x} but shorter.

The map translates "k" and "s" to the function {x*x}

The map translates "c" and "o" to the output function {-1@$x;x} which again in K6 is slightly longer: {""0:,$x;x} but both print its output followed by a newline, and then returns the argument.

.z.s is self-recursion. In K6 we can simply say o` which is shorter.


答:
Pyke, <s>6</s> 5 bytes

```<code>Sm.bB
</code>```

Try it here!

```<code>product(map(nth_fib, input))
</code>```

Title: Fibonacci-orial

Body:
Definition

Fibonacci sequence F(n), on the positive integers, are defined as such:

```<code>1. F(1) = 1
2. F(2) = 1
3. F(n) = F(n-1) + F(n-2), where n is an integer and n > 2
</code>```

The Fibonacci-orial of a positive integer is the product of [F(1), F(2), ..., F(n)].

Task

Given positive integer n, find the Fibonacci-orial of n.

Specs

The fibonacci-orial of 100 must compute in under 5 seconds on a reasonable computer.

Testcases

```<code>n   Fibonacci-orial of n
1   1
2   1
3   2
4   6
5   30
6   240
7   3120
8   65520
9   2227680
10  122522400
11  10904493600
12  1570247078400
13  365867569267200
14  137932073613734400
15  84138564904377984000
16  83044763560621070208000
17  132622487406311849122176000
18  342696507457909818131702784000
19  1432814097681520949608649339904000
20  9692987370815489224102512784450560000
100 3371601853146468125386964065447576689828006172937411310662486977801540671138589868616500834190029067583665182291701553172011082574587431382310099030394306877775647395167143332483560925112960024644459715300507481235056111434293619038347456390454209587101225261757371666449068625033999573552165524529725467628060170886602001077137613803027158648329335507728698605769992818756765633305318529965186184043999696650407246193257877568825245646129366994079739720698147440310773871269639752334356493678913424390564535389212240038895626811627949132978086070255082668392290037141141291484839596694182152062726390364094447642643912371532491388089634845995941928089653751672688740718152064107169357399466473375804972260594768969952507346694189050233823596316467570584434128052398891223730335019092974935617029638919358286124350711360361279157416837428904150054292406756317837582840596331363581207781793070936765786629772999832857257349696094416616259974304208756997835360702840912518532683324936435856348020736000000000000000000000000
</code>```

References

Obligatory OEIS A003266

OEIS A000045 - Fibonacci sequence

Body:
Pyke, <s>6</s> 5 bytes

Sm.bB

Try it here!

product(map(nth_fib, input))


问:
Decimal concatenation of squares
Premise

One night, I was just contemplating on numbers. I found out about something unique about numbers like 7, 10, 12, 13, and more. They are squares of squares! Meaning, that when squared, are comprised of squares themselves. The OEIS calls them Squares which are a decimal concatenation of two or more squares.

Examples of such numbers include 7 (49 has 22 and 32) 13 (169 has 42 and 32) and 20 (400 has 22 and 02). Other examples include 37, as 1369 is a term as it can be partitioned as 1, 36 and 9. 1444 (382) is a term as it can be partitioned as 1, 4, 4, 4. I asked about this on Math.SE, and it was named after me!

Challenge

Design a program that prints TanMath numbers.  Given the number n (starting at 1), print the nth TanMath number, T(n).

As a code example:

```<code>>> 1
>> 7
</code>```

or

```<code>>> 4
>> 13
</code>```

Reference Python implementation(thanks @MartinBüttner and @Sp3000!):

```<code>from math import sqrt

n = input()

def r(digits, depth):
    z = len(digits)
    if z < 1:
        return (depth > 1)
    else:
        for i in range(1, z+1):
            t = int(digits[:i])
            if sqrt(t).is_integer() and r(digits[i:], depth+1):
                return True
        return False

i=0
t=0
while t < n:
    i += 1

    if r(str(i**2), 0):
        t += 1

print i
</code>```

Here is a list of the first 100 numbers:

7 10 12 13 19 20 21 30 35 37 38 40 41
  44 50 57 60 65 70 80 90 95 97 100 102 105 107 108 110 112 119 120 121
  125 129 130 138 140 150 160 170 180 190 191 200 201 204 205 209 210
  212 220 223 230 240 250 253 260 270 280 285 290 300 305 306 310 315
  320 325 330 340 342 343 345 348 350 360 369 370 375 379 380 390 397
  400 402 405 408 410 413 420 430 440 441 450 460 470 475 480 487

This is a code golf, so the shortest code wins!

Good luck!

答:
Python 3, <s>283</s> 243 bytes

This is a brute-force implementation. Golfing suggestions welcome.

from itertools import*
def t(n):
 a=m=0
 while a<n:m+=1;d=str(m*m);r=range(1,len(d));c=[i*i for i in range(m)];a+=any(all(p in c for p in q)for q in[[int(d[x:y])for x,y in zip((0,)+j,j+(None,))]for i in r for j in combinations(r,i)])
 return m
```

<p><strong>Ungolfed:</strong></p>

<pre class="lang-python prettyprint-override"><code>import itertools
def tanmath(n):
    a = 0
    m = 0
    while a < n:
        m += 1
        d = str(m*m)
        squares = [i*i for i in range(m)]
        z = []
        # partitions code
        for i in range(1, len(d)):
            for j in itertools.combinations(range(1, len(d)), i):
                partition_indices = zip((0,)+j, j+(None,))
                z.append([int(d[x:y]) for x, y in partition_indices]
        # end partitions code
        if any(all(p in squares for p in q) for q in z):
            a += 1
    return m
</code>```

Title: Decimal concatenation of squares

Body:
Python 3, <s>283</s> 243 bytes

This is a brute-force implementation. Golfing suggestions welcome.

from itertools import*
def t(n):
 a=m=0
 while a<n:m+=1;d=str(m*m);r=range(1,len(d));c=[i*i for i in range(m)];a+=any(all(p in c for p in q)for q in[[int(d[x:y])for x,y in zip((0,)+j,j+(None,))]for i in r for j in combinations(r,i)])
 return m

Ungolfed:

import itertools
def tanmath(n):
    a = 0
    m = 0
    while a < n:
        m += 1
        d = str(m*m)
        squares = [i*i for i in range(m)]
        z = []
        # partitions code
        for i in range(1, len(d)):
            for j in itertools.combinations(range(1, len(d)), i):
                partition_indices = zip((0,)+j, j+(None,))
                z.append([int(d[x:y]) for x, y in partition_indices]
        # end partitions code
        if any(all(p in squares for p in q) for q in z):
            a += 1
    return m


答:
Dyalog APL, <s>10</s> 11 bytes

```<code>(↑⍳∘⍴⌽¨⊂)⎕A
</code>```

TryAPL online!

Requires ⎕IO←0 which is standard on many systems.

The generalized 7-char function is just ↑⍳∘⍴⌽¨⊂:

↑ make the following list of strings into a character table:

    ⍳the indices

    ∘ of

    ⍴ the length of the argument, i.e [1, 2, 3, ..., 26]

⌽¨ each rotate

    ⊂ the entire argument

With the argument of ⎕A (uppercase alphabet) we get the desired result, but any argument can be fed to get the corresponding cipher:

```<code>      f←↑⍳∘⍴⌽¨⊂
      f'o+×'
o+×
+×o
×o+
</code>```

In fact, even strings and numbers are allowed:

```<code>      f'Alpha' 'Bravo' 'Charlie' 'Delta'
┌───────┬───────┬───────┬───────┐
│Alpha  │Bravo  │Charlie│Delta  │
├───────┼───────┼───────┼───────┤
│Bravo  │Charlie│Delta  │Alpha  │
├───────┼───────┼───────┼───────┤
│Charlie│Delta  │Alpha  │Bravo  │
├───────┼───────┼───────┼───────┤
│Delta  │Alpha  │Bravo  │Charlie│
└───────┴───────┴───────┴───────┘
      f⍳8
0 1 2 3 4 5 6 7
1 2 3 4 5 6 7 0
2 3 4 5 6 7 0 1
3 4 5 6 7 0 1 2
4 5 6 7 0 1 2 3
5 6 7 0 1 2 3 4
6 7 0 1 2 3 4 5
7 0 1 2 3 4 5 6
</code>```

Title: Print a Tabula Recta!

Body:
Dyalog APL, <s>10</s> 11 bytes

(↑⍳∘⍴⌽¨⊂)⎕A

TryAPL online!

Requires ⎕IO←0 which is standard on many systems.

The generalized 7-char function is just ↑⍳∘⍴⌽¨⊂:

↑ make the following list of strings into a character table:

    ⍳the indices

    ∘ of

    ⍴ the length of the argument, i.e [1, 2, 3, ..., 26]

⌽¨ each rotate

    ⊂ the entire argument

With the argument of ⎕A (uppercase alphabet) we get the desired result, but any argument can be fed to get the corresponding cipher:

      f←↑⍳∘⍴⌽¨⊂
      f'o+×'
o+×
+×o
×o+

In fact, even strings and numbers are allowed:

      f'Alpha' 'Bravo' 'Charlie' 'Delta'
┌───────┬───────┬───────┬───────┐
│Alpha  │Bravo  │Charlie│Delta  │
├───────┼───────┼───────┼───────┤
│Bravo  │Charlie│Delta  │Alpha  │
├───────┼───────┼───────┼───────┤
│Charlie│Delta  │Alpha  │Bravo  │
├───────┼───────┼───────┼───────┤
│Delta  │Alpha  │Bravo  │Charlie│
└───────┴───────┴───────┴───────┘
      f⍳8
0 1 2 3 4 5 6 7
1 2 3 4 5 6 7 0
2 3 4 5 6 7 0 1
3 4 5 6 7 0 1 2
4 5 6 7 0 1 2 3
5 6 7 0 1 2 3 4
6 7 0 1 2 3 4 5
7 0 1 2 3 4 5 6


问:
Count of "a"s and "b"s must be equal. Did you get it computer?
In the popular (and essential) computer science book, An Introduction to Formal Languages and Automata by Peter Linz, the following formal language is frequently stated:

$$\large{L=\{a^n b^n:n\in\mathbb{Z}^+\}}$$

mainly because this language can not be processed with finite-state automata.
This expression mean "Language L consists all strings of 'a's followed by 'b's, in which the number of 'a's and 'b's are equal and non-zero".

Challenge

Write a working program/function which gets a string, containing "a"s and "b"s only, as input and returns/outputs a truth value, saying if this string is valid the formal language L.

Your program cannot use any external computation tools, including network, external programs, etc. Shells are an exception to this rule; Bash, e.g., can use command line utilities.

Your program must return/output the result in a "logical" way, for example: returning 10 instead of 0, "beep" sound, outputting to stdout etc. More info here.

Standard code golf rules apply.

This is a code-golf. Shortest code in bytes wins. Good luck!

Truthy test cases

```<code>"ab"
"aabb"
"aaabbb"
"aaaabbbb"
"aaaaabbbbb"
"aaaaaabbbbbb"
</code>```

Falsy test cases

```<code>""
"a"
"b"
"aa"
"ba"
"bb"
"aaa"
"aab"
"aba"
"abb"
"baa"
"bab"
"bba"
"bbb"
"aaaa"
"aaab"
"aaba"
"abaa"
"abab"
"abba"
"abbb"
"baaa"
"baab"
"baba"
"babb"
"bbaa"
"bbab"
"bbba"
"bbbb"
</code>```

Leaderboard

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

/* Configuration */

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

/* App */

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

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

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

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

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

getAnswers();

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

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

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

function process() {
  var valid = [];

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

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

  });

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

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

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

    var lang = a.language;
    if (/ b.lang) return 1;
    if (a.lang < b.lang) return -1;
    return 0;
  });

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

}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body { text-align: left !important}

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

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

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
K, 10 bytes

```<code>~/1_'-':'=
</code>```

Note this is a function, so it needs to be called:

```<code>  ~/1_'-':'="aaaaaabbbbbb"
1
  ~/1_'-':'="aba"
0
</code>```

= groups its arguments, so ="aaaaaabbbbbb" produces "ab"!(0 1 2 3 4 5;6 7 8 9 10 11) and ="aba" returns "ab"!(0 2;,1)

-':' is minus eachprior each. -': is a good way to find out if a series is increasing (or decreasing). -':'="aaaaaabbbbbb" gives us "ab"!(0 1 1 1 1 1;6 1 1 1 1 1) and -':'="aba" gives us "ab"!(0 2;,1)

1_' is one drop each which pops the first element off each list.

~/ is match over.

Body:
K, 10 bytes

~/1_'-':'=

Note this is a function, so it needs to be called:

  ~/1_'-':'="aaaaaabbbbbb"
1
  ~/1_'-':'="aba"
0

= groups its arguments, so ="aaaaaabbbbbb" produces "ab"!(0 1 2 3 4 5;6 7 8 9 10 11) and ="aba" returns "ab"!(0 2;,1)

-':' is minus eachprior each. -': is a good way to find out if a series is increasing (or decreasing). -':'="aaaaaabbbbbb" gives us "ab"!(0 1 1 1 1 1;6 1 1 1 1 1) and -':'="aba" gives us "ab"!(0 2;,1)

1_' is one drop each which pops the first element off each list.

~/ is match over.


问:
Print/Output the L-phabet
Inspired by George Gibson's Print a Tabula Recta.

You are to print/output this exact text:

```<code>ABCDEFGHIJKLMNOPQRSTUVWXYZ
BBCDEFGHIJKLMNOPQRSTUVWXYZ
CCCDEFGHIJKLMNOPQRSTUVWXYZ
DDDDEFGHIJKLMNOPQRSTUVWXYZ
EEEEEFGHIJKLMNOPQRSTUVWXYZ
FFFFFFGHIJKLMNOPQRSTUVWXYZ
GGGGGGGHIJKLMNOPQRSTUVWXYZ
HHHHHHHHIJKLMNOPQRSTUVWXYZ
IIIIIIIIIJKLMNOPQRSTUVWXYZ
JJJJJJJJJJKLMNOPQRSTUVWXYZ
KKKKKKKKKKKLMNOPQRSTUVWXYZ
LLLLLLLLLLLLMNOPQRSTUVWXYZ
MMMMMMMMMMMMMNOPQRSTUVWXYZ
NNNNNNNNNNNNNNOPQRSTUVWXYZ
OOOOOOOOOOOOOOOPQRSTUVWXYZ
PPPPPPPPPPPPPPPPQRSTUVWXYZ
QQQQQQQQQQQQQQQQQRSTUVWXYZ
RRRRRRRRRRRRRRRRRRSTUVWXYZ
SSSSSSSSSSSSSSSSSSSTUVWXYZ
TTTTTTTTTTTTTTTTTTTTUVWXYZ
UUUUUUUUUUUUUUUUUUUUUVWXYZ
VVVVVVVVVVVVVVVVVVVVVVWXYZ
WWWWWWWWWWWWWWWWWWWWWWWXYZ
XXXXXXXXXXXXXXXXXXXXXXXXYZ
YYYYYYYYYYYYYYYYYYYYYYYYYZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZ
</code>```

(Yes, I typed that by hand)

You are allowed to use all lowercase instead of all uppercase.

However, your choice of case must be consistent throughout the whole text.

Rules/Requirements

Each submission should be either a full program or function. If it is a function, it must be runnable by only needing to add the function call to the bottom of the program. Anything else (e.g. headers in C), must be included.

If it is possible, provide a link to a site where your program can be tested.

Your program must not write anything to STDERR.

Standard Loopholes are forbidden.

Your program can output in any case, but it must be printed (not an array or similar).

Scoring

Programs are scored according to bytes, in UTF-8 by default or a different character set of your choice.

Eventually, the answer with the least bytes will win.

Submissions

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

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

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

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

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

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

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

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

Leaderboard

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

/* Configuration */

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

/* App */

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

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

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

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

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

getAnswers();

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

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

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

function process() {
  var valid = [];

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

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

  });

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

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

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

    var lang = a.language;
    if (/ b.lang) return 1;
    if (a.lang < b.lang) return -1;
    return 0;
  });

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

}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body { text-align: left !important}

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

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

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
MATL, 10 bytes

```<code>lY2t!2$X>c
</code>```

Online demo (If you have issues with this interpreter, ping me in the MATL chat. Also, here is the TIO link in case you have issues)

Explanation

```<code>lY2     % Push an array of characters to the stack: 'AB...Z'
t!      % Duplicate and transpose
2$X>    % Take the element-wise maximum between these two (with expansion)
c       % Explicitly convert back to characters
        % Implicitly display the result.
</code>```

Title: Print/Output the L-phabet

Body:
MATL, 10 bytes

lY2t!2$X>c

Online demo (If you have issues with this interpreter, ping me in the MATL chat. Also, here is the TIO link in case you have issues)

Explanation

lY2     % Push an array of characters to the stack: 'AB...Z'
t!      % Duplicate and transpose
2$X>    % Take the element-wise maximum between these two (with expansion)
c       % Explicitly convert back to characters
        % Implicitly display the result.