问:
Count the Unique Rectangles!
In my last challenge, you were asked to find all rectangles given a m x n grid of them. However, it turned out to be very trivial as there actually was a mathematical formula I did not even know about to solve the problem! So now, for a little bit more of a challenge, how about calculating the number of unique rectangles, i.e. find the number rectangles that are all of different dimensions?

For example, consider 4 horizontal, or y lines at [-250,-50,50,250] and 4 vertical, or x lines at [-250,-70,70,250]. Graphing these on a coordinate plane with infinite dimensions results in the following 500 x 500 pixel closed grid, in which the length of each segment in pixels and the lines corresponding to their respected values from the arrays are shown:

which contains the 16 unique rectangles shown in this animated GIF:

However, if the topmost line (y = 250) were to be removed, there would only be 12 unique rectangles, as the top 3 rectangles would be factored out since they each won't be fully closed without the y = 250 line.

Task

So, as shown above, the task is counting the number of rectangles rectangles with different dimensions. In other words, given an input of 2 arrays, with the first one containing all equations of all x lines, and the latter containing those of all y lines, output the total number of rectangles of different dimensions created when the lines corresponding to those equations are graphed on a coordinate plane.

Rules

The use of any built-ins that directly solve this problem is explicitly disallowed.

If either of the arrays have less than 2 elements, the output should be 0, since if there are less than 4 lines on the plane, there are no closed, 4 sided figures.

The input arrays are not guaranteed to be sorted.

You can assume that there are not any repeated values in either of the the input arrays.

A n x m rectangle is the same as a m x n rectangle. For example, a 300 x 200 rectangle is the same as a 200 x 300 one.

Standard loopholes are prohibited.

Test Cases

Given in the format Comma Separated Arrays Input -> Integer output:

```<code>[],[] -> 0
[-250,-50,50,250],[-250,-70,70,250] -> 16 (Visualized above)
[-250,-50,50,250],[-250,-70,70] -> 12
[-40, 40],[-80, 50] -> 1
[10],[10] -> 0
[60, -210, -60, 180, 400, -400], [250, -150] -> 12
[0,300,500],[0,300,500] -> 6
[0,81,90],[0,90,100] -> 9
</code>```

Remember, this is code-golf, so shortest code wins!

答:
Jelly, 13 bytes

```<code>ṢIẆS€µ€ŒpṢ€QL
</code>```

Try it online!

A rectangle is uniquely defined by its height and its width.

```<code>ṢIẆS€µ€ŒpṢ€QL   Main chain, argument: z

     µ€         For each subarray:
Ṣ                   sort
 I                  compute consecutive increments
  Ẇ                 yield all substrings
   S€               compute sum of each substring
       Œp       Cartesian product
         Ṣ€     Sort each
           Q    Remove duplicates
            L   Length
</code>```

Title: Count the Unique Rectangles!

Body:
Jelly, 13 bytes

ṢIẆS€µ€ŒpṢ€QL

Try it online!

A rectangle is uniquely defined by its height and its width.

ṢIẆS€µ€ŒpṢ€QL   Main chain, argument: z

     µ€         For each subarray:
Ṣ                   sort
 I                  compute consecutive increments
  Ẇ                 yield all substrings
   S€               compute sum of each substring
       Œp       Cartesian product
         Ṣ€     Sort each
           Q    Remove duplicates
            L   Length


问:
Hofstadter H-sequence

Definition

\$a(0) = 0\$

\$a(n) = n-a(a(a(n-1)))\$ for integer \$n > 0\$

Task

Given non-negative integer \$n\$, output \$a(n)\$.

Testcases

```<code>n     a(n)
0     0
1     1
2     1
3     2
4     3
5     4
6     4
7     5
8     5
9     6
10    7
11    7
12    8
13    9
14    10
15    10
16    11
17    12
18    13
19    13
20    14
10000 6823
</code>```

References

WolframMathWorld

OEIS A005374

答:
VBA, 69 bytes

```<code>Function H(N):ReDim G(N):For j=1To N:G(j)=j-G(G(G(j-1))):Next:H=G(N)
</code>```

Works in the blink of an eye on the test set, slows down a little above n=1000000, runs into a memory wall a little above n=25 million.

ContentLicense: CC BY-SA 4.0

Title: Hofstadter H-sequence

Body:
VBA, 69 bytes

Function H(N):ReDim G(N):For j=1To N:G(j)=j-G(G(G(j-1))):Next:H=G(N)

Works in the blink of an eye on the test set, slows down a little above n=1000000, runs into a memory wall a little above n=25 million.

ContentLicense: CC BY-SA 3.0


问:
Alphabet triangle
You are to print this exact text:

```<code>A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
ABCDEFGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYZYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGFEDCBA
ABCDEFEDCBA
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A
</code>```

Specs

Extra trailing newlines are allowed at the end of the output.

Extra trailing spaces (U+0020) are allowed at the end of each line, including the extra trailing newlines.

You can use all lowercase instead of all uppercase, but you cannot print partially lowercase partially uppercase.

You can return the text as a function output instead of printing it in a full program.

Scoring

Since this is a triangle, and a triangle has 3 sides, and 3 is a small number, your code should be small in terms of byte-count.

答:
J, <s>26</s> <s>23</s> 22 bytes

```<code>f(f=:,1}.|.)\u:65+i.26
</code>```

Explanation

```<code>,1}.|.  Monad f: Input: A
    |.  Reverse the items in A
 1}.    Drop the first item in the reversed A
,       Join A and the previous

f(f=:,1}.|.)\u:65+i.26
                  i.26  Create the range [0, 1, ..., 25]
               65+      Add 65 to each
             u:         Convert to characters to get 'A..Z'
  f=:,1}.|.             Define a verb f
 (         )\           Call f monadically on each prefix of 'A..Z'
f                       Call f again on that result
</code>```

Title: Alphabet triangle

Body:
J, <s>26</s> <s>23</s> 22 bytes

f(f=:,1}.|.)\u:65+i.26

Explanation

,1}.|.  Monad f: Input: A
    |.  Reverse the items in A
 1}.    Drop the first item in the reversed A
,       Join A and the previous

f(f=:,1}.|.)\u:65+i.26
                  i.26  Create the range [0, 1, ..., 25]
               65+      Add 65 to each
             u:         Convert to characters to get 'A..Z'
  f=:,1}.|.             Define a verb f
 (         )\           Call f monadically on each prefix of 'A..Z'
f                       Call f again on that result


问:
Create and write to a file

Challenge

Create a new file and write the string Hello World to it.

Restrictions

Your challenge must write to a file on disk, in the file system.

The file may not be a log file generated during normal operation of the interpreter.

The file must contain only the string Hello World. It is allowed to contain a trailing newline or minimal whitespace. No other content.

No command-line flags/pipes (etc) allowed, except when necessary to run the program. (e.g. perl -p)

Notes

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

Follow the spirit, not the letter, of the rules.

答:
Common Lisp, 69 bytes

Lauded for being incredibly expressive, it's not the best golfing language...

```<code>(with-open-file (f "f" :direction :output) (format f "Hello, world"))
</code>```

See it work, with permission denied.

Title: Create and write to a file

Body:
Common Lisp, 69 bytes

Lauded for being incredibly expressive, it's not the best golfing language...

(with-open-file (f "f" :direction :output) (format f "Hello, world"))

See it work, with permission denied.


答:
Javascript(using external library-Enumerable), 135 bytes

```<code>_.Range(1,51).WriteLine(x=>(g=_.Range(65,x>25?52-x:x)).Write("",y=>(w=String.fromCharCode)(y))+(g.Reverse().Skip(1).Write("",y=>w(y))))
</code>```

Link to the library: https://github.com/mvegh1/Enumerable

Code explanation: Create a range of ints starting at 1, for a count of 51. For each, write a line according to complex pred. Do some JS wizardry with global variables and caching...and voila. For each int in WriteLine, we are creating the left hand range of ints and storing into global "g", and String Joining (Write) with "" delimiter and mapping each int to the String mapping to the int char code. Then, we concat the right hand side by taking the reversal of that sequence (and skipping the first element because that will match the last element of the original order...), writing with the same logic. EDIT: Updated the internals of Write in the library. An empty sequence will write an empty string instead of null now. This also shaved 15 bytes off the answer

Title: Alphabet triangle

Body:
You are to print this exact text:

```<code>A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
ABCDEFGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYZYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGFEDCBA
ABCDEFEDCBA
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A
</code>```

Specs

Extra trailing newlines are allowed at the end of the output.

Extra trailing spaces (U+0020) are allowed at the end of each line, including the extra trailing newlines.

You can use all lowercase instead of all uppercase, but you cannot print partially lowercase partially uppercase.

You can return the text as a function output instead of printing it in a full program.

Scoring

Since this is a triangle, and a triangle has 3 sides, and 3 is a small number, your code should be small in terms of byte-count.

Body:
Javascript(using external library-Enumerable), 135 bytes

_.Range(1,51).WriteLine(x=>(g=_.Range(65,x>25?52-x:x)).Write("",y=>(w=String.fromCharCode)(y))+(g.Reverse().Skip(1).Write("",y=>w(y))))

Link to the library: https://github.com/mvegh1/Enumerable

Code explanation: Create a range of ints starting at 1, for a count of 51. For each, write a line according to complex pred. Do some JS wizardry with global variables and caching...and voila. For each int in WriteLine, we are creating the left hand range of ints and storing into global "g", and String Joining (Write) with "" delimiter and mapping each int to the String mapping to the int char code. Then, we concat the right hand side by taking the reversal of that sequence (and skipping the first element because that will match the last element of the original order...), writing with the same logic. EDIT: Updated the internals of Write in the library. An empty sequence will write an empty string instead of null now. This also shaved 15 bytes off the answer


答:
Haskell, 58 bytes

f x=init x++reverse x
t=unlines$f[f['A'..c]|c<-['A'..'Z']]
```

<p>Defines a function <code>t</code> that returns the output as a string.</p>

<pre class="lang-hs prettyprint-override"><code>f x=               define a helper function
init x             take the argument minus its last element
++                 and concatenate it with
reverse x          the argument reversed, producing ex. [a,b,c,b,a] from [a,b,c]

t=                                    define the main function
           [         |c<-['A'..'Z']]  for every char c from 'A' to 'Z'...
             ['A'..c]                 generate the range from 'A' to c
            f                         call the helper function to "reflect" it
          f                           call the helper function on the entire list
  unlines$                            join on newlines
</code>```

Title: Alphabet triangle

Body:
Haskell, 58 bytes

f x=init x++reverse x
t=unlines$f[f['A'..c]|c<-['A'..'Z']]

Defines a function t that returns the output as a string.

f x=               define a helper function
init x             take the argument minus its last element
++                 and concatenate it with
reverse x          the argument reversed, producing ex. [a,b,c,b,a] from [a,b,c]

t=                                    define the main function
           [         |c<-['A'..'Z']]  for every char c from 'A' to 'Z'...
             ['A'..c]                 generate the range from 'A' to c
            f                         call the helper function to "reflect" it
          f                           call the helper function on the entire list
  unlines$                            join on newlines


问:
Snakes all around

Challenge

The challenge is simple: print a snake.

You will get the length of the snake as input.

A snake of length 2 looks like this:

```<code>==(:)-
</code>```

A snake of length 7 looks like this:

```<code>=======(:)-
</code>```

In other words, the length of a snake is how many equal signs are before the head.

Usage

Let's say I made a C++ implementation and compiled it to ./getsnake.

I could run it like so:

```<code>$ ./getsnake 10
==========(:)-
</code>```

Clarifications

Standard loopholes are disallowed.

You can get input and output in any acceptable way.

You can assume all inputs given are positive integers.

You may write a function instead of a regular program.

答:
Java 1.7, 46 bytes

A recursive (and shorter) alternative to the iterative and 'replace' versions.

```<code>String f(int n){return n>0?"="+f(--n):"(:)-";}
</code>```

Run it here.

This function first builds the n tail elements recursively, then appends the head.

Title: Snakes all around

Body:
Java 1.7, 46 bytes

A recursive (and shorter) alternative to the iterative and 'replace' versions.

String f(int n){return n>0?"="+f(--n):"(:)-";}

Run it here.

This function first builds the n tail elements recursively, then appends the head.


答:
Ruby, 71 bytes

Try it on repl.it

```<code>s=*?A..?Y
s+=[?Z]+s.reverse
puts s.map{|e|k=[*?A...e]*'';k+e+k.reverse}
</code>```

Title: Alphabet triangle

Body:
Ruby, 71 bytes

Try it on repl.it

s=*?A..?Y
s+=[?Z]+s.reverse
puts s.map{|e|k=[*?A...e]*'';k+e+k.reverse}


答:
VBA, 94 bytes

```<code>Function T:For j=-25To 25:k=25-Abs(j):For i=-k To k:T=T &Chr(65+k-Abs(i)):Next:T=T &vbLf:Next
</code>```

Call in Immediate window with ?T

Just to explain what's going on: I use Abs function twice, to reflect both the alphabet traverse and the line length. It's well suited to the task because of the single extreme value in both cases, which corresponds to the zero crossing of the pre-Abs variable.

As a simple set of commands in VBA Immediate window, rather than a program or function, the following would need 72 bytes:

```<code>For j=-25To 25:k=25-Abs(j):For i=-k To k:?Chr(65+k-Abs(i));:Next:?:Next
</code>```

(with thanks to @GuitarPicker)

Title: Alphabet triangle

Body:
VBA, 94 bytes

Function T:For j=-25To 25:k=25-Abs(j):For i=-k To k:T=T &Chr(65+k-Abs(i)):Next:T=T &vbLf:Next

Call in Immediate window with ?T

Just to explain what's going on: I use Abs function twice, to reflect both the alphabet traverse and the line length. It's well suited to the task because of the single extreme value in both cases, which corresponds to the zero crossing of the pre-Abs variable.

As a simple set of commands in VBA Immediate window, rather than a program or function, the following would need 72 bytes:

For j=-25To 25:k=25-Abs(j):For i=-k To k:?Chr(65+k-Abs(i));:Next:?:Next

(with thanks to @GuitarPicker)


问:
Score a game of Yahtzee
For each of the 13 rows of a Yahtzee scoresheet you are given (from stdin)
a space separated list of 5 numbers (dice).
Your task is to calculate the score for each line and output the Grand Total of the game.

Example

Input and how to interpret it:

```<code>Input       Box              Score
6 1 4 1 3   Aces              2
3 2 2 1 2   Twos              6
6 3 2 3 3   Threes            9
4 2 3 6 5   Fours             4
6 3 5 5 1   Fives            10
1 5 6 5 6   Sixes            12
            Bonus             -
4 2 4 4 1   3 of a kind      15
2 2 3 2 4   4 of a kind       -
3 2 2 2 3   Full house       25
1 3 1 6 1   Small straight    -
2 5 4 6 3   Large straight   40
2 2 2 2 2   Yahtzee          50
5 5 4 5 2   Chance           21
            Grand Total     194
</code>```

We will disregard the Yahtzee Bonus and Joker rules, and only sum up the scores from the Upper and Lower Section and the Bonus in the Upper Section. If in doubt, refer to these rules.

May the shortest code win!

答:
GolfScript 180

```<code>n/{~]}%6,{)`['{''=},,''*']*}%[{.{+}*\{..|{'{'\'=},,'++1$\~}%$\;}:g~)\;2>*}{.{+}*\g)\;3>*}{g[2 3]=25*}{$:§;3,{).4+,\>§-}%1?)!!30*}{.$(\;.5+,\>\-!40*}{g)\;5=50*}{{+}*}]+]zip{~~}%{+}*
</code>```

You can test the program here

Annotated program:

```<code>n/                          # split input by newline
{~]}%                       # parse an int array from each line

6,{)`['{''=},,''*']*}%      # create {X=},,X* code blocks,
                            # where X goes from 1 to 6
                            # (needed for processing the first
                            # half of the board)

[       # create an array of code blocks, for scoring:

        # three of a kind:
    {.{+}*\{..|{'{'\'=},,'++1$\~}%$\;}:g~)\;2>*}

        # four of a kind:
    {.{+}*\g)\;3>*}

        # full house:
    {g[2 3]=25*}

        # small straight:
    {$:§;3,{).4+,\>§-!}%1?)!!30*}

        # straight:
    {.$(\;.5+,\>\-!40*}

        # yahtzee:
    {g)\;5=50*}

        #chance:
    {{+}*}
]+              # concatenate the 1-6 code block array with this one

]zip            # distribute each line in the input
                # to the corresponding scoring rule (code block)

{~~}%           # evaluate each input/code pair
                # and get an array with score for each hand

{+}*            # sum up the partial scores.
</code>```

Title: Score a game of Yahtzee

Body:
GolfScript 180

n/{~]}%6,{)`['{''=},,''*']*}%[{.{+}*\{..|{'{'\'=},,'++1$\~}%$\;}:g~)\;2>*}{.{+}*\g)\;3>*}{g[2 3]=25*}{$:§;3,{).4+,\>§-}%1?)!!30*}{.$(\;.5+,\>\-!40*}{g)\;5=50*}{{+}*}]+]zip{~~}%{+}*

You can test the program <a href="http://golfscript.apphb.com/?c=Oyc2IDEgNCAxIDMKMyAyIDIgMSAyCjYgMyAyIDMgMwo0IDIgMyA2IDUgIAo2IDMgNSA1IDEKMSA1IDYgNSA2CjQgMiA0IDQgMQoyIDIgMyAyIDQKMyAyIDIgMiAzICAKMSAzIDEgNiAxCjIgNSA0IDYgMwoyIDIgMiAyIDIKNSA1IDQgNSAyJwoKbi97fl19JTYseylgWyd7Jyc9fSwsJycqJ10qfSVbey57K30qXHsuLnx7J3snXCc9fSwsJysrMSRcfn0lJFw7fTpnfilcOzI%2bKn17LnsrfSpcZylcOzM%2bKn17Z1syIDNdPTI1Kn17JDrCpzszLHspLjQrLFw%2bwqctfSUxPykhITMwKn17LiQoXDsuNSssXD5cLSE0MCp9e2cpXDs1PTUwKn17eyt9Kn1dK116aXB7fn59JXsrfSo=&run=true" rel="nofollow">here

Annotated program:

n/                          # split input by newline
{~]}%                       # parse an int array from each line

6,{)`['{''=},,''*']*}%      # create {X=},,X* code blocks,
                            # where X goes from 1 to 6
                            # (needed for processing the first
                            # half of the board)

[       # create an array of code blocks, for scoring:

        # three of a kind:
    {.{+}*\{..|{'{'\'=},,'++1$\~}%$\;}:g~)\;2>*}

        # four of a kind:
    {.{+}*\g)\;3>*}

        # full house:
    {g[2 3]=25*}

        # small straight:
    {$:§;3,{).4+,\>§-!}%1?)!!30*}

        # straight:
    {.$(\;.5+,\>\-!40*}

        # yahtzee:
    {g)\;5=50*}

        #chance:
    {{+}*}
]+              # concatenate the 1-6 code block array with this one

]zip            # distribute each line in the input
                # to the corresponding scoring rule (code block)

{~~}%           # evaluate each input/code pair
                # and get an array with score for each hand

{+}*            # sum up the partial scores.


问:
How Many Rectangles in the Grid?

Well, although this challenge turned out to be a huge success, it also turned out to be very trivial to solve. Therefore, for those of looking for more of a challenge, I created a sequel to this challenge in which you must now count the number of unique rectangles. Check it out!

Now, for those of you looking to solve this challenge, here it comes.

Well, we don't really have a challenge like this yet, so here we go.

Consider this 3 x 3 grid of rectangles:

How many rectangles are there? Well, counting visually, we can see that there are actually 36 rectangles, including the entire plane itself, which are all shown in the animated GIF below:

The Task

The counting of rectangles as shown above is the task. In other words, given 2 integers greater than or equal to 0, m and n, where m represents the width and n represents the height, output the total number of rectangles in that m x n grid of rectangles.

Rules

The use of any built-ins that directly solve this problem is explicitly disallowed.

This challenge is not about finding the shortest answer, but finding the shortest answer in every language. Therefore, no answer will be accepted.

Standard loopholes are prohibited.

Test Cases

Presented in the format Array of Integers Input -> Integer Output:

```<code>[0,0] -> 0
[1,1] -> 1
[3,3] -> 36 (Visualized above)
[4,4] -> 100
[6,7] -> 588
</code>```

References

http://oeis.org/A096948

Remember, this is code-golf, so shortest code wins!

答:
Convex, 7 bytes

I know that this can be smaller, I just can't figure out how yet...

```<code>_:)+×½½
</code>```

Try it online!. Uses the CP-1252 encoding.

Title: How Many Rectangles in the Grid?

Body:
Convex, 7 bytes

I know that this can be smaller, I just can't figure out how yet...

_:)+×½½

Try it online!. Uses the CP-1252 encoding.


答:
Pyth, 10 bytes

```<code>L-WbbyFtb3
</code>```

Defines a function y. Try it online: Demonstration

This uses a relative new feature of Pyth. You can apply a function multiple times using the fold-syntax. It doesn't actually save any bytes, I used it just for demonstration purposes.

Explanation:

```<code>L-WbbyFtb3
L            define function y(b), that returns:
    b           b
 -Wb            and subtract the following if b>0
     yF  3      y applied three times to
       tb       b - 1
</code>```

Title: Hofstadter H-sequence

Body:
Definition

\$a(0) = 0\$

\$a(n) = n-a(a(a(n-1)))\$ for integer \$n > 0\$

Task

Given non-negative integer \$n\$, output \$a(n)\$.

Testcases

```<code>n     a(n)
0     0
1     1
2     1
3     2
4     3
5     4
6     4
7     5
8     5
9     6
10    7
11    7
12    8
13    9
14    10
15    10
16    11
17    12
18    13
19    13
20    14
10000 6823
</code>```

References

WolframMathWorld

OEIS A005374

Body:
Pyth, 10 bytes

L-WbbyFtb3

Defines a function y. Try it online: Demonstration

This uses a relative new feature of Pyth. You can apply a function multiple times using the fold-syntax. It doesn't actually save any bytes, I used it just for demonstration purposes.

Explanation:

L-WbbyFtb3
L            define function y(b), that returns:
    b           b
 -Wb            and subtract the following if b>0
     yF  3      y applied three times to
       tb       b - 1


问:
Leo's Pokerface

Pokerface

Introduction

Leo enjoys playing poker, but his job at Tech Inc. is too demanding for him to learn how to play well. Leo, being a computer scientist, is not discouraged. He decides to take more time than it would have taken to just learn poker, and use it to write a poker bot to help him play better. But now Leo has a problem: in order to understand how to play a bit better, Leo needs to observe multiple games of multiple "people," but the "people" need different play styles to improve the quality and reality of the game.

The Challenge

Leo recalls that there is actually a website dedicated to programming challenges, and is enlisting your help! Your job is to write a program which plays "Pokerface" a modified version of 5-card poker. The program will take input as a 5-card hand in whatever format you wish, after which the program will output:

Exactly (case-sensitive) "true" "1" or "t" if the player wishes to exchange cards, any other non-empty output otherwise.

If true, list of indices of cards and/or card names the player wishes to exchange.

A single number between 0 and 3, which specifies how many additional cards the player wants.

Print out the hand the player wishes to use.

(See formatting below)

Pokerface rules

Since pokerface is a text-based adventure game, cards must be presented in a consistent way. Cards are represented by two character codes, the first character is the suit, and the second is the name of the card.

Cards:

2-9 = 2-9

10 = T

Jack = J

Queen = Q

King = K

Ace = A

Suits:

Spades = S

Clubs = C

Hearts = H

Diamond = D

So the ace of spades would be SA, the 10 of hearts is HT, the 4th of diamonds is D4, etc.

A single round of Pokerface consists of four steps:

The deck is reshuffled and a five card hand is dealt to each player.

Each player is given the chance to exchange as many cards as they want.

Each player is given the chance to gain up to three more cards.

Each player must reveal their best hand.

The best hand wins, and gains that player a point. In the event of a tie, both players get a point.

In a single game, ten rounds are played and the player with the most points wins and gains a single "win point." In the event of a tie, both players gain a win point.

Leo doesn't really have a large amount of money, so your bot can assume that this is a perfect world with no betting.

Hands

Hands are exactly 5 cards in length (initial input and final output).

Hands are ranked consistent with the rules described here.

Input / Output

Leo only knows Java, so your program must be executable via the Process API (command line), and use STDIN and STDOUT for input and output, respectively.

For each step of input and output detailed above, the input and output must each exist on one line.

There must be at least one trailing new line after the final output. (This is due to the way input is read from STDIN)

No extraneous input/output is allowed, other than trailing and leading spaces. The parser simply does not understand things like final_hand=... or draw 0.

When drawing, output is a single integer, when exchanging output is a list of integers and/or cards defined below, and when being dealt the original hand, output is a list of cards defined below.

All input/output numbers must be positive integers in base 10.

You may define the format for card input (see post format below).

True is defined as exactly "true," "1" or "t" and false is any other non-empty value.

During the exchange step:

Card indices must be output with at least one space between them (e.g. 3  4    0)

Card names must be output with at least one space between them (e.g. H4 S8)

Card names and indices may be mixed in the output (e.g. 0 H7 3 D3)

Trailing and leading spaces are allowed.

The input as a result of the player outputting the above will be formatted as specified by the bot.jlsc file, in the same order as requested

The number of cards a player wants to add to their hand can have leading and trailing spaces.

Hands must be output with at least one space between them (e.g. H4 D5  CA), trailing spaces and leading spaces are allowed.

Hands do not need to be output in proper order (e.g. H4 D4 C4 DA SA and H4 DA D4 SA C4 both represent 4, 4, 4, Ace, Ace, which is a full house).

If you wish to build a strategy by analyzing opponents hands, you may store data in a <botname>/data directory.

After competing bots have displayed their hands, they will be written to every bots data directory, in hands.txt, with each hand on a new line (separated by \n). The file will be encoded in US_ASCII.

After your bot requests new cards or exchange cards, the cards will be input depending on what format you specify in the bot.jlsc file.

Post Format

Every post must include two things:

The source code of your bot, or a link to a public facing repository.

A zip file containing:

The compiled/executable version of your bot (If the file is a .exe or other non-de-compilable file, please just include compilation instructions in your post).

A bot.jlsc file, see below (side note: the .jlsc extension is just because of a side project of mine, a configuration format. The file below matches the proper syntax, so don't worry).

The .zip file must be named the same as your bot.

If you don't have access to windows or some other zipping utility, or can't make a .zip for whatever reason, just include the text of the bot.jlsc file in your post

bot.jlsc file:

```<code>name= "Botty"
link= "example.com"
cmd= "java -jar Botty.jar"
input_hand= "${0} ${1} ${2} ${3} ${4}"
input_1= "${0}"
input_2= "${0} ${1}"
input_3= "${0} ${1} ${2}"
input_4= "${0} ${1} ${2} ${3}"
</code>```

Where:

"cmd" is the windows command line command to run your bot. Note that your bot will be in directory <botname>, so adjust the command accordingly.

"name" is the name of your bot.

"link" is the link to your answer, you'll have to edit this in after posting.

"input_hand" is how you want the original dealing to be formatted (with ${#} representing cards 0-4).

"input_1" is how you want the input of one additional card to be formatted.

"input_2" is how you want the input of two additional cards to be formatted.

"input_3" is how you want the input of three additional cards to be formatted.

"input_4" is how you want the input of four additional cards to be formatted.

Specifics

These loopholes are disallowed (see 'common pitfalls')

You may not write a bot the will always output the best hand possible, every time, within the rule set. (i.e. no long-running brute-force bots, nothing should be quite as 'good' as LeoBot)

Your bot should run in ~100 ms or less (Lenient on this point, max of ~1 second)

Any output of the bot after its chosen hand will be ignored.

Standard loopholes are disallowed.

Yes, I know linux is better, but I have a windows PC, so be sure the compiled/executable version of your program can be run from the windows command line.

I already have python and java installed on my computer, but I'm willing to update to new versions and install other environments, so please specify what type of environment your program requires.

You may not write a bot which does the same thing as another bot in every case. Spam bots are allowed, but discouraged.

Your bot may only use cards it has. Cards lost through exchange or not dealt to begin with are invalid output in the final hand.

Input and output may only contain ASCII characters.

Tournaments

Tournaments will be run when I get the time (my schedule is nearly as packed as Leo's, so this my be a little infrequent. Sorry for the inconvenience.).

Bots will be pit against eachother in 4 person games, and there will be one game for each possible subset of bots (i.e. lots of games).

This process will be repeated five times.

Due to the way the tournament handler makes the groups of bots, up to three filler bots will be added to make the number of bots divisible by 4. These bots will simply return the hand they were originally dealt.

After every round and game is run, the scores of the bots will be computed based on the number games they won.

Multiple bots can share a position (ties for first won by first posted).

After a tournament finishes, the scores will be appended to the bottom of this post.

Scoring

Normal KoTH rules. The bot(s) that win the most games win the challenge.

LeoBot

Leo's bot is pretty smart. It doesn't exchange any cards, that's too hard, but it does request the maximum number of additional cards, and it determines the best possible hand it can make, and plays that hand. The main logic of leobot is below.

```<code>package com.gmail.socraticphoenix.pokerface.leobot;

import com.gmail.socraticphoenix.pokerface.lib.card.Card;
import com.gmail.socraticphoenix.pokerface.lib.card.Deck;
import com.gmail.socraticphoenix.pokerface.lib.rule.HandRegistry;

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

public class LeoBot {

    public static void main(String[] args) {
        List<Card> hand = new ArrayList<>();

        Scanner scanner = new Scanner(System.in);
        hand.addAll(Card.parseHand(scanner.nextLine()));
        System.out.println(false);

        System.out.println(3);
        hand.addAll(Card.parseHand(scanner.nextLine()));

        List<List<Card>> possibleHands = LeoBot.getSubsets(hand, 5);
        System.out.println(Deck.toString(possibleHands.stream().sorted((a, b) -> HandRegistry.determineWinner(b, a).comparable()).findFirst().get()));
    }

    private static <T> void getSubsets(List<T> superSet, int k, int idx, List<T> current, List<List<T>> solution) {
        if (current.size() == k) {
            solution.add(new ArrayList<>(current));
            return;
        }
        if (idx == superSet.size()) return;
        T x = superSet.get(idx);
        if (!current.contains(x)) {
            current.add(x);
        }
        getSubsets(superSet, k, idx + 1, current, solution);
        current.remove(x);
        getSubsets(superSet, k, idx + 1, current, solution);
    }

    public static <T> List<List<T>> getSubsets(List<T> superSet, int k) {
        List<List<T>> res = new ArrayList<>();
        getSubsets(superSet, k, 0, new ArrayList<T>(), res);
        return res;
    }

}
</code>```

Note that if LeoBot consistently wins the tournaments, and there are a good amount of entries, I'll stop including him in the running.

Important Links

Tournament bot and library

Leo's bot

Disclaimer

Leo and Tech Inc. are story elements and any resemblance to real-life companies or people is purely unintentional. (However, when Leo's 'situation' adds or subtracts conditions from the question, those are actually part of the question...)

答:
LadyGaga, Python 3

Is somewhat blind to suits

Has a dress full of bugs

And likes to play Poker Face once in a while

```<code>from math import ceil as f
M=lambda A:max(set(A),key=A.count)
K=lambda A:A.count(M(A))
O=lambda A:range(len(A))
J=lambda A:A[0]+str(U(A[1]))
X={"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"T":10,"J":11,"Q":12,"K":13,"A":14}
def V(A):return([A[0]]+[int(X[A[1]])])
def U(c):
 if c==10:c='T'
 if c==11:c='J'
 if c==12:c='Q'
 if c==13:c='K'
 if c==14:c='A'
 return(c)
def P(A):
 S=[];C=[];t=len(A)
 for x in A:S.append(x[0]);C.append(x[1])
 B=[0]*9;q=len(set(C));p=K(C);D=list(set(C));D.sort()
 B[2]=1/f(13**(4-p));B[6]=1/f(13**(3-p));B[8]=1/f(13**(2-p))
 if (p,q)==(2,4):B[3]=1/1100;B[7]=5/34
 if (p,q)==(3,3):B[3]=1/169;B[7]=1/169
 if (p,q)==(4,2):B[3]=1/13;B[7]=1
 if (p,q)==(2,3):B[3]=5/169;B[7]=1
 if (p,q)==(3,2):B[3]=1;B[7]=1
 for x in O(D):D[x]-=x
 j=M(D);h=K(D)-5;B[5]=13**h
 for x in O(D):
  if j+h<D[x]<j-h and D[x]!=j:B[5]*=13
 W=K(S);B[4]=(4**(W-t))*(13-W)/52
 return(B,M(S))
def E(B,h,u):
 x=0;D=[];C=[]
 while 1:
  k=list(C)
  C=[]
  while 1:
   p=list(B);del p[x]
   if len(D)==3:break
   if P(p)[0][h]>=P(B)[0][h]:C.append(B[x])
   x+=1
   if x>len(p):break
  if len(C)==0:break
  for x in O(C):
   if k==C or not((u in C[x])and(len(C)-1)):D.append(C[x]);del B[B.index(C[x])]
 return(D)
s=input()
A=s.split(' ')
b=list(map(V,A));G,u=P(b);F=[649739,72192,4164,693,508,254,46.3,20,1.4];H=[]
for x in O(F):F[x]=1-((1-(1/F[x]))**4)
for x in O(F):H.append(G[x]-F[x])
Y=H.index(max(H));p=[]
e=E(list(b),Y,u);g=list(e)
for x in O(e):e[x]=J(e[x])
print(' '.join(e)if len(e)else'')
for x in g:
 if x in b:del b[b.index(x)]
s=input()
if len(s):
 A=s.split(' ')
 b+=list(map(V,A))
print(3)
s=input()
A=s.split(' ')
b+=list(map(V,A));G,u=P(b);H=[]
for x in O(F):H.append(G[x]-F[x])
Y=H.index(max(H))
e=E(list(b),Y,u)
for x in e:
 if x in b:del b[b.index(x)]
for x in O(b):b[x]=J(b[x])
print(' '.join(b[:5]))
print()
</code>```

(I/O) modeled after PlumberBot
-Edit: Extensive bugfixes thanks to Destructible Watermelon
-Edit: Due to new rules, a trailing newline after the final output

Title: Leo's Pokerface

Body:
LadyGaga, Python 3

Is somewhat blind to suits

Has a dress full of bugs

And likes to play Poker Face once in a while

from math import ceil as f
M=lambda A:max(set(A),key=A.count)
K=lambda A:A.count(M(A))
O=lambda A:range(len(A))
J=lambda A:A[0]+str(U(A[1]))
X={"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"T":10,"J":11,"Q":12,"K":13,"A":14}
def V(A):return([A[0]]+[int(X[A[1]])])
def U(c):
 if c==10:c='T'
 if c==11:c='J'
 if c==12:c='Q'
 if c==13:c='K'
 if c==14:c='A'
 return(c)
def P(A):
 S=[];C=[];t=len(A)
 for x in A:S.append(x[0]);C.append(x[1])
 B=[0]*9;q=len(set(C));p=K(C);D=list(set(C));D.sort()
 B[2]=1/f(13**(4-p));B[6]=1/f(13**(3-p));B[8]=1/f(13**(2-p))
 if (p,q)==(2,4):B[3]=1/1100;B[7]=5/34
 if (p,q)==(3,3):B[3]=1/169;B[7]=1/169
 if (p,q)==(4,2):B[3]=1/13;B[7]=1
 if (p,q)==(2,3):B[3]=5/169;B[7]=1
 if (p,q)==(3,2):B[3]=1;B[7]=1
 for x in O(D):D[x]-=x
 j=M(D);h=K(D)-5;B[5]=13**h
 for x in O(D):
  if j+h<D[x]<j-h and D[x]!=j:B[5]*=13
 W=K(S);B[4]=(4**(W-t))*(13-W)/52
 return(B,M(S))
def E(B,h,u):
 x=0;D=[];C=[]
 while 1:
  k=list(C)
  C=[]
  while 1:
   p=list(B);del p[x]
   if len(D)==3:break
   if P(p)[0][h]>=P(B)[0][h]:C.append(B[x])
   x+=1
   if x>len(p):break
  if len(C)==0:break
  for x in O(C):
   if k==C or not((u in C[x])and(len(C)-1)):D.append(C[x]);del B[B.index(C[x])]
 return(D)
s=input()
A=s.split(' ')
b=list(map(V,A));G,u=P(b);F=[649739,72192,4164,693,508,254,46.3,20,1.4];H=[]
for x in O(F):F[x]=1-((1-(1/F[x]))**4)
for x in O(F):H.append(G[x]-F[x])
Y=H.index(max(H));p=[]
e=E(list(b),Y,u);g=list(e)
for x in O(e):e[x]=J(e[x])
print(' '.join(e)if len(e)else'')
for x in g:
 if x in b:del b[b.index(x)]
s=input()
if len(s):
 A=s.split(' ')
 b+=list(map(V,A))
print(3)
s=input()
A=s.split(' ')
b+=list(map(V,A));G,u=P(b);H=[]
for x in O(F):H.append(G[x]-F[x])
Y=H.index(max(H))
e=E(list(b),Y,u)
for x in e:
 if x in b:del b[b.index(x)]
for x in O(b):b[x]=J(b[x])
print(' '.join(b[:5]))
print()

(I/O) modeled after PlumberBot
-Edit: Extensive bugfixes thanks to Destructible Watermelon
-Edit: Due to new rules, a trailing newline after the final output


答:
CJam (22 bytes)

```<code>q~{2m*::-:z0-}/m*:$_&,
</code>```

Takes input as an array of arrays. Online demo, test suite

Dissection

```<code>q~     e# Parse input
{      e# For each of the two elements in the top-level array
  2m*  e#   Take its Cartesian self-product
  ::-  e#   Map fold subtraction, giving the separations between lines
  :z   e#   Map absolute value
  0-   e#   Remove 0, since trivial rectangles don't count
}/
m*     e# Cartesian product of the two sets of separations
:$     e# Sort so that mxn === nxm
_&     e# Deduplicate
,      e# Count
</code>```

Title: Count the Unique Rectangles!

Body:
In my last challenge, you were asked to find all rectangles given a m x n grid of them. However, it turned out to be very trivial as there actually was a mathematical formula I did not even know about to solve the problem! So now, for a little bit more of a challenge, how about calculating the number of unique rectangles, i.e. find the number rectangles that are all of different dimensions?

For example, consider 4 horizontal, or y lines at [-250,-50,50,250] and 4 vertical, or x lines at [-250,-70,70,250]. Graphing these on a coordinate plane with infinite dimensions results in the following 500 x 500 pixel closed grid, in which the length of each segment in pixels and the lines corresponding to their respected values from the arrays are shown:

which contains the 16 unique rectangles shown in this animated GIF:

However, if the topmost line (y = 250) were to be removed, there would only be 12 unique rectangles, as the top 3 rectangles would be factored out since they each won't be fully closed without the y = 250 line.

Task

So, as shown above, the task is counting the number of rectangles rectangles with different dimensions. In other words, given an input of 2 arrays, with the first one containing all equations of all x lines, and the latter containing those of all y lines, output the total number of rectangles of different dimensions created when the lines corresponding to those equations are graphed on a coordinate plane.

Rules

The use of any built-ins that directly solve this problem is explicitly disallowed.

If either of the arrays have less than 2 elements, the output should be 0, since if there are less than 4 lines on the plane, there are no closed, 4 sided figures.

The input arrays are not guaranteed to be sorted.

You can assume that there are not any repeated values in either of the the input arrays.

A n x m rectangle is the same as a m x n rectangle. For example, a 300 x 200 rectangle is the same as a 200 x 300 one.

Standard loopholes are prohibited.

Test Cases

Given in the format Comma Separated Arrays Input -> Integer output:

```<code>[],[] -> 0
[-250,-50,50,250],[-250,-70,70,250] -> 16 (Visualized above)
[-250,-50,50,250],[-250,-70,70] -> 12
[-40, 40],[-80, 50] -> 1
[10],[10] -> 0
[60, -210, -60, 180, 400, -400], [250, -150] -> 12
[0,300,500],[0,300,500] -> 6
[0,81,90],[0,90,100] -> 9
</code>```

Remember, this is code-golf, so shortest code wins!

Body:
CJam (22 bytes)

q~{2m*::-:z0-}/m*:$_&,

Takes input as an array of arrays. Online demo, test suite

Dissection

q~     e# Parse input
{      e# For each of the two elements in the top-level array
  2m*  e#   Take its Cartesian self-product
  ::-  e#   Map fold subtraction, giving the separations between lines
  :z   e#   Map absolute value
  0-   e#   Remove 0, since trivial rectangles don't count
}/
m*     e# Cartesian product of the two sets of separations
:$     e# Sort so that mxn === nxm
_&     e# Deduplicate
,      e# Count


答:
Python 2, <s>86</s> 85 bytes

```<code>n=0;exec'x=25-abs(n-25);print bytearray(65+x-abs(y-x)for y in range(2*x+1));n+=1;'*51
</code>```

Try it at Ideone.

This follows a simple process. First, create the range [0, 1, ..., 24, 25, 24, ..., 1, 0]. Then, for each value x in that range, create another range [0, 1, ..., x, ..., 1, 0] and map each of those values to a character in 'A..Z'. Finally, print each string of characters.

Title: Alphabet triangle

Body:
Python 2, <s>86</s> 85 bytes

n=0;exec'x=25-abs(n-25);print bytearray(65+x-abs(y-x)for y in range(2*x+1));n+=1;'*51

Try it at Ideone.

This follows a simple process. First, create the range [0, 1, ..., 24, 25, 24, ..., 1, 0]. Then, for each value x in that range, create another range [0, 1, ..., x, ..., 1, 0] and map each of those values to a character in 'A..Z'. Finally, print each string of characters.


答:
Python, 74 bytes

def f(x=66,s='A'):
 t=s+s[-2::-1];print t
 if x<91:f(x+1,s+chr(x));print t
```
<p>A Python 2 function that prints and takes no arguments. The key idea is to generate the triangular there-and-back pattern with recursion. First consider this simpler function that prints the letters 'A' up to 'Z' and down back to 'A':</p>
<pre class="lang-python prettyprint-override"><code>def f(x=65):
 t=chr(x);print t
 if x<90:f(x+1);print t
</code>```

The function first prints "A" (char-code 65), then recurses to print "B" (66) and so on to "Z" (90). From there, it stops recursing. On the way popping back down the recursive stack, it prints whatever character t it printed at the same layer, from "Y" back to "A".

The main code does the same, except it accumulates into s the string of letters so far, and prints the up-and-down string s+s[-2::-1].

Thanks to xsot for 2 bytes.

In Python 3, the same thing is a byte shorter (73 bytes) by putting everything on one line.

def f(x=66,s='A'):t=s+s[-2::-1];print(t);x>90or[f(x+1,s+chr(x)),print(t)]
```

Title: Alphabet triangle

Body:
Python, 74 bytes

def f(x=66,s='A'):
 t=s+s[-2::-1];print t
 if x<91:f(x+1,s+chr(x));print t

A Python 2 function that prints and takes no arguments. The key idea is to generate the triangular there-and-back pattern with recursion. First consider this simpler function that prints the letters 'A' up to 'Z' and down back to 'A':

def f(x=65):
 t=chr(x);print t
 if x<90:f(x+1);print t

The function first prints "A" (char-code 65), then recurses to print "B" (66) and so on to "Z" (90). From there, it stops recursing. On the way popping back down the recursive stack, it prints whatever character t it printed at the same layer, from "Y" back to "A".

The main code does the same, except it accumulates into s the string of letters so far, and prints the up-and-down string s+s[-2::-1].

Thanks to xsot for 2 bytes.

In Python 3, the same thing is a byte shorter (73 bytes) by putting everything on one line.

def f(x=66,s='A'):t=s+s[-2::-1];print(t);x>90or[f(x+1,s+chr(x)),print(t)]


答:
Sesos, 27 bytes

```<code>0000000: a85ab9 ac5daa f8b1c7 785f9b b961f7 665c1b 73ccfc  .Z..]....x_..a.f\.s..
0000015: c01ecb 987303                                     ....s.
</code>```

Try it online! Check Debug to see the generated SBIN code.

Sesos assembly

The binary file above has been generated by assembling the following SASM code.

add 65, rwd 1, add 10, rwd 2, add 25
jmp
    fwd 3
    jmp
        put, fwd 1
    jnz
    rwd 1
    jmp
        fwd 1, add 1, fwd 1, add 1, rwd 2, sub 1
    jnz
    fwd 2
    jmp
        rwd 2, add 1, fwd 2, sub 1
    jnz
    rwd 1, add 1, rwd 2
    jmp
        put, rwd 1
    jnz
    rwd 1, sub 1
jnz
fwd 3
jmp
    jmp
        put, fwd 1
    jnz
    rwd 1, get, rwd 1
    jmp
        put, rwd 1
    jnz
    fwd 2
; jnz (implicit)
```

Title: Alphabet triangle

Body:
Sesos, 27 bytes

0000000: a85ab9 ac5daa f8b1c7 785f9b b961f7 665c1b 73ccfc  .Z..]....x_..a.f\.s..
0000015: c01ecb 987303                                     ....s.

<a href="http://sesos.tryitonline.net/#code=YWRkIDY1LCByd2QgMSwgYWRkIDEwLCByd2QgMiwgYWRkIDI1CmptcAoJZndkIDMKCWptcAoJCXB1dCwgZndkIDEKCWpuegoJcndkIDEKCWptcAoJCWZ3ZCAxLCBhZGQgMSwgZndkIDEsIGFkZCAxLCByd2QgMiwgc3ViIDEKCWpuegoJZndkIDIKCWptcAoJCXJ3ZCAyLCBhZGQgMSwgZndkIDIsIHN1YiAxCglqbnoKCXJ3ZCAxLCBhZGQgMSwgcndkIDIKCWptcAoJCXB1dCwgcndkIDEKCWpuegoJcndkIDEsIHN1YiAxCmpuegpmd2QgMwpqbXAKCWptcAoJCXB1dCwgZndkIDEKCWpuegoJcndkIDEsIGdldCwgcndkIDEKCWptcAoJCXB1dCwgcndkIDEKCWpuegoJZndkIDIKOyBqbnogKGltcGxpY2l0KQ&input=" rel="nofollow">Try it online! Check Debug to see the generated SBIN code.

Sesos assembly

The binary file above has been generated by assembling the following SASM code.

add 65, rwd 1, add 10, rwd 2, add 25
jmp
    fwd 3
    jmp
        put, fwd 1
    jnz
    rwd 1
    jmp
        fwd 1, add 1, fwd 1, add 1, rwd 2, sub 1
    jnz
    fwd 2
    jmp
        rwd 2, add 1, fwd 2, sub 1
    jnz
    rwd 1, add 1, rwd 2
    jmp
        put, rwd 1
    jnz
    rwd 1, sub 1
jnz
fwd 3
jmp
    jmp
        put, fwd 1
    jnz
    rwd 1, get, rwd 1
    jmp
        put, rwd 1
    jnz
    fwd 2
; jnz (implicit)


答:
Batch, <s>226</s> 224 bytes

```<code>@set z=ABCDEFGHIJKLMNOPQRSTUVWXYZ
@set a=YXWVUTSRQPONMLKJIHGFEDCBA
@for /l %%i in (0,1,25)do @call echo %%z:~0,%%i%%%%z:~%%i,1%%%%a:~-%%i,%%i%%
@for /l %%i in (24,-1,0)do @call echo %%z:~0,%%i%%%%z:~%%i,1%%%%a:~-%%i,%%i%%
</code>```

Edit: Saved 2 bytes thanks to @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ.

Title: Alphabet triangle

Body:
Batch, <s>226</s> 224 bytes

@set z=ABCDEFGHIJKLMNOPQRSTUVWXYZ
@set a=YXWVUTSRQPONMLKJIHGFEDCBA
@for /l %%i in (0,1,25)do @call echo %%z:~0,%%i%%%%z:~%%i,1%%%%a:~-%%i,%%i%%
@for /l %%i in (24,-1,0)do @call echo %%z:~0,%%i%%%%z:~%%i,1%%%%a:~-%%i,%%i%%

Edit: Saved 2 bytes thanks to @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ.


问:
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

```

答:
F#, 74 bytes

```<code>for i=0 to 25 do(for j=0 to 25 do printf"%c"<|char((j+i)%26+65));printfn""
</code>```

Pretty straightforward

Title: Print a Tabula Recta!

Body:
F#, 74 bytes

for i=0 to 25 do(for j=0 to 25 do printf"%c"<|char((j+i)%26+65));printfn""

Pretty straightforward


答:
Mathematica <S>98 96</S> 92 bytes

There has to be a shorter way, even in Mathematica.

6 bytes saved thanks to Martin Ender.

```<code>r=Reverse@*Most; Print/@FromCharacterCode@Join[t=Join[s=Range[65,64+k],r@s]~Table~{k,26},r@t]
</code>```

Title: Alphabet triangle

Body:
You are to print this exact text:

```<code>A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
ABCDEFGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYZYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGFEDCBA
ABCDEFEDCBA
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A
</code>```

Specs

Extra trailing newlines are allowed at the end of the output.

Extra trailing spaces (U+0020) are allowed at the end of each line, including the extra trailing newlines.

You can use all lowercase instead of all uppercase, but you cannot print partially lowercase partially uppercase.

You can return the text as a function output instead of printing it in a full program.

Scoring

Since this is a triangle, and a triangle has 3 sides, and 3 is a small number, your code should be small in terms of byte-count.

Body:
Mathematica <S>98 96</S> 92 bytes

There has to be a shorter way, even in Mathematica.

6 bytes saved thanks to Martin Ender.

r=Reverse@*Most; Print/@FromCharacterCode@Join[t=Join[s=Range[65,64+k],r@s]~Table~{k,26},r@t]


问:
Partitions of a list
The answer to this question is much too long

Your challenge is to write a partitioning function in the smallest number of characters.

Input example

```<code>['a', 'b', 'c']
</code>```

Output example

```<code>[(('a'),('b'),('c')),
 (('a', 'b'), ('c')),
 (('a', 'c'), ('b')),
 (('b', 'c'), ('a')),
 (('a', 'b', 'c'))]
</code>```

The input can be a list/array/set/string etc. whatever is easiest for your function to process

You can also choose the output format to suit yourself as long as the structure is clear.

Your function should work for at least 6 items in the input

答:
GolfScript (43 chars)

```<code>{[[]]:E\{:v;{:^E+1/{^1$-\[~[v]+]+}/}%}/}:P;
</code>```

or

```<code>{[[]]:E\{:v;{:^E+1/{^1$-\{[v]+}%+}/}%}/}:P;
</code>```

Same input format, output format, and function name as Howard's solution. There's no brute forcing: this takes the simple iterative approach of adding one element from the input list to the partition each time round the outer loop.

Title: Partitions of a list

Body:
GolfScript (43 chars)

{[[]]:E\{:v;{:^E+1/{^1$-\[~[v]+]+}/}%}/}:P;

or

{[[]]:E\{:v;{:^E+1/{^1$-\{[v]+}%+}/}%}/}:P;

Same input format, output format, and function name as Howard's solution. There's no brute forcing: this takes the simple iterative approach of adding one element from the input list to the partition each time round the outer loop.


Title: Count the Unique Rectangles!

Body:
JavaScript (ES6), 99

(X,Y,Z=new Set)=>X.map(v=>X.map(t=>t>v&&Y.map(w=>Y.map(u=>u>w&&Z.add([u-w,t-v].sort()+0)))))|Z.size

Note: sort is not numeric but lexicographic, but in this specific case I don't care

Less golfed

(X, Y, Z = new Set) =>
  X.map(
    v => X.map(
      t => t>v && Y.map(
        w => Y.map(
          u => u>w && Z.add([u-w, t-v].sort() + 0)
        )
      )
    )
  ) | Z.size

Test

F=(X,Y,Z=new Set)=>X.map(v=>X.map(t=>t>v&&Y.map(w=>Y.map(u=>u>w&&Z.add([u-w,t-v].sort()+0)))))|Z.size

;[
 [[],[], 0]
,[[-250,-50,50,250],[-250,-70,70,250], 16]
,[[-250,-50,50,250],[-250,-70,70], 12]
,[[-40, 40],[-80, 50], 1]
,[[10],[10], 0]
,[[60, -210, -60, 180, 400, -400], [250, -150], 12]
,[[0,300,500],[0,300,500], 6]
].forEach(t=>{
  var a=t[0],b=t[1],k=t[2],r=F(a,b)

  console.log(r==k?'OK':'KO','['+a+']','['+b+']',r)
})


Title: Alphabet triangle

Body:
bash, 80 bytes

printf -v a %s {A..Z};for i in {1..26} {25..1};{ echo ${a::i}`rev<<<${a::i-1}`;}


答:
///, 208 bytes

```<code>/'/\/\///+/BA
AB'-/DC+CD'&/FE-EF')/HG&GH'=/JI)IJ'|/LK=KL'7/NM|MN'1/PO7OP'q/RQ1QR'p/TSqST'6/VUpUV'[/XW6WX/A
A+C+C-E-E&G&G)I)I=K=K|M|M7O7O1Q1QqSqSpUpU6W6W[Y[YZY[Y[W6W6UpUpSqSqQ1Q1O7O7M|M|K=K=I)I)G&G&E-E-C+C+A
A
</code>```

Not winning of course, but here it is, predating Martin Ender...

Title: Alphabet triangle

Body:
///, 208 bytes

/'/\/\///+/BA
AB'-/DC+CD'&/FE-EF')/HG&GH'=/JI)IJ'|/LK=KL'7/NM|MN'1/PO7OP'q/RQ1QR'p/TSqST'6/VUpUV'[/XW6WX/A
A+C+C-E-E&G&G)I)I=K=K|M|M7O7O1Q1QqSqSpUpU6W6W[Y[YZY[Y[W6W6UpUpSqSqQ1Q1O7O7M|M|K=K=I)I)G&G&E-E-C+C+A
A

Not winning of course, but here it is, predating Martin Ender...


答:
05AB1E, 4 bytes

```<code>€LOP
</code>```

Explanation

Uses the formula described at A096948

```<code>      # Implicit input, ex: [7,6]
€L    # Enumerate each, [[1,2,3,4,5,6,7],[1,2,3,4,5,6]]
  O   # Sum, [28,21]
   P  # Product, 588
      # Implicit display
</code>```

Takes input as [n,m].

Try it online

Title: How Many Rectangles in the Grid?

Body:
Well, although this challenge turned out to be a huge success, it also turned out to be very trivial to solve. Therefore, for those of looking for more of a challenge, I created a sequel to this challenge in which you must now count the number of unique rectangles. Check it out!

Now, for those of you looking to solve this challenge, here it comes.

Well, we don't really have a challenge like this yet, so here we go.

Consider this 3 x 3 grid of rectangles:

How many rectangles are there? Well, counting visually, we can see that there are actually 36 rectangles, including the entire plane itself, which are all shown in the animated GIF below:

The Task

The counting of rectangles as shown above is the task. In other words, given 2 integers greater than or equal to 0, m and n, where m represents the width and n represents the height, output the total number of rectangles in that m x n grid of rectangles.

Rules

The use of any built-ins that directly solve this problem is explicitly disallowed.

This challenge is not about finding the shortest answer, but finding the shortest answer in every language. Therefore, no answer will be accepted.

Standard loopholes are prohibited.

Test Cases

Presented in the format Array of Integers Input -> Integer Output:

```<code>[0,0] -> 0
[1,1] -> 1
[3,3] -> 36 (Visualized above)
[4,4] -> 100
[6,7] -> 588
</code>```

References

http://oeis.org/A096948

Remember, this is code-golf, so shortest code wins!

Body:
05AB1E, 4 bytes

€LOP

Explanation

Uses the formula described at A096948

      # Implicit input, ex: [7,6]
€L    # Enumerate each, [[1,2,3,4,5,6,7],[1,2,3,4,5,6]]
  O   # Sum, [28,21]
   P  # Product, 588
      # Implicit display

Takes input as [n,m].

Try it online


答:
Emacs, 47 bytes

```<code>abcdefghijklmnopqrstuvwxyz^M
^P
<F3>
^K ^K ^Y ^Y
^P
^<space> ^F ^W ^E ^Y ^A
<F4>
^U 2 4 F4
</code>```

Where ^P means "Control P", etc.  That's 47 bytes, since the F3 and F4 keys require two ASCII bytes.

After entering the starting input, it defines a keyboard macro to duplicate the line and move the first character to the end. It then runs the macro a further 24 times.

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:
Emacs, 47 bytes

abcdefghijklmnopqrstuvwxyz^M
^P
<F3>
^K ^K ^Y ^Y
^P
^<space> ^F ^W ^E ^Y ^A
<F4>
^U 2 4 F4

Where ^P means "Control P", etc.  That's 47 bytes, since the F3 and F4 keys require two ASCII bytes.

After entering the starting input, it defines a keyboard macro to duplicate the line and move the first character to the end. It then runs the macro a further 24 times.


答:
C, <s>272</s> <s>247</s> <s>234</s> <s>230</s> <s>144</s> 137 bytes:

(Saved many bytes (272 -> 230) in my previous method thanks to great golfing tips & tricks from sigalor!)

(Saved nearly 100 bytes (230 -> 144) by switching to a better method.)

```<code>main(q,i,e,x){for(q=0;q<51;q++){i=q>25 ? 25-(q-25):q;for(e=65;e<66+i;e++)printf("%c",e);for(x=64+i;x>64;x--)printf("%c",x);printf("\n");}}
</code>```

My first answer ever in C. I just started self-learning it recently, so let's see how it goes.

C it in Action! (Ideone)

Title: Alphabet triangle

Body:
C, <s>272</s> <s>247</s> <s>234</s> <s>230</s> <s>144</s> 137 bytes:

(Saved many bytes (272 -> 230) in my previous method thanks to great golfing tips & tricks from sigalor!)

(Saved nearly 100 bytes (230 -> 144) by switching to a better method.)

main(q,i,e,x){for(q=0;q<51;q++){i=q>25 ? 25-(q-25):q;for(e=65;e<66+i;e++)printf("%c",e);for(x=64+i;x>64;x--)printf("%c",x);printf("\n");}}

My first answer ever in C. I just started self-learning it recently, so let's see how it goes.

C it in Action! (Ideone)


答:
MATL, 22 bytes

```<code>"@gd&Xfo!s|]Z*!S!Xuz2/
</code>```

Try it online! Or verify all test cases.

Explanation

```<code>"        % Implicitly input cell array of two numerical arrays. For each cell
  @g     %   Push cell contents
  d      %   Difference of its two entries
  &Xf    %   Cell array of all substrings
  o      %   Convert to numerical array, padding with zeros
  !s     %   Sum of each row. Gives a row vector
  |      %   Absolute value of each entry
]        % End for
Z*       % Cartesian product
!S!      % Sort each row
Xu       % Unique rows
z2/      % Number of unique rows excluding zeros. Implicitly display
</code>```

Title: Count the Unique Rectangles!

Body:
In my last challenge, you were asked to find all rectangles given a m x n grid of them. However, it turned out to be very trivial as there actually was a mathematical formula I did not even know about to solve the problem! So now, for a little bit more of a challenge, how about calculating the number of unique rectangles, i.e. find the number rectangles that are all of different dimensions?

For example, consider 4 horizontal, or y lines at [-250,-50,50,250] and 4 vertical, or x lines at [-250,-70,70,250]. Graphing these on a coordinate plane with infinite dimensions results in the following 500 x 500 pixel closed grid, in which the length of each segment in pixels and the lines corresponding to their respected values from the arrays are shown:

which contains the 16 unique rectangles shown in this animated GIF:

However, if the topmost line (y = 250) were to be removed, there would only be 12 unique rectangles, as the top 3 rectangles would be factored out since they each won't be fully closed without the y = 250 line.

Task

So, as shown above, the task is counting the number of rectangles rectangles with different dimensions. In other words, given an input of 2 arrays, with the first one containing all equations of all x lines, and the latter containing those of all y lines, output the total number of rectangles of different dimensions created when the lines corresponding to those equations are graphed on a coordinate plane.

Rules

The use of any built-ins that directly solve this problem is explicitly disallowed.

If either of the arrays have less than 2 elements, the output should be 0, since if there are less than 4 lines on the plane, there are no closed, 4 sided figures.

The input arrays are not guaranteed to be sorted.

You can assume that there are not any repeated values in either of the the input arrays.

A n x m rectangle is the same as a m x n rectangle. For example, a 300 x 200 rectangle is the same as a 200 x 300 one.

Standard loopholes are prohibited.

Test Cases

Given in the format Comma Separated Arrays Input -> Integer output:

```<code>[],[] -> 0
[-250,-50,50,250],[-250,-70,70,250] -> 16 (Visualized above)
[-250,-50,50,250],[-250,-70,70] -> 12
[-40, 40],[-80, 50] -> 1
[10],[10] -> 0
[60, -210, -60, 180, 400, -400], [250, -150] -> 12
[0,300,500],[0,300,500] -> 6
[0,81,90],[0,90,100] -> 9
</code>```

Remember, this is code-golf, so shortest code wins!

Body:
MATL, 22 bytes

"@gd&Xfo!s|]Z*!S!Xuz2/

Try it online! Or verify all test cases.

Explanation

"        % Implicitly input cell array of two numerical arrays. For each cell
  @g     %   Push cell contents
  d      %   Difference of its two entries
  &Xf    %   Cell array of all substrings
  o      %   Convert to numerical array, padding with zeros
  !s     %   Sum of each row. Gives a row vector
  |      %   Absolute value of each entry
]        % End for
Z*       % Cartesian product
!S!      % Sort each row
Xu       % Unique rows
z2/      % Number of unique rows excluding zeros. Implicitly display


问:
Shortest code to check if a number is in a range in JavaScript
This is how I checkout to see if a number is in a range (in between two other numbers):

```<code>var a = 10,
    b = 30,
    x = 15,
    y = 35;

x < Math.max(a,b) && x > Math.min(a,b) // -> true
y < Math.max(a,b) && y > Math.min(a,b) // -> false
</code>```

I have to do this math in my code a lot and I'm looking for shorter equivalent code.

This is a shorter version I came up with. But I am sure it can get much shorter:

```<code>a < x && x < b
true
a < y && y < b
false
</code>```

But downside is I have to repeat x or y

答:
```<code>a<x==x<b
</code>```

JavaScript, 8 chars.

Body:
a<x==x<b

JavaScript, 8 chars.


答:
05AB1E, <s>20 13 12</s> 6 bytes

Saved 2 bytes thanks to Adnan.

Saved 6 bytes thanks to Magic Octopus Urn and some new language functionality.

```<code>Aη€ûû»
</code>```

Try it online!

Explanation

```<code>Aη       # push prefixes of alphabet
  €û     # palendromize each prefix
    û    # palendromize the whole list
     »   # join on newlines
</code>```

Title: Alphabet triangle

Body:
05AB1E, <s>20 13 12</s> 6 bytes

Saved 2 bytes thanks to Adnan.

Saved 6 bytes thanks to Magic Octopus Urn and some new language functionality.

Aη€ûû»

Try it online!

Explanation

Aη       # push prefixes of alphabet
  €û     # palendromize each prefix
    û    # palendromize the whole list
     »   # join on newlines


答:
Dyalog APL, 18 bytes

```<code>↑(⊣,⌽)(⊣,1↓⌽)¨,\⎕a
</code>```

Title: Alphabet triangle

Body:
Dyalog APL, 18 bytes

↑(⊣,⌽)(⊣,1↓⌽)¨,\⎕a


答:
TSQL, 159 bytes

```<code>DECLARE @ varchar(52)='ABCDEFGHIJKLMNOPQRSTUVWXY',@o varchar(max)SELECT @+='Z'+REVERSE(@)+'
',@o=@
WHILE''<@
SELECT @=STUFF(@,LEN(@)/2,2,''),@o=@+@o+@
PRINT @o
</code>```

Fiddle

Title: Alphabet triangle

Body:
TSQL, 159 bytes

DECLARE @ varchar(52)='ABCDEFGHIJKLMNOPQRSTUVWXY',@o varchar(max)SELECT @+='Z'+REVERSE(@)+'
',@o=@
WHILE''<@
SELECT @=STUFF(@,LEN(@)/2,2,''),@o=@+@o+@
PRINT @o

Fiddle


问:
Compounding english
A compound word is a word that contains 2 or more words in it.  We can do better than that, though.  We need you to create 1 (nonsensical) word that contains every word.

However, we want this word to be as short as possible.  We can use overlapping letters to achieve this.

For example, if your word list was ["cat", "atom", "a"], you would want to return "catom".

Input/Output

Your program will need to take a list of words as input, and return a compound word as output.

The word list you will be using is the top 10000 words in English, according to Google  (If this list turns out to be too easy, I may change it to a longer one).   For reference, simply appending each word gives you a score of 65888.

Your score is the number of letters in your final word, lower is better.  Tie breaker goes to the first poster.

答:
C++11, 38272 letters, proven optimal

This algorithm is guaranteed to provide a lower bound on the solution. In this case, it is able to achieve the lower bound and output an optimal 38272 letter solution. (This matches the solution found by Dave’s greedy algorithm. I was surprised and a little disappointed to discover that it’s optimal, but, there we are.)

It works by solving the minimum-cost flow problem on the network built as follows.

First, any words contained in other words are redundant; discard them.

For every word w, draw two nodes w_0 and w_1, where w_0 is a source with capacity 1 and w_1 is a sink with capacity 1.

For every (strict) prefix or suffix a of any word, draw a node a.

For every suffix a of w, draw an arc from w_0 to a with capacity 1 and cost 0.

For every prefix a of w, draw an arc from a to w_1 with capacity 1 and cost length(w) − length(a).

Any string of length n that contains every word can be converted into a flow on this network with cost at most n. Therefore, the minimum cost flow on this network is a lower bound on the length of the shortest such string.

If we’re lucky—and in this case we are—then after we redirect the flow coming into w_1 back out of w_0, we will find an optimal flow that has just one connected component and that passes through the node for the empty string. If so, it will contain an Eulerian circuit starting and ending there. Such an Eulerian circuit can be read back out as a string of optimal length.

If we weren’t lucky, add some extra arcs between the empty string and the shortest strings in the other connected components in order to ensure that an Eulerian circuit exists. The string would no longer necessarily be optimal in that case.

I use the LEMON library for its min-cost flow and Eulerian circuit algorithms. (This was my first time using this library, and I was impressed—I will definitely use it again for future graph algorithm needs.) LEMON comes with four different minimum-cost flow algorithms; you can try them here with --net, --cost, --cap, and --cycle (default).

The program runs in 0.5 seconds, producing this output string.

#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <lemon/core.h>
#include <lemon/connectivity.h>
#include <lemon/euler.h>
#include <lemon/maps.h>
#include <lemon/list_graph.h>
#include <lemon/network_simplex.h>
#include <lemon/cost_scaling.h>
#include <lemon/capacity_scaling.h>
#include <lemon/cycle_canceling.h>

using namespace std;

typedef lemon::ListDigraph G;

struct Word {
    G::Node suffix, prefix;
    G::Node tour_node;
};

struct Edge {
    unordered_map<string, Word>::iterator w;
    G::Arc arc;
};

struct Affix {
    vector<Edge> suffix, prefix;
    G::Node node;
    G::Node tour_node;
};

template<class MCF>
bool solve(const G &net, const G::ArcMap<int> &lowerMap, const G::ArcMap<int> &upperMap, const G::ArcMap<int> &costMap, const G::NodeMap<int> &supplyMap, int &totalCost, G::ArcMap<int> &flowMap)
{
    MCF mcf(net);
    if (mcf.lowerMap(lowerMap).upperMap(upperMap).costMap(costMap).supplyMap(supplyMap).run() != mcf.OPTIMAL)
        return false;
    totalCost = mcf.totalCost();
    mcf.flowMap(flowMap);
    return true;
}

int main(int argc, char **argv)
{
    clog << "Reading dictionary from stdin" << endl;
    unordered_map<string, Affix> affixes;
    unordered_map<string, Word> words;
    unordered_set<string> subwords;
    G net, tour;
    G::ArcMap<int> lowerMap(net), upperMap(net), costMap(net);
    G::NodeMap<int> supplyMap(net);
    string new_word;
    while (getline(cin, new_word)) {
        if (subwords.find(new_word) != subwords.end())
            continue;
        for (auto i = new_word.begin(); i != new_word.end(); ++i) {
            for (auto j = new_word.end(); j != i; --j) {
                string s(i, j);
                words.erase(s);
                subwords.insert(s);
            }
        }
        words.emplace(new_word, Word());
    }
    for (auto w = words.begin(); w != words.end(); ++w) {
        w->second.suffix = net.addNode();
        supplyMap.set(w->second.suffix, 1);
        w->second.prefix = net.addNode();
        supplyMap.set(w->second.prefix, -1);
        for (auto i = w->first.begin(); ; ++i) {
            affixes.emplace(string(w->first.begin(), i), Affix()).first->second.prefix.push_back(Edge {w});
            affixes.emplace(string(i, w->first.end()), Affix()).first->second.suffix.push_back(Edge {w});
            if (i == w->first.end())
                break;
        }
        w->second.tour_node = tour.addNode();
    }
    for (auto a = affixes.begin(); a != affixes.end();) {
        if (a->second.suffix.empty() || a->second.prefix.empty() ||
            (a->second.suffix.size() == 1 && a->second.prefix.size() == 1 &&
             a->second.suffix.begin()->w == a->second.prefix.begin()->w)) {
            affixes.erase(a++);
        } else {
            a->second.node = net.addNode();
            supplyMap.set(a->second.node, 0);
            for (auto &e : a->second.suffix) {
                e.arc = net.addArc(e.w->second.suffix, a->second.node);
                lowerMap.set(e.arc, 0);
                upperMap.set(e.arc, 1);
                costMap.set(e.arc, 0);
            }
            for (auto &e : a->second.prefix) {
                e.arc = net.addArc(a->second.node, e.w->second.prefix);
                lowerMap.set(e.arc, 0);
                upperMap.set(e.arc, 1);
                costMap.set(e.arc, e.w->first.length() - a->first.length());
            }
            a->second.tour_node = lemon::INVALID;
            ++a;
        }
    }

    clog << "Read " << words.size() << " words and found " << affixes.size() << " affixes; ";
    clog << "created network with " << countNodes(net) << " nodes and " << countArcs(net) << " arcs" << endl;

    int totalCost;
    G::ArcMap<int> flowMap(net);
    bool solved;
    if (argc > 1 && string(argv[1]) == "--net") {
        clog << "Using network simplex algorithm" << endl;
        solved = solve<lemon::NetworkSimplex<G>>(net, lowerMap, upperMap, costMap, supplyMap, totalCost, flowMap);
    } else if (argc > 1 && string(argv[1]) == "--cost") {
        clog << "Using cost scaling algorithm" << endl;
        solved = solve<lemon::CostScaling<G>>(net, lowerMap, upperMap, costMap, supplyMap, totalCost, flowMap);
    } else if (argc > 1 && string(argv[1]) == "--cap") {
        clog << "Using capacity scaling algorithm" << endl;
        solved = solve<lemon::CapacityScaling<G>>(net, lowerMap, upperMap, costMap, supplyMap, totalCost, flowMap);
    } else if ((argc > 1 && string(argv[1]) == "--cycle") || true) {
        clog << "Using cycle canceling algorithm" << endl;
        solved = solve<lemon::CycleCanceling<G>>(net, lowerMap, upperMap, costMap, supplyMap, totalCost, flowMap);
    }

    if (!solved) {
        clog << "error: no solution found" << endl;
        return 1;
    }
    clog << "Lower bound: " << totalCost << endl;

    G::ArcMap<string> arcLabel(tour);
    G::Node empty = tour.addNode();
    affixes.find("")->second.tour_node = empty;
    for (auto &a : affixes) {
        for (auto &e : a.second.suffix) {
            if (flowMap[e.arc]) {
                if (a.second.tour_node == lemon::INVALID)
                    a.second.tour_node = tour.addNode();
                arcLabel.set(tour.addArc(e.w->second.tour_node, a.second.tour_node), "");
            }
        }
        for (auto &e : a.second.prefix) {
            if (flowMap[e.arc]) {
                if (a.second.tour_node == lemon::INVALID)
                    a.second.tour_node = tour.addNode();
                arcLabel.set(tour.addArc(a.second.tour_node, e.w->second.tour_node), e.w->first.substr(a.first.length()));
            }
        }
    }

    clog << "Created tour graph with " << countNodes(tour) << " nodes and " << countArcs(tour) << " arcs" << endl;

    G::NodeMap<int> compMap(tour);
    int components = lemon::stronglyConnectedComponents(tour, compMap);
    if (components != 1) {
        vector<unordered_map<string, Affix>::iterator> breaks(components, affixes.end());
        for (auto a = affixes.begin(); a != affixes.end(); ++a) {
            if (a->second.tour_node == lemon::INVALID)
                continue;
            int c = compMap[a->second.tour_node];
            if (c == compMap[empty])
                continue;
            auto &b = breaks[compMap[a->second.tour_node]];
            if (b == affixes.end() || b->first.length() > a->first.length())
                b = a;
        }
        int offset = 0;
        for (auto &b : breaks) {
            if (b != affixes.end()) {
                arcLabel.set(tour.addArc(empty, b->second.tour_node), b->first);
                arcLabel.set(tour.addArc(b->second.tour_node, empty), "");
                offset += b->first.length();
            }
        }
        clog << "warning: Found " << components << " components; solution may be suboptimal by up to " << offset << " letters" << endl;
    }

    if (!lemon::eulerian(tour)) {
        clog << "error: failed to make tour graph Eulerian" << endl;
        return 1;
    }

    for (lemon::DiEulerIt<G> e(tour, empty); e != lemon::INVALID; ++e)
        cout << arcLabel[e];
    cout << endl;

    return 0;
}
```

Title: Compounding english


答:
JavaScript (ES6), 141

for(a=65,q=[],z=[];a<91;z.push(a++))q.push(String.fromCharCode(...z,a,...[...z].reverse()))
a=q.pop(),alert([...q,a,...q.reverse()].join`\n`)```

Title: Alphabet triangle


答:
R, <s>127</s> 125 bytes

```<code>k=cat;L=LETTERS;for(i in 1:26)k(c(L[1:i],L[(i-1):0],"\n"));for(i in 1:26)k(c(L[0:(26-i)],L[ifelse((25-i)>=0,25-i,0):0],"\n"))
</code>```

Not completely satisfied with this solution, especially the two for loops, but couldn't come with something better !

LETTERS contains the uppercase letters.

Ungolfed :

```<code>for(i in 1:26){
  cat(c(LETTERS[1:i],LETTERS[(i-1):0],"\n"))
               }

for(i in 1:26){
  cat(c(LETTERS[0:(26-i)],LETTERS[ifelse((25-i)>=0,25-i,0):0],"\n"))
               }
</code>```

ifelse is a shorter way for unsing if... else... and works this way : ifelse(condition,action if TRUE, action if FALSE)

An other 125 bytes' solution :

```<code>for(i in 1:26)(k=cat)(c((L=LETTERS)[1:i],L[(i-1):0],"\n"));for(i in 1:26)k(c(L[0:(26-i)],L[ifelse((25-i)>=0,25-i,0):0],"\n"))
</code>```

Title: Alphabet triangle

Body:
R, <s>127</s> 125 bytes

k=cat;L=LETTERS;for(i in 1:26)k(c(L[1:i],L[(i-1):0],"\n"));for(i in 1:26)k(c(L[0:(26-i)],L[ifelse((25-i)>=0,25-i,0):0],"\n"))

Not completely satisfied with this solution, especially the two for loops, but couldn't come with something better !

LETTERS contains the uppercase letters.

Ungolfed :

for(i in 1:26){
  cat(c(LETTERS[1:i],LETTERS[(i-1):0],"\n"))
               }

for(i in 1:26){
  cat(c(LETTERS[0:(26-i)],LETTERS[ifelse((25-i)>=0,25-i,0):0],"\n"))
               }

ifelse is a shorter way for unsing if... else... and works this way : ifelse(condition,action if TRUE, action if FALSE)

An other 125 bytes' solution :

for(i in 1:26)(k=cat)(c((L=LETTERS)[1:i],L[(i-1):0],"\n"));for(i in 1:26)k(c(L[0:(26-i)],L[ifelse((25-i)>=0,25-i,0):0],"\n"))


答:
Mathematica 59 bytes

```<code>Column@FromCharacterCode[#@#@26+64]&[#-Abs@Range[1-#,#-1]&]
</code>```

Title: Alphabet triangle

Body:
You are to print this exact text:

```<code>A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
ABCDEFGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYZYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGFEDCBA
ABCDEFEDCBA
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A
</code>```

Specs

Extra trailing newlines are allowed at the end of the output.

Extra trailing spaces (U+0020) are allowed at the end of each line, including the extra trailing newlines.

You can use all lowercase instead of all uppercase, but you cannot print partially lowercase partially uppercase.

You can return the text as a function output instead of printing it in a full program.

Scoring

Since this is a triangle, and a triangle has 3 sides, and 3 is a small number, your code should be small in terms of byte-count.

Body:
Mathematica 59 bytes

Column@FromCharacterCode[#@#@26+64]&[#-Abs@Range[1-#,#-1]&]


问:
Construct the Jacobian matrix
Take the vector of unknowns , and apply some generic differentiable function . The Jacobian is then given by a matrix  such that:

For example, suppose m=3 and n=2. Then (using 0-based indexing)

The Jacobian of f is then

The goal of this challenge is to print this Jacobian matrix.

Input

Your program/function should take as input two positive integers m and n, which represent the number of components of f and u respectively. The input may come from any source desired (stdio, function parameter, etc.). You may dictate the order in which these are received, and this must be consistent for any input to your answer (please specify in your answer).

Output

Something which represents the Jacobian matrix. This representation must explicitly spell out all elements of the Jacobian matrix, but the exact form of each term is implementation defined so long as is unambiguous what is being differentiated and with respect to what, and every entry is outputted in a logical order. Example acceptable forms for representing a matrix:

A list of lists where each entry of the outer list corresponds to a row of the Jacobian, and each entry of the inner list corresponds to a column of the Jacobian.

A string or textual output where each line is a row of the Jacobian, and each delimiter separated entry in a line corresponds to a column of the jacobian.

Some graphical/visual representation of a matrix. Example: what is shown by Mathematica when using the MatrixForm command

Some other dense matrix object where every entry is already stored in memory and can be queried (i.e. you can't use a generator object). Example  would be how Mathematica internally represents a Matrix object

Example entry formats:

A string of the form d f_i/d u_j, where i and j are integers. Ex: d f_1/d u_2. Note that these spaces between d and f_1 or x_2 are optional. Additionally, the underscores are also optional.

A string of the form d f_i(u_1,...,u_n)/d u_j or d f_i(u)/d u_j. That is, the input parameters of the function component f_i are optional, and can either be explicitly spelled out or left in compact form.

A formatted graphical output. Ex.: what Mathematica prints when you evaluate the expression D[f_1[u_,u_2,...,u_n],u_1]

You may choose what the starting index for u and f are (please specify in your answer). The output may be to any sink desired (stdio, return value, output parameter, etc.).

Test cases

The following test cases use the convention m,n. Indexes are shown 0-based.

```<code>1,1
[[d f0/d u0]]

2,1
[[d f0/d u0],
 [d f1/d u0]]

2 2
[[d f0/d u0, d f0/d u1],
 [d f1/d u0, d f1/d u1]]

1,2
[[d f0/d u0, d f0/d u1]]

3,3
[[d f0/d u0, d f0/d u1, d f0/d u2],
 [d f1/d u0, d f1/d u1, d f1/d u2],
 [d f2/d u0, d f2/d u1, d f2/d u2]]
</code>```

Scoring

This is code golf; shortest code in bytes wins. Standard loopholes are forbidden. You are allowed to use any built-ins desired.

答:
Python, 63 bytes

lambda m,n:["df%d/du%%d "%i*n%tuple(range(n))for i in range(m)]
```

<p>For <code>m=3,n=2</code>, outputs</p>

<pre class="lang-python prettyprint-override"><code>['df0/du0 df0/du1 ', 'df1/du0 df1/du1 ', 'df2/du0 df2/du1 ']
</code>```

The string formatting is 1 byte shorter than the more obvious

lambda m,n:[["df%d/du"%i+`j`for j in range(n)]for i in range(m)]
```

Title: Construct the Jacobian matrix

Body:
Python, 63 bytes

lambda m,n:["df%d/du%%d "%i*n%tuple(range(n))for i in range(m)]

For m=3,n=2, outputs

['df0/du0 df0/du1 ', 'df1/du0 df1/du1 ', 'df2/du0 df2/du1 ']

The string formatting is 1 byte shorter than the more obvious

lambda m,n:[["df%d/du"%i+`j`for j in range(n)]for i in range(m)]


答:
JavaScript (ES6), 122 bytes

_=>(s='',r=x=>[...x].reverse().join``,t=[...'ABCDEFGHIJKLMNOPQRSTUVWXYZ'].map(c=>s+c+r(s,s+=c)).join`
`)+r(t.slice(0,650))
```

<p>As an anonymous function. (4 more bytes if you want to <code>alert</code> it)</p>

<h2>Test</h2>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>document.write('```'+(

_=>(
  s='',
  r=x=>[...x].reverse().join``,
  t=
    [...'ABCDEFGHIJKLMNOPQRSTUVWXYZ']
    .map(c=>
      s+c+r(s,s+=c)
    ).join`\n`
)+r(t.slice(0,650))

)());```

Title: Alphabet triangle

Body:
JavaScript (ES6), 122 bytes

_=>(s='',r=x=>[...x].reverse().join``,t=[...'ABCDEFGHIJKLMNOPQRSTUVWXYZ'].map(c=>s+c+r(s,s+=c)).join`
`)+r(t.slice(0,650))

As an anonymous function. (4 more bytes if you want to alert it)

Test

document.write('<pre>'+(

_=>(
  s='',
  r=x=>[...x].reverse().join``,
  t=
    [...'ABCDEFGHIJKLMNOPQRSTUVWXYZ']
    .map(c=>
      s+c+r(s,s+=c)
    ).join`\n`
)+r(t.slice(0,650))

)());