问:
Help Sam understand chess
For this challenge, you will be writing a program or function which outputs (or prints) (in a reasonable format, i.e single string or an array of lines) a chess board which indicates all the possible moves of a piece given an empty board.

There are 5 chess pieces (for this challenge a pawn may be ignored):

Bishop (Moves diagonally any number of squares)

Rook (Moves orthogonally any number of squares)

Queen (Moves diagonally or orthogonally any number of squares)

KNight (Moves in an L shape, i.e. two in one dimension, and one in the other)

King (Moves one step orthogonally or diagonally)

Your submission will take in three inputs: the row of the chess piece, the column of the chess piece, and the type of piece (as a character or integer).

Say we call drawBoard(4,4,'N') for the Knight using 0-indexing, the output will be as follows:

```<code>........
........
...M.M..
..M...M.
....N...
..M...M.
...M.M..
........
</code>```

where the '.' and 'M' can be replaced accordingly with printable ascii characters of your choice.

Sample outputs as follows for other piece types. (Note all of these are called with input of 4,4 and are 0-indexed).

King:

```<code>........
........
........
...mmm..
...mKm..
...mmm..
........
........
</code>```

Rook:

```<code>....m...
....m...
....m...
....m...
mmmmRmmm
....m...
....m...
....m...
</code>```

Sam does not mind 1-based indexing, or even indexing following chess algebraic notation. However, your code must be as small as possible so Sam has enough space to think about his chess with the code next to him.

Sam has also realized that outputs will be accepted regardless of trailing or preceding whitespace (before and after input and each line)

答:
Java 8 lambda, <s>473</s> <s>435</s> 289 characters

Looks like this:

```<code>(R,C,f)->{String b="";for(int r=0,c,d,D;r<8;r++){for(c=0;c<8;c++){d=R-r<0?r-R:R-r;D=C-c<0?c-C:C-c;b+=R==r&&C==c?f:((f=='R'||f=='Q')&&(R==r||C==c))||((f=='B'||f=='Q')&&d==D)||(f=='K'&&((R==r&&D==1||C==c&&d==1)||(d==D&&d==1)))||(f=='N'&&(d==2&&D==1||d==1&&D==2))?"M":".";}b+="\n";}return b;}
</code>```

Or ungolfed into a class:

```<code>public class Q89429 {

    static String chessMoves(int row, int column, char figure) {
        String board = "";

        for (int r = 0, c, deltaRow, deltaColumn; r < 8; r++) {
            for (c = 0; c < 8; c++) {
                deltaRow = row - r < 0 ? r - row : row - r;
                deltaColumn = column - c < 0 ? c - column : column - c;
                board += row == r && column == c ?
                        figure :
                        ((figure == 'R' || figure == 'Q') && (row == r || column == c))
                        || ((figure == 'B' || figure == 'Q') && deltaRow == deltaColumn)
                        || (figure == 'K' && (
                                (row == r && deltaColumn == 1 || column == c && deltaRow == 1)
                                || (deltaRow == deltaColumn && deltaRow == 1)))
                        || (figure == 'N' && (deltaRow == 2 && deltaColumn == 1 || deltaRow == 1 && deltaColumn == 2))
                        ? "M" : ".";
            }
            board += "\n";
        }

        return board;
    }
}
</code>```

This is a TriFunction. It returns the chess field as a printable String. <s>I wanted to use streams, and it looks quite good. It's like a 2D iteration, may be shorter without the streams.</s> Switched to classic loops and saved a lot!

<s>It can definitely be shortened by using a ternary, I will do that now.</s>

Updates

Saved 38 characters by using a ternary.

Saved 146 characters by using good old loops. We should all abandon streams ;)

ContentLicense: CC BY-SA 4.0

Title: Help Sam understand chess

Body:
Java 8 lambda, <s>473</s> <s>435</s> 289 characters

Looks like this:

(R,C,f)->{String b="";for(int r=0,c,d,D;r<8;r++){for(c=0;c<8;c++){d=R-r<0?r-R:R-r;D=C-c<0?c-C:C-c;b+=R==r&&C==c?f:((f=='R'||f=='Q')&&(R==r||C==c))||((f=='B'||f=='Q')&&d==D)||(f=='K'&&((R==r&&D==1||C==c&&d==1)||(d==D&&d==1)))||(f=='N'&&(d==2&&D==1||d==1&&D==2))?"M":".";}b+="\n";}return b;}

Or ungolfed into a class:

public class Q89429 {

    static String chessMoves(int row, int column, char figure) {
        String board = "";

        for (int r = 0, c, deltaRow, deltaColumn; r < 8; r++) {
            for (c = 0; c < 8; c++) {
                deltaRow = row - r < 0 ? r - row : row - r;
                deltaColumn = column - c < 0 ? c - column : column - c;
                board += row == r && column == c ?
                        figure :
                        ((figure == 'R' || figure == 'Q') && (row == r || column == c))
                        || ((figure == 'B' || figure == 'Q') && deltaRow == deltaColumn)
                        || (figure == 'K' && (
                                (row == r && deltaColumn == 1 || column == c && deltaRow == 1)
                                || (deltaRow == deltaColumn && deltaRow == 1)))
                        || (figure == 'N' && (deltaRow == 2 && deltaColumn == 1 || deltaRow == 1 && deltaColumn == 2))
                        ? "M" : ".";
            }
            board += "\n";
        }

        return board;
    }
}

This is a TriFunction. It returns the chess field as a printable String. <s>I wanted to use streams, and it looks quite good. It's like a 2D iteration, may be shorter without the streams.</s> Switched to classic loops and saved a lot!

<s>It can definitely be shortened by using a ternary, I will do that now.</s>

Updates

Saved 38 characters by using a ternary.

Saved 146 characters by using good old loops. We should all abandon streams ;)


问:
Medieval orthography

Task

Your task is to convert a text into medieval orthography.

Details

j is converted to i and J to I.

u and U at the beginning of words are converted to v and V respectively.

v and V at anywhere except the beginning of words are converted to u and U respectively.

s is converted to ſ (U+017F) unless at the end of the word or preceded by another s.

Specs

A word is defined as a sequence of letters in abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.

All words will have at least two letters.

The input will only consist of printable ASCII characters (U+0020 - U+007E).

There will be no occurrences of more than two consecutive s. That is, sss will not be a substring of the input.

Testcases

Individual words:

```<code>Input       Output
------------------------
Joy         Ioy
joy         ioy
Universe    Vniuerſe
universe    vniuerſe
Success     Succeſs
successfull ſucceſsfull
Supervise   Superuiſe
supervise   ſuperuiſe
Super-vise  Super-viſe
I've        I've
majors      maiors
UNIVERSE    VNIUERSE
0universe   0vniuerſe
0verify     0verify
I0ve        I0ve
_UU_          _VU_
_VV_          _VU_
ss_         ſs_
</code>```

Whole paragraph:

```<code>Input:  Christian Reader, I have for thy use collected this small Concordance, with no small labour. For being to comprise much in little roome, I was to make choyse of the most principall and usefull places, and to rank them under such words as I thought most essentiall and materiall in the sentence, because the scant roome allotted unto me, would not permit that I should expresse them under every word in the verse, as it is the manner in large Concordances.

Output: Chriſtian Reader, I haue for thy vſe collected this ſmall Concordance, with no ſmall labour. For being to compriſe much in little roome, I was to make choyſe of the moſt principall and vſefull places, and to rank them vnder ſuch words as I thought moſt eſsentiall and materiall in the ſentence, becauſe the ſcant roome allotted vnto me, would not permit that I ſhould expreſse them vnder euery word in the verſe, as it is the manner in large Concordances.
</code>```

The SHA-256 hash of the output of the last testcase is:

```<code>5641899e7d55e6d1fc6e9aa4804f2710e883146bac0e757308afc58521621644
</code>```

Disclaimer

Medievall orthographie is not that conſtante. Pleaſe do not complayne if you ſhall ſee olde bookes with a different orthographie.

答:
SED, 144 140 111 Bytes

saved 29 bytes thanks to NoOneIsHere

```<code>-r -e'y/j/i/g;y/J/I/g;s/ u/ v/g;s/ U/ V/g;s/^u/v/g;s/^U/V/g;s/([^s])s(\w)/\1ſ\2/g;s/(\w)v/\1u/g;s/(\w)V/\1U/g'
</code>```

ContentLicense: CC BY-SA 3.0

Title: Medieval orthography

Body:
SED, 144 140 111 Bytes

saved 29 bytes thanks to NoOneIsHere

-r -e'y/j/i/g;y/J/I/g;s/ u/ v/g;s/ U/ V/g;s/^u/v/g;s/^U/V/g;s/([^s])s(\w)/\1ſ\2/g;s/(\w)v/\1u/g;s/(\w)V/\1U/g'


Title: Help Sam understand chess

Body:
For this challenge, you will be writing a program or function which outputs (or prints) (in a reasonable format, i.e single string or an array of lines) a chess board which indicates all the possible moves of a piece given an empty board.

There are 5 chess pieces (for this challenge a pawn may be ignored):

Bishop (Moves diagonally any number of squares)

Rook (Moves orthogonally any number of squares)

Queen (Moves diagonally or orthogonally any number of squares)

KNight (Moves in an L shape, i.e. two in one dimension, and one in the other)

King (Moves one step orthogonally or diagonally)

Your submission will take in three inputs: the row of the chess piece, the column of the chess piece, and the type of piece (as a character or integer).

Say we call drawBoard(4,4,'N') for the Knight using 0-indexing, the output will be as follows:

```<code>........
........
...M.M..
..M...M.
....N...
..M...M.
...M.M..
........
</code>```

where the '.' and 'M' can be replaced accordingly with printable ascii characters of your choice.

Sample outputs as follows for other piece types. (Note all of these are called with input of 4,4 and are 0-indexed).

King:

```<code>........
........
........
...mmm..
...mKm..
...mmm..
........
........
</code>```

Rook:

```<code>....m...
....m...
....m...
....m...
mmmmRmmm
....m...
....m...
....m...
</code>```

Sam does not mind 1-based indexing, or even indexing following chess algebraic notation. However, your code must be as small as possible so Sam has enough space to think about his chess with the code next to him.

Sam has also realized that outputs will be accepted regardless of trailing or preceding whitespace (before and after input and each line)

Body:
Ruby, 209 Bytes

->v,a,b{R=->x,y{x==a||y==b};B=->x,y{x-y==a-b||a-x==y-b};Q=->x,y{R.(x,y)||B.(x,y)};K=->x,y{((x-a).i+y-b).abs<2};N=->x,y{((a-x)*(b-y)).abs==2};(r=(0..7)).map{|x|r.map{|y|[x,y]==[a,b]?v: eval(v+".(x,y)??x:?o")}}}

This is a lambda that makes use of other lambdas, defined inside.


问:
Lemon-Limify a String
Write a program or function that takes in a nonempty single-line string. You may assume it only contains printable ASCII excluding space.

Print or return an ASCII art lozenge shape similar to a lemon or lime made from the prefixes of the string.

Suppose the input string is n letters long. Then, such a shape consists of 2n − 1 columns of ASCII art stitched together, each consisting of 2n − 1 lines. Counting from 1, the k-th column is f(k) = min(k, 2n − k) characters wide, and contains f(k) copies of the first f(k) characters of input, centered vertically, with single blank lines separating the copies.

For example, if the input is Lemon, the output should be:

```<code>          Lemon
      Lemo     Lemo
   Lem    Lemon    Lem
 Le   Lemo     Lemo   Le
L  Lem    Lemon    Lem  L
 Le   Lemo     Lemo   Le
   Lem    Lemon    Lem
      Lemo     Lemo
          Lemon
</code>```

If the input is lime the output should be:

```<code>      lime
   lim    lim
 li   lime   li
l  lim    lim  l
 li   lime   li
   lim    lim
      lime
</code>```

And the same pattern is followed for other inputs:

```<code>a

a

Be

 Be
B  B
 Be

/\

 /\
/  /
 /\

cat

   cat
 ca   ca
c  cat  c
 ca   ca
   cat

|||

   |||
 ||   ||
|  |||  |
 ||   ||
   |||

.__.

      .__.
   .__    .__
 ._   .__.   ._
.  .__    .__  .
 ._   .__.   ._
   .__    .__
      .__.

$tring

               $tring
          $trin      $trin
      $tri     $tring     $tri
   $tr    $trin      $trin    $tr
 $t   $tri     $tring     $tri   $t
$  $tr    $trin      $trin    $tr  $
 $t   $tri     $tring     $tri   $t
   $tr    $trin      $trin    $tr
      $tri     $tring     $tri
          $trin      $trin
               $tring
</code>```

Lines in the output may have trailing spaces and there may be one optional trailing newline.

The shortest code in bytes wins.

答:
Matlab, <s>140 136 128</s> 124 bytes

Basically first starts with the middle section, and then prepends/appends the shortened/modified versions step by step.

```<code>a=input('');v=ones(nnz(a)*2-1,1)*a;v(2:2:end,:)=0;b=v;for k=a;v=v(2:end,1:end-1);v(end+1,:)=0;b=[v,b,v,''];end;b(~flip(b))=0
</code>```

Thanks for 8 bytes @LuisMendo!

E.g. for MATLAB we get:

```<code>               MATLAB
          MATLA      MATLA
      MATL     MATLAB     MATL
   MAT    MATLA      MATLA    MAT
 MA   MATL     MATLAB     MATL   MA
M  MAT    MATLA      MATLA    MAT  M
 MA   MATL     MATLAB     MATL   MA
   MAT    MATLA      MATLA    MAT
      MATL     MATLAB     MATL
          MATLA      MATLA
               MATLAB
</code>```

Title: Lemon-Limify a String

Body:
Matlab, <s>140 136 128</s> 124 bytes

Basically first starts with the middle section, and then prepends/appends the shortened/modified versions step by step.

a=input('');v=ones(nnz(a)*2-1,1)*a;v(2:2:end,:)=0;b=v;for k=a;v=v(2:end,1:end-1);v(end+1,:)=0;b=[v,b,v,''];end;b(~flip(b))=0

Thanks for 8 bytes @LuisMendo!

E.g. for MATLAB we get:

               MATLAB
          MATLA      MATLA
      MATL     MATLAB     MATL
   MAT    MATLA      MATLA    MAT
 MA   MATL     MATLAB     MATL   MA
M  MAT    MATLA      MATLA    MAT  M
 MA   MATL     MATLAB     MATL   MA
   MAT    MATLA      MATLA    MAT
      MATL     MATLAB     MATL
          MATLA      MATLA
               MATLAB


问:
Smile! Just smile
It's well known that Brainf*ck is very bad at Kolmogorov-complexity problems, for example, it requires around 100 characters just to print "Hello world".

However, there might be texts where Brainf*ck is just very good at.

Your task is now to write a program that takes no input, and it displays the following:

```<code>☺
</code>```

That is, a smiley face (ASCII 1, if you browser does not render it).

Brainf*ck can do it in 2 characters.

```<code>+.
</code>```

Try to find a language that beats it!

We assume your console can actually display that character (or your font has it, etc.).

Shortest code wins. If there are more of the same length, the first wins, but I'll upvote the others as well.

EDIT: I'm very sorry, I did not think the first post arrives this soon. A quick edit: the language has to be Turing-complete!

答:
FALSE (2)

```<code>1,
</code>```

All that reading about BF paid off! False is an ancestor of Brainfuck.

Title: Smile! Just smile

Body:
FALSE (2)

1,

All that reading about BF paid off! False is an ancestor of Brainfuck.


问:
Is it a Proth number?
A Proth number, named after François Proth, is a number that can be expressed as

$$N = k \times 2^n + 1$$

Where \$k\$ is an odd positive integer and \$n\$ is a positive integer such that \$2^n > k\$. Let's use a more concrete example. Take 3. 3 is a Proth number because it can be written as

$$ 3 = (1 \times 2^1) + 1 $$

and \$2^1 > 1\$ is satisfied. 5 Is also a Proth number because it can be written as

$$ 5 = (1 \times 2^2) + 1 $$

and \$2^2 > 1\$ is satisfied. However, 7 is not a Proth number because the only way to write it in the form \$N = k \times 2^n + 1\$ is

$$ 7 = (3 \times 2^1) + 1 $$

and \$2^1 > 3\$ is not satisfied.

Your challenge is fairly simple: you must write a program or function that, given a positive integer, determines if it is a Proth number or not. You may take input in any reasonable format, and should output a truthy value if it is a Proth number and a falsy value if it is not. If your language has any "Proth-number detecting" functions, you may use them.

Test IO

Here are the first 46 Proth numbers up to 1000. (A080075)

```<code>3, 5, 9, 13, 17, 25, 33, 41, 49, 57, 65, 81, 97, 113, 129, 145, 161, 177, 193, 209, 225, 241, 257, 289, 321, 353, 385, 417, 449, 481, 513, 545, 577, 609, 641, 673, 705, 737, 769, 801, 833, 865, 897, 929, 961, 993
</code>```

Every other valid input should give a falsy value.

As usual, this is code-golf, so standard loopholes apply, and the shortest answer in bytes wins!

Number theory fun-fact side-note:

The largest known prime that is not a Mersenne Prime is \$19249 \times 2^{13018586} + 1\$, which just so happens to also be a Proth number!

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

Thanks to Emigna for saving 4 bytes!

Code:

```<code><©Ó¬oD®s/›
</code>```

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

Explanation:

For the explanation, let's use the number 241. We first decrement the number by one with <. That results into 240. Now, we calculate the prime factors (with duplicates) using Ò. The prime factors are:

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

We split them into two parts. Using 2Q·0K, we get the list of two's:

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

With ®2K, we get the list of the remaining numbers:

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

Finally, take the product of both. [2, 2, 2, 2] results into 16. The product of [3, 5] results into 15.

This test case is truthy since 16 > 15.

Title: Is it a Proth number?

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

Thanks to Emigna for saving 4 bytes!

Code:

<©Ó¬oD®s/›

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

Explanation:

For the explanation, let's use the number 241. We first decrement the number by one with <. That results into 240. Now, we calculate the prime factors (with duplicates) using Ò. The prime factors are:

[2, 2, 2, 2, 3, 5]

We split them into two parts. Using 2Q·0K, we get the list of two's:

[2, 2, 2, 2]

With ®2K, we get the list of the remaining numbers:

[3, 5]

Finally, take the product of both. [2, 2, 2, 2] results into 16. The product of [3, 5] results into 15.

This test case is truthy since 16 > 15.


Title: Is it a Proth number?

Body:
A Proth number, named after François Proth, is a number that can be expressed as

$$N = k \times 2^n + 1$$

Where \$k\$ is an odd positive integer and \$n\$ is a positive integer such that \$2^n > k\$. Let's use a more concrete example. Take 3. 3 is a Proth number because it can be written as

$$ 3 = (1 \times 2^1) + 1 $$

and \$2^1 > 1\$ is satisfied. 5 Is also a Proth number because it can be written as

$$ 5 = (1 \times 2^2) + 1 $$

and \$2^2 > 1\$ is satisfied. However, 7 is not a Proth number because the only way to write it in the form \$N = k \times 2^n + 1\$ is

$$ 7 = (3 \times 2^1) + 1 $$

and \$2^1 > 3\$ is not satisfied.

Your challenge is fairly simple: you must write a program or function that, given a positive integer, determines if it is a Proth number or not. You may take input in any reasonable format, and should output a truthy value if it is a Proth number and a falsy value if it is not. If your language has any "Proth-number detecting" functions, you may use them.

Test IO

Here are the first 46 Proth numbers up to 1000. (A080075)

```<code>3, 5, 9, 13, 17, 25, 33, 41, 49, 57, 65, 81, 97, 113, 129, 145, 161, 177, 193, 209, 225, 241, 257, 289, 321, 353, 385, 417, 449, 481, 513, 545, 577, 609, 641, 673, 705, 737, 769, 801, 833, 865, 897, 929, 961, 993
</code>```

Every other valid input should give a falsy value.

As usual, this is code-golf, so standard loopholes apply, and the shortest answer in bytes wins!

Number theory fun-fact side-note:

The largest known prime that is not a Mersenne Prime is \$19249 \times 2^{13018586} + 1\$, which just so happens to also be a Proth number!

Body:
Mathematica, <s>50</s> <s>48</s> <s>45</s> <s>40</s> <s>38</s> <s>35</s> <s>31</s> 29 bytes

Mathematica generally sucks when it comes to code golf, but sometimes there's a built-in that makes things look really nice.

1<#<4^IntegerExponent[#-1,2]&

A test:

Reap[Do[If[f[i],Sow[i]],{i,1,1000}]][[2,1]]

{3, 5, 9, 13, 17, 25, 33, 41, 49, 57, 65, 81, 97, 113, 129, 145, 161, 177, 193, 209, 225, 241, 257, 289, 321, 353, 385, 417, 449, 481, 513, 545, 577, 609, 641, 673, 705, 737, 769, 801, 833, 865, 897, 929, 961, 993}

Edit: Actually, if I steal Dennis's bitwise AND idea, I can get it down to <s>23</s> <s>22</s> 20 bytes.

Mathematica, <s>23</s> <s>22</s> 20 bytes (thanks A Simmons)

BitAnd[#-1,1-#]^2>#&


答:
Jelly, 5 bytes

```<code>’&C²>
</code>```

Try it online! or verify all test cases.

Let \$\newcommand{\&}[]{\text{ & }}j\$ be a strictly positive integer. \$j + 1\$ toggles all trailing set bits of \$j\$ and the adjacent unset bit. For example, \$10011_{2} + 1 = 10100_{2}\$.

Since \${\sim}j = -(j + 1) = -j - 1\$, \$-j = {\sim}j + 1\$, so \$-n\$ applies the above to the bitwise NOT of \$j\$ (which toggles all bits), thus toggling all bits before the last \$1\$.

By taking \$j \& (-j)\$ (the bitwise AND of \$j\$ and \$-j\$), all bits before and after the last set bit are nullified (since unequal in \$j\$ and \$-j\$), thus yielding the highest power of \$2\$ that divides \$j\$ evenly.

For input \$N\$, we want to apply the above to \$N - 1\$ to find \$2^{n}\$, the highest power of \$2\$ that divides \$N - 1\$. If \$m = N - 1\$, \$-m = -(N - 1) = 1 - N\$, so \$(N - 1) \& (1 - N)\$ yields \$2^{n}\$.

All that's left to test is if \$2^{n} > k\$. If \$k > 0\$, this is true if and only if \$(2^{n})^{2} > k2^{n}\$, which is true itself if and only if \$(2^{n})^{2} \ge k2^{n} + 1 = N\$.

Finally, if \$(2^{n})^{2} = N = k2^{n} + 1\$, \$2^{n}\$ must be odd (\$1\$) so the parities of both sides can match, implying that \$k = 0\$ and \$N = 1\$. In this case \$(N - 1) \& (1 - N) = 0 \& 0 = 0\$ and \$((N - 1) \& (1 - N))^{2} = 0 < 1 = N\$.

Therefore, \$((N - 1) \& (1 - N))^{2} > N\$ is true if and only if \$N\$ is a Proth number.

How it works

```<code>’&C²>  Main link. Argument: N

’      Decrement; yield N - 1.
  C    Complement; yield 1 - N.
 &     Take the bitwise AND of both results.
   ²   Square the bitwise AND.
    >  Compare the square to N.
</code>```

Title: Is it a Proth number?

Body:
Jelly, 5 bytes

’&C²>

Try it online! or verify all test cases.

Let \$\newcommand{\&}[]{\text{ & }}j\$ be a strictly positive integer. \$j + 1\$ toggles all trailing set bits of \$j\$ and the adjacent unset bit. For example, \$10011_{2} + 1 = 10100_{2}\$.

Since \${\sim}j = -(j + 1) = -j - 1\$, \$-j = {\sim}j + 1\$, so \$-n\$ applies the above to the bitwise NOT of \$j\$ (which toggles all bits), thus toggling all bits before the last \$1\$.

By taking \$j \& (-j)\$ (the bitwise AND of \$j\$ and \$-j\$), all bits before and after the last set bit are nullified (since unequal in \$j\$ and \$-j\$), thus yielding the highest power of \$2\$ that divides \$j\$ evenly.

For input \$N\$, we want to apply the above to \$N - 1\$ to find \$2^{n}\$, the highest power of \$2\$ that divides \$N - 1\$. If \$m = N - 1\$, \$-m = -(N - 1) = 1 - N\$, so \$(N - 1) \& (1 - N)\$ yields \$2^{n}\$.

All that's left to test is if \$2^{n} > k\$. If \$k > 0\$, this is true if and only if \$(2^{n})^{2} > k2^{n}\$, which is true itself if and only if \$(2^{n})^{2} \ge k2^{n} + 1 = N\$.

Finally, if \$(2^{n})^{2} = N = k2^{n} + 1\$, \$2^{n}\$ must be odd (\$1\$) so the parities of both sides can match, implying that \$k = 0\$ and \$N = 1\$. In this case \$(N - 1) \& (1 - N) = 0 \& 0 = 0\$ and \$((N - 1) \& (1 - N))^{2} = 0 < 1 = N\$.

Therefore, \$((N - 1) \& (1 - N))^{2} > N\$ is true if and only if \$N\$ is a Proth number.

How it works

’&C²>  Main link. Argument: N

’      Decrement; yield N - 1.
  C    Complement; yield 1 - N.
 &     Take the bitwise AND of both results.
   ²   Square the bitwise AND.
    >  Compare the square to N.


答:
Python 2, 23 bytes

lambda n:(~-n&1-n)**2>n
```

Title: Is it a Proth number?


答:
Python, 22 bytes

lambda N:N-1&1-N>N**.5
```

This is a port of my Jelly answer. Test it on Ideone.

How it works

Let \$\newcommand{\&}[]{\text{ & }}j\$ be a strictly positive integer. \$j + 1\$ toggles all trailing set bits of \$j\$ and the adjacent unset bit. For example, \$10011_{2} + 1 = 10100_{2}\$.

Since \${\sim}j = -(j + 1) = -j - 1\$, \$-j = {\sim}j + 1\$, so \$-n\$ applies the above to the bitwise NOT of \$j\$ (which toggles all bits), thus toggling all bits before the last \$1\$.

By taking \$j \& (-j)\$ (the bitwise AND of \$j\$ and \$-j\$), all bits before and after the last set bit are nullified (since unequal in \$j\$ and \$-j\$), thus yielding the highest power of \$2\$ that divides \$j\$ evenly.

For input \$N\$, we want to apply the above to \$N - 1\$ to find \$2^{n}\$, the highest power of \$2\$ that divides \$N - 1\$. If \$m = N - 1\$, \$-m = -(N - 1) = 1 - N\$, so \$(N - 1) \& (1 - N)\$ yields \$2^{n}\$.

All that's left to test is if \$2^{n} > k\$. If \$k > 0\$, this is true if and only if \$(2^{n})^{2} > k2^{n}\$, which is true itself if and only if \$(2^{n})^{2} \ge k2^{n} + 1 = N\$.

Finally, if \$(2^{n})^{2} = N = k2^{n} + 1\$, \$2^{n}\$ must be odd (\$1\$) so the parities of both sides can match, implying that \$k = 0\$ and \$N = 1\$. In this case \$(N - 1) \& (1 - N) = 0 \& 0 = 0\$ and \$((N - 1) \& (1 - N))^{2} = 0 < 1 = N\$.

Therefore, \$((N - 1) \& (1 - N))^{2} > N\$ is true if and only if \$N\$ is a Proth number.

Ignoring floating point inaccuracies, this is equivalent to the code N-1&1-N>N**.5 in the implementation.

Title: Is it a Proth number?

Body:
Python, 22 bytes

lambda N:N-1&1-N>N**.5

This is a port of my Jelly answer. Test it on Ideone.

How it works

Let \$\newcommand{\&}[]{\text{ & }}j\$ be a strictly positive integer. \$j + 1\$ toggles all trailing set bits of \$j\$ and the adjacent unset bit. For example, \$10011_{2} + 1 = 10100_{2}\$.

Since \${\sim}j = -(j + 1) = -j - 1\$, \$-j = {\sim}j + 1\$, so \$-n\$ applies the above to the bitwise NOT of \$j\$ (which toggles all bits), thus toggling all bits before the last \$1\$.

By taking \$j \& (-j)\$ (the bitwise AND of \$j\$ and \$-j\$), all bits before and after the last set bit are nullified (since unequal in \$j\$ and \$-j\$), thus yielding the highest power of \$2\$ that divides \$j\$ evenly.

For input \$N\$, we want to apply the above to \$N - 1\$ to find \$2^{n}\$, the highest power of \$2\$ that divides \$N - 1\$. If \$m = N - 1\$, \$-m = -(N - 1) = 1 - N\$, so \$(N - 1) \& (1 - N)\$ yields \$2^{n}\$.

All that's left to test is if \$2^{n} > k\$. If \$k > 0\$, this is true if and only if \$(2^{n})^{2} > k2^{n}\$, which is true itself if and only if \$(2^{n})^{2} \ge k2^{n} + 1 = N\$.

Finally, if \$(2^{n})^{2} = N = k2^{n} + 1\$, \$2^{n}\$ must be odd (\$1\$) so the parities of both sides can match, implying that \$k = 0\$ and \$N = 1\$. In this case \$(N - 1) \& (1 - N) = 0 \& 0 = 0\$ and \$((N - 1) \& (1 - N))^{2} = 0 < 1 = N\$.

Therefore, \$((N - 1) \& (1 - N))^{2} > N\$ is true if and only if \$N\$ is a Proth number.

Ignoring floating point inaccuracies, this is equivalent to the code N-1&1-N>N**.5 in the implementation.


问:
Count the number of vowels in each word of a string
This is a rather easy challenge.

Challenge

Input will contain a string (not null or empty) of maximum length 100. Output the number of vowels in each word of the string, separated by spaces.

Rules

The string will not be more than 100 characters in length.

The string will only contain alphabets A-Z , a-z and can also contain spaces.

Input must be consumed from the stdin or command line arguments.

Output must be outputted in the stdout.

You can write a full program, or a function that takes input from the stdin and outputs the result.

The vowels that your program/function needs to count are aeiou and AEIOU.

Test Cases

```<code>This is the first test case     --> 1 1 1 1 1 2
one plus two equals three       --> 2 1 1 3 2
aeiou AEIOU                     --> 5 5
psst                            --> 0
the quick brown fox jumped over the lazy dog --> 1 2 1 1 2 2 1 1 1
</code>```

Scoring

This is code-golf, so the shortest submission (in bytes) wins.

答:
PowerShell, 65 bytes

```<code>($input-split'\s'|%{($_-split''-match'a|e|i|o|u').count})-join' '
</code>```

test by using the pattern below after saving as vowels.ps1

```<code>"the quick brown fox" | vowels.ps1
</code>```

This way it is an actual script and not just a code snippet thereby satisfying constraint:

"Input must be consumed from the stdin or command line arguments."

Body:
PowerShell, 65 bytes

($input-split'\s'|%{($_-split''-match'a|e|i|o|u').count})-join' '

test by using the pattern below after saving as vowels.ps1

"the quick brown fox" | vowels.ps1

This way it is an actual script and not just a code snippet thereby satisfying constraint:

"Input must be consumed from the stdin or command line arguments."


问:
Only Even Bytes

The scenario

Lately you have been noticing some strange behavior with your favorite text editor. At first it seemed that it was ignoring random characters in your code when writing to disk. After a while you noticed a pattern; characters with odd ASCII values were being ignored. Under further inspection you discovered that you can only write to files properly if every eighth bit is zero.  Now you need to know if your valuable files have been affected by this strange bug.

The task

You must write a complete program that determines if a file contains any odd bytes (demonstrating it is uncorrupted).  But because of your text editor you cannot write any odd bytes in your source code. You may assume any pre-existing encoding for input, however you must still check every individual byte, not just characters.

Input

Your program will take the contents of or the path to a file from either stdin or command line.

Output

Your program will output to stdout either a truthy value if the given file contains an odd byte or a falsy if every eighth bit is zero.

Criteria

This is code golf, shortest program that completes the task wins.  To be a valid submission every eighth bit in the files source code must be a zero.  I would recommend including a copy of your source code's binaries in your submission.

Standard loopholes apply.

Test Cases

(In ASCII encoding)
    Input:

```<code>"$&(*,.02468:<>@BDFHJLNPRTVXZ\^`bdfhjlnprtvxz|~

Output:
falsy

Input:
!#%')+-/13579;=?ACEGIKMOQSUWY[]_acegikmoqsuwy{}

Output:
truthy

Input:
LOREMIPSVMDOLORSITAMETCONSECTETVRADIPISCINGELITSEDDOEIVSMODTEMPORINCIDIDVNTVTLABOREETDOLOREMAGNAALIQVA
VTENIMADMINIMVENIAMQVISNOSTRVDEXERCITATIONVLLAMCOLABORISNISIVTALIQVIPEXEACOMMODOCONSEQVAT
DVISAVTEIRVREDOLORINREPREHENDERITINVOLVPTATEVELITESSECILLVMDOLOREEVFVGIATNVLLAPARIATVR
EXCEPTEVRSINTOCCAECATCVPIDATATNONPROIDENTSVNTINCVLPAQVIOFFICIADESERVNTMOLLITANIMIDESTLABORVM

Output:
truthy
</code>```

Tips

Choose language wisely this challenge might not be possible in every language

The Unix command xxd -b <file name> will print the binaries of a file to the console (along with some extra formatting stuff)

You may use other encodings other than ASCII such as UTF-8 as long as all other rules are followed

答:
Printable .COM file, 100 bytes

```<code>^FZjfDXVL\,LPXD$$4"PXD,lHPXDjJXDRDX@PXDjtXDH,nPXDj@XD4`@PXD,ZHPXD4,@PXD4:4"PXDH,\PXD4"PXD,hPXDRDX@P\
</code>```

Hexdump:

```<code>00000000  5e 46 5a 6a 66 44 58 56  4c 5c 2c 4c 50 58 44 24  |^FZjfDXVL\,LPXD$|
00000010  24 34 22 50 58 44 2c 6c  48 50 58 44 6a 4a 58 44  |$4"PXD,lHPXDjJXD|
00000020  52 44 58 40 50 58 44 6a  74 58 44 48 2c 6e 50 58  |RDX@PXDjtXDH,nPX|
00000030  44 6a 40 58 44 34 60 40  50 58 44 2c 5a 48 50 58  |Dj@XD4`@PXD,ZHPX|
00000040  44 34 2c 40 50 58 44 34  3a 34 22 50 58 44 48 2c  |D4,@PXD4:4"PXDH,|
00000050  5c 50 58 44 34 22 50 58  44 2c 68 50 58 44 52 44  |\PXD4"PXD,hPXDRD|
00000060  58 40 50 5c                                       |X@P\|
00000064
</code>```

Using a very loose definition of source as something that can be reasonably typed by a human, and inspired by EICAR Standard Antivirus Test File (more info at "Let's have fun with EICAR test file" at Bugtraq).

Using only printable non-odd ASCII bytes (side note: opcodes affecting words tend to be odd, the W bit is the lsb of some opcodes), it constructs a fragment of code at SP (which we conveniently set just past our generating code), and execution ends up falling through to the generated code.

It uses the fact that the stack initially contains a near pointer to the start of the PSP, and that the start of the PSP contains the INT 20h instruction (more info on this at https://stackoverflow.com/questions/12591673/).

Real source:

```<code>; we want to generate the following fragment of code

;  5E                pop si             ; zero SI (pop near pointer to start of PSP)
;  46                inc si             ; set SI to 1
; loop:
;  B406              mov ah,0x6         ; \
;  99                cwd                ; >
;  4A                dec dx             ; > D-2106--DLFF
;  CD21              int 0x21           ; > DIRECT CONSOLE INPUT
;  7405              jz end             ; > jump if no more input
;  40                inc ax             ; > lsb 0/1 odd/even
;  21C6              and si,ax          ; > zero SI on first odd byte
;  EBF3              jmp short loop     ; /
; end:
;  96                xchg ax,si         ; return code
;  B44C              mov ah,0x4c        ; D-214C
;  CD21              int 0x21           ; TERMINATE WITH RETURN CODE

 pop si             ; this two opcodes don't need to be encoded
 inc si

 pop dx             ; DX = 20CD (int 0x20 at start of PSP)
 push byte +0x66
 inc sp
 pop ax
 push si
 dec sp
 pop sp             ; SP = 0x0166
 sub al,0x4c        ; B4
 push ax
 pop ax
 inc sp
 and al,0x24
 xor al,0x22        ; 06
 push ax
 pop ax
 inc sp
 sub al,0x6c
 dec ax             ; 99
 push ax
 pop ax
 inc sp
 push byte +0x4a    ; 4A
 pop ax
 inc sp
 push dx            ; [20]CD
 inc sp
 pop ax
 inc ax             ; 21
 push ax
 pop ax
 inc sp
 push byte +0x74    ; 74
 pop ax
 inc sp
 dec ax
 sub al,0x6e        ; 05
 push ax
 pop ax
 inc sp
 push byte +0x40    ; 40
 pop ax
 inc sp
 xor al,0x60
 inc ax             ; 21
 push ax
 pop ax
 inc sp
 sub al,0x5a
 dec ax             ; C6
 push ax
 pop ax
 inc sp
 xor al,0x2c
 inc ax             ; EB
 push ax
 pop ax
 inc sp
 xor al,0x3a
 xor al,0x22        ; F3
 push ax
 pop ax
 inc sp
 dec ax
 sub al,0x5c        ; 96
 push ax
 pop ax
 inc sp
 xor al,0x22        ; B4
 push ax
 pop ax
 inc sp
 sub al,0x68        ; 4C
 push ax
 pop ax
 inc sp
 push dx            ; [20]CD
 inc sp
 pop ax
 inc ax
 push ax            ; 21
 pop sp             ; now get the stack out of the way
</code>```

Title: Only Even Bytes

Body:
Printable .COM file, 100 bytes

^FZjfDXVL\,LPXD$$4"PXD,lHPXDjJXDRDX@PXDjtXDH,nPXDj@XD4`@PXD,ZHPXD4,@PXD4:4"PXDH,\PXD4"PXD,hPXDRDX@P\

Hexdump:

00000000  5e 46 5a 6a 66 44 58 56  4c 5c 2c 4c 50 58 44 24  |^FZjfDXVL\,LPXD$|
00000010  24 34 22 50 58 44 2c 6c  48 50 58 44 6a 4a 58 44  |$4"PXD,lHPXDjJXD|
00000020  52 44 58 40 50 58 44 6a  74 58 44 48 2c 6e 50 58  |RDX@PXDjtXDH,nPX|
00000030  44 6a 40 58 44 34 60 40  50 58 44 2c 5a 48 50 58  |Dj@XD4`@PXD,ZHPX|
00000040  44 34 2c 40 50 58 44 34  3a 34 22 50 58 44 48 2c  |D4,@PXD4:4"PXDH,|
00000050  5c 50 58 44 34 22 50 58  44 2c 68 50 58 44 52 44  |\PXD4"PXD,hPXDRD|
00000060  58 40 50 5c                                       |X@P\|
00000064

Using a very loose definition of source as something that can be reasonably typed by a human, and inspired by EICAR Standard Antivirus Test File (more info at "Let's have fun with EICAR test file" at Bugtraq).

Using only printable non-odd ASCII bytes (side note: opcodes affecting words tend to be odd, the W bit is the lsb of some opcodes), it constructs a fragment of code at SP (which we conveniently set just past our generating code), and execution ends up falling through to the generated code.

It uses the fact that the stack initially contains a near pointer to the start of the PSP, and that the start of the PSP contains the INT 20h instruction (more info on this at https://stackoverflow.com/questions/12591673/).

Real source:

; we want to generate the following fragment of code

;  5E                pop si             ; zero SI (pop near pointer to start of PSP)
;  46                inc si             ; set SI to 1
; loop:
;  B406              mov ah,0x6         ; \
;  99                cwd                ; >
;  4A                dec dx             ; > D-2106--DLFF
;  CD21              int 0x21           ; > DIRECT CONSOLE INPUT
;  7405              jz end             ; > jump if no more input
;  40                inc ax             ; > lsb 0/1 odd/even
;  21C6              and si,ax          ; > zero SI on first odd byte
;  EBF3              jmp short loop     ; /
; end:
;  96                xchg ax,si         ; return code
;  B44C              mov ah,0x4c        ; D-214C
;  CD21              int 0x21           ; TERMINATE WITH RETURN CODE

 pop si             ; this two opcodes don't need to be encoded
 inc si

 pop dx             ; DX = 20CD (int 0x20 at start of PSP)
 push byte +0x66
 inc sp
 pop ax
 push si
 dec sp
 pop sp             ; SP = 0x0166
 sub al,0x4c        ; B4
 push ax
 pop ax
 inc sp
 and al,0x24
 xor al,0x22        ; 06
 push ax
 pop ax
 inc sp
 sub al,0x6c
 dec ax             ; 99
 push ax
 pop ax
 inc sp
 push byte +0x4a    ; 4A
 pop ax
 inc sp
 push dx            ; [20]CD
 inc sp
 pop ax
 inc ax             ; 21
 push ax
 pop ax
 inc sp
 push byte +0x74    ; 74
 pop ax
 inc sp
 dec ax
 sub al,0x6e        ; 05
 push ax
 pop ax
 inc sp
 push byte +0x40    ; 40
 pop ax
 inc sp
 xor al,0x60
 inc ax             ; 21
 push ax
 pop ax
 inc sp
 sub al,0x5a
 dec ax             ; C6
 push ax
 pop ax
 inc sp
 xor al,0x2c
 inc ax             ; EB
 push ax
 pop ax
 inc sp
 xor al,0x3a
 xor al,0x22        ; F3
 push ax
 pop ax
 inc sp
 dec ax
 sub al,0x5c        ; 96
 push ax
 pop ax
 inc sp
 xor al,0x22        ; B4
 push ax
 pop ax
 inc sp
 sub al,0x68        ; 4C
 push ax
 pop ax
 inc sp
 push dx            ; [20]CD
 inc sp
 pop ax
 inc ax
 push ax            ; 21
 pop sp             ; now get the stack out of the way


问:
Palindrome Hello, World
Your task is to create a program that prints "Greetings, Planet!" exactly to the console. Seems simple enough, right? Well, here's the trick. The code must be a palindrome, meaning it reads from right to left the same as in left to right.
Standard loopholes are NOT allowed.

答:
Nim, 49 bytes

echo"Greetings, Planet!"#"!tenalP ,sgniteerG"ohce
```

Pretty self-explanatory. Uses Nim's short echo syntax and a comment to create the palindrome.

Title: Palindrome Hello, World

Body:
Nim, 49 bytes

echo"Greetings, Planet!"#"!tenalP ,sgniteerG"ohce

Pretty self-explanatory. Uses Nim's short echo syntax and a comment to create the palindrome.


答:
Swift, 68 Bytes

```<code>func f(n:Int,_ a:Int=1,_ b:Int=1)->Int{return n<1 ?1:a*f(n-1,b,a+b)}
</code>```

Title: Fibonacci-orial

Body:
Definition

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

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

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

Task

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

Specs

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

Testcases

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

References

Obligatory OEIS A003266

OEIS A000045 - Fibonacci sequence

Body:
Swift, 68 Bytes

func f(n:Int,_ a:Int=1,_ b:Int=1)->Int{return n<1 ?1:a*f(n-1,b,a+b)}


答:
Ruby, 125

anonymous function, prints to stdout.

RevB: golfed, but a bug fix brought it back to the same length as before.

```<code>->x,y,z{72.times{|i|v=y-i/9;u=x-i%=9
e=u*u+v*v
$><<(i<8?e<1?z:[r=0==v*u,b=u*u==v*v,b|r,3>e,5==e]["RBQKN"=~/#{z}/]??*:?.:$/)}}
</code>```

Prints each of the 64 squares + 8 newlines = 72 characters individually.
Relies on e, the square of the Euclidean distance between the current square and the given coordinates for checking king moves and knight moves (and also for printing the piece value z when the Euclidean distance is zero.)

Ungolfed in test program

```<code>f=->x,y,z{                         #x,y,character
  72.times{|i|                     #8 rows of (8 chars + newline) = 72 chars
    v=y-i/9;                       #vertical diff between y coord and current square
    u=x-i%=9                       #horizontal diff between x coord and current square. note i%=8
    e=u*u+v*v                      #square of euclidean distance
    $><<(                          #$> is stdout. send to it....
      i<8?                         #if not the newline column,
        e<1?z:                       #if the euclidean distance is 0, print the symbol for the piece, else
        [r=0==v*u,                   #TRUE if v or u is 0 (rook)
        b=u*u==v*v,                  #TRUE if abs(u)==abs(v) (bishop)
        b|r,                         #TRUE if either of the above are true (queen)
        3>e,                         #TRUE if e == 1 or 2 (king)
        5==e                         #TRUE if e == 5 (knight)
        ]["RBQKN"=~/#{z}/]??*:?.:    #select value from array corresponding to piece and print * or . accordingly
      $/                           #if newline column, print a newline
    )
  }
}

x=gets.to_i
y=gets.to_i
z=gets.chomp
f[x,y,z]
</code>```

Title: Help Sam understand chess

Body:
Ruby, 125

anonymous function, prints to stdout.

RevB: golfed, but a bug fix brought it back to the same length as before.

->x,y,z{72.times{|i|v=y-i/9;u=x-i%=9
e=u*u+v*v
$><<(i<8?e<1?z:[r=0==v*u,b=u*u==v*v,b|r,3>e,5==e]["RBQKN"=~/#{z}/]??*:?.:$/)}}

Prints each of the 64 squares + 8 newlines = 72 characters individually.
Relies on e, the square of the Euclidean distance between the current square and the given coordinates for checking king moves and knight moves (and also for printing the piece value z when the Euclidean distance is zero.)

Ungolfed in test program

f=->x,y,z{                         #x,y,character
  72.times{|i|                     #8 rows of (8 chars + newline) = 72 chars
    v=y-i/9;                       #vertical diff between y coord and current square
    u=x-i%=9                       #horizontal diff between x coord and current square. note i%=8
    e=u*u+v*v                      #square of euclidean distance
    $><<(                          #$> is stdout. send to it....
      i<8?                         #if not the newline column,
        e<1?z:                       #if the euclidean distance is 0, print the symbol for the piece, else
        [r=0==v*u,                   #TRUE if v or u is 0 (rook)
        b=u*u==v*v,                  #TRUE if abs(u)==abs(v) (bishop)
        b|r,                         #TRUE if either of the above are true (queen)
        3>e,                         #TRUE if e == 1 or 2 (king)
        5==e                         #TRUE if e == 5 (knight)
        ]["RBQKN"=~/#{z}/]??*:?.:    #select value from array corresponding to piece and print * or . accordingly
      $/                           #if newline column, print a newline
    )
  }
}

x=gets.to_i
y=gets.to_i
z=gets.chomp
f[x,y,z]


答:
Micronetics System MUMPS 4.4 (7 chars)

```<code>w $c(1)
</code>```

Title: Smile! Just smile

Body:
It's well known that Brainf*ck is very bad at Kolmogorov-complexity problems, for example, it requires around 100 characters just to print "Hello world".

However, there might be texts where Brainf*ck is just very good at.

Your task is now to write a program that takes no input, and it displays the following:

```<code>☺
</code>```

That is, a smiley face (ASCII 1, if you browser does not render it).

Brainf*ck can do it in 2 characters.

```<code>+.
</code>```

Try to find a language that beats it!

We assume your console can actually display that character (or your font has it, etc.).

Shortest code wins. If there are more of the same length, the first wins, but I'll upvote the others as well.

EDIT: I'm very sorry, I did not think the first post arrives this soon. A quick edit: the language has to be Turing-complete!

Body:
Micronetics System MUMPS 4.4 (7 chars)

w $c(1)


答:
MATL, 44 bytes

I took some inspiration from @flawr's answer (although the algorithm is not the same)

```<code>GtnEq:!g*2Mo*XKG"K1YS3LZ)OX@:Y(PO5MY(XKwyhhc
</code>```

Input is a string with single quotes.

Try it online!

Title: Lemon-Limify a String

Body:
Write a program or function that takes in a nonempty single-line string. You may assume it only contains printable ASCII excluding space.

Print or return an ASCII art lozenge shape similar to a lemon or lime made from the prefixes of the string.

Suppose the input string is n letters long. Then, such a shape consists of 2n − 1 columns of ASCII art stitched together, each consisting of 2n − 1 lines. Counting from 1, the k-th column is f(k) = min(k, 2n − k) characters wide, and contains f(k) copies of the first f(k) characters of input, centered vertically, with single blank lines separating the copies.

For example, if the input is Lemon, the output should be:

```<code>          Lemon
      Lemo     Lemo
   Lem    Lemon    Lem
 Le   Lemo     Lemo   Le
L  Lem    Lemon    Lem  L
 Le   Lemo     Lemo   Le
   Lem    Lemon    Lem
      Lemo     Lemo
          Lemon
</code>```

If the input is lime the output should be:

```<code>      lime
   lim    lim
 li   lime   li
l  lim    lim  l
 li   lime   li
   lim    lim
      lime
</code>```

And the same pattern is followed for other inputs:

```<code>a

a

Be

 Be
B  B
 Be

/\

 /\
/  /
 /\

cat

   cat
 ca   ca
c  cat  c
 ca   ca
   cat

|||

   |||
 ||   ||
|  |||  |
 ||   ||
   |||

.__.

      .__.
   .__    .__
 ._   .__.   ._
.  .__    .__  .
 ._   .__.   ._
   .__    .__
      .__.

$tring

               $tring
          $trin      $trin
      $tri     $tring     $tri
   $tr    $trin      $trin    $tr
 $t   $tri     $tring     $tri   $t
$  $tr    $trin      $trin    $tr  $
 $t   $tri     $tring     $tri   $t
   $tr    $trin      $trin    $tr
      $tri     $tring     $tri
          $trin      $trin
               $tring
</code>```

Lines in the output may have trailing spaces and there may be one optional trailing newline.

The shortest code in bytes wins.

Body:
MATL, 44 bytes

I took some inspiration from @flawr's answer (although the algorithm is not the same)

GtnEq:!g*2Mo*XKG"K1YS3LZ)OX@:Y(PO5MY(XKwyhhc

Input is a string with single quotes.

Try it online!


问:
Input ∩ Source Code

Intro

The challenge is to create a program/function that prints the intersection of its own source code and a given string input. This is code golf and to be more precise:

Let I be the input set

{"a","b","c"}

Let S be the source code set

{"b","f"}

Then the intersection is what they share

I ∩ S = {"b"}

Input

Input is flexible. It should be able to handle the character encoding used for the source code.

Output

Output is flexible. It should be the set of characters that the input and source code share. Also, sets are unordered collections of distinct objects. In summary:

Output is flexible:

Could be any data structure (string or otherwise)

Could unordered

Could have a trailing \n

Should be distinct

Restriction

Similar to quine challenges, the program/function may not read its own source code and 0-byte solutions are not allowed.

Examples

#1

```<code>functor x(I){ return I ∩ self; }

Inputs                                Outputs
------                                -------
enter preformatted text here      ->  {"e","n","t","r","f","o","x"}

["Albrt"," Einstin"]              ->  {"l","r","t","n","s"}
</code>```

#2

```<code>(_)->_&"(_)->&\"\\"

Inputs                                Outputs
------                                -------
"Security at the expense of       ->  "
usability comes at the expense
of security."

(0____0)                          ->  (_)
</code>```

#3

```<code>ಠa益длф

Inputs                                Outputs
------                                -------
Far out in the uncharted backwaters ->"a"
of the unfashionable end of the
Western Spiral arm of the Galaxy lies
a small unregarded yellow sun.
Orbiting this at a distance of roughly
ninety-eight million miles is an
utterly insignificant little blue-green
planet whose ape-descended life forms
are so amazingly primitive that they
still think digital watches are a pretty
neat idea.

(ノಠ益ಠ)ノ彡┻━┻                      ->"ಠ益"
</code>```

Test Cases

```<code>Albert Einstein

\__( O__O)_/

!@#$%^&*()_+{}|:"<>?

1234567890-=[]\;',./

(ノಠ益ಠ)ノ彡┻━┻

“¤>%,oỊȤʠ“ØụĊ5D³ṃṠɼQ»j;Ç;“;}¶”

┬──┬ ノ( ゜-゜ノ)

Far out in the uncharted backwaters of the unfashionable end of the Western Spiral arm of the Galaxy lies a small unregarded yellow sun. Orbiting this at a distance of roughly ninety-eight million miles is an utterly insignificant little blue-green planet whose ape-descended life forms are so amazingly primitive that they still think digital watches are a pretty neat idea.
</code>```

Update

[16-08-10]: sets are unordered collections of distinct objects

[16-08-10]: trailing newline is acceptable

答:
Haskell (30 bytes)

This is such a boring solution... But I couldn't do better. :(

filter(`elem`"f(term)\"i`l\\")
```

Title: Input ∩ Source Code


答:
MATL, 9 bytes

```<code>qtYF1)EW<
</code>```

Truthy output is 1.  Falsy is 0 or empty output. (The only inputs that produce empty output are 1 and 2; the rest produce either 0 or 1).

Try it online!

Explanation

Let x denote the input. Let y be the largest power of 2 that divides x−1, and z = (x−1)/y. Note that z is automatically odd. Then x is a Proth number if and only if y > z, or equivalently if y2 > x−1.

```<code>q    % Input x implicitly. Subtract 1
t    % Duplicate
YF   % Exponents of prime factorization of x-1
1)   % First entry: exponent of 2. Errors for x equal to 1 or 2
E    % Duplicate
W    % 2 raised to that. This is y squared
<    % Is x-1 less than y squared? Implicitly display
</code>```

Title: Is it a Proth number?

Body:
MATL, 9 bytes

qtYF1)EW<

Truthy output is 1.  Falsy is 0 or empty output. (The only inputs that produce empty output are 1 and 2; the rest produce either 0 or 1).

Try it online!

Explanation

Let x denote the input. Let y be the largest power of 2 that divides x−1, and z = (x−1)/y. Note that z is automatically odd. Then x is a Proth number if and only if y > z, or equivalently if y2 > x−1.

q    % Input x implicitly. Subtract 1
t    % Duplicate
YF   % Exponents of prime factorization of x-1
1)   % First entry: exponent of 2. Errors for x equal to 1 or 2
E    % Duplicate
W    % 2 raised to that. This is y squared
<    % Is x-1 less than y squared? Implicitly display


Title: Is it a Proth number?

Body:
Brain-Flak, <s>460</s> <s>350</s> <s>270</s> <s>266</s> <s>264</s> <s>188</s> 176 bytes

Try it online!

({}[()])(((<>()))){{}([(((({}<(({}){})>){}){})<>[({})(())])](<>)){({}())<>}{}<>{}{}<>(({})){{}{}<>(<(())>)}{}}(<{}{}>)<>{({}[()])<>(({}()[({})])){{}(<({}({}))>)}{}<>}{}<>({}<>)

Explanation

The program goes through powers of two and four until it finds a power of two greater than N-1.  When it finds it it checks for the divisibility of N-1 by the power of two using modulo and outputs the result

({}[()])      #Subtract one from input
(((<>())))    #Put three ones on the other stack
{
 {}           #Pop the crap off the top
 ([(
  ((({}<(({}){})>){}){}) #Multiply the top by four and the bottom by two
  <>[({})(())])](<>)){({}())<>}{}<>{}{}<>(({})){{}{}<>(<(())>)}{} #Check if the power of four is greater than N-1
}
(<{}{}>) #Remove the power of 4
<>{({}[()])<>(({}()[({})])){{}(<({}({}))>)}{}<>}{}<>({}<{}><>) #Modulo N-1 by the power of two

This program is not stack clean.  If you add an extra 4 bytes you can make it stack clean:

({}[()])(((<>()))){{}([(((({}<(({}){})>){}){})<>[({})(())])](<>)){({}())<>}{}<>{}{}<>(({})){{}{}<>(<(())>)}{}}(<{}{}>)<>{({}[()])<>(({}()[({})])){{}(<({}({}))>)}{}<>}{}<>({}<{}><>)


问:
Sort the months of the year
Write a function or program that takes string inputs, fully-spelled, English month names in title case: January, February, March, etc. (null/CR/LF terminated OK, delimited with some non-alpha character if you so choose) and either

compares two inputs, returning a Truthy value if the second input is greater (in month order) than the first. Equal values result in a Falsey value

or sorts an arbitrary sequence (list, delimited string, etc.) of them in chronological order

(The crux of the challenge is defining a method/expression that gives the correct lexicographical sort. Some languages might have a shorter answer with one or the other)

You cannot use any internal time parsing methods (e.g. strptime) to translate the month name into a number or a pre-canned mapping of month names. Use properties of the strings themselves, a parsimonious look-up table you define, or something clever.

Example

Functioning examples, though the first is prohibited by the rules...

```<code>import datetime
def is_later_month(a, b):
    '''
    Example of prohibited code because it relies on language
    features about how to parse month names
    '''
    return datetime.strptime(a, '%B') < datetime.strptime(b, '%B')
</code>```

The below versions are OK though, because we code that info

```<code>months = {
    'January':  1, 'February':  2, 'March':      3,
    'April':    4, 'May':       5, 'June':       6,
    'July':     7, 'August':    8, 'September':  9,
    'October': 10, 'November': 11, 'December':  12,
}
def is_later_month(a, b):
    """
    Returns True/False when comparing two months.
    """
    return months[a] < months[b]
</code>```

Or you could do a sorting function

```<code>months = {'as above...'}
def sort_months(l):
    """
    Sorts list and returns it. Different input and output than the above,
    but equally valid. Sorting versus comparing might be shorter in your
    favorite language.
    """
    return sorted(l, key=lambda x: months[x])
</code>```

Example tests

```<code>assert is_later_month('January', 'February')
assert is_later_month('January', 'December')
assert is_later_month('November', 'December')
assert not is_later_month('July', 'July')
assert not is_later_month('October', 'September')
</code>```

答:
Python, <s>81</s> 71 bytes

```<code>lambda x,y,m='anebarprayunulugepctovec':m.index(x[1:3])<m.index(y[1:3])
</code>```

https://repl.it/CluN/1

Compares the index in m of the second and third letters of two months.

83 byte version to sort a list of months:

```<code>lambda x:sorted(x,key=lambda i:'JanFebMarAprMayJunJulAugSepOctNovDec'.index(i[:3]))
</code>```

Title: Sort the months of the year

Body:
Python, <s>81</s> 71 bytes

lambda x,y,m='anebarprayunulugepctovec':m.index(x[1:3])<m.index(y[1:3])

https://repl.it/CluN/1

Compares the index in m of the second and third letters of two months.

83 byte version to sort a list of months:

lambda x:sorted(x,key=lambda i:'JanFebMarAprMayJunJulAugSepOctNovDec'.index(i[:3]))


问:
Automate the OEIS
We see a lot of challenges here asking for a function to create a sequence from the OEIS.  While these challenges are fun, as a programmer I see an opportunity for automation.

Your challenge is to make a program that takes the index of a sequence (e.g. A172141) and some integer n (e.g. 7), and pulls the appropriate value from the appropriate webpage.

I/O

As mentioned, your program should take a sequence index and some value n as input and output the nth term in that sequence. You accept any index in the sequence's B-files. If the index is greater than the largest index listed in the B-files you may throw an exception or output whatever you choose (these are not in the test cases).  Standard methods of input and output are permitted.

Restrictions on web use

You should not access any websites other than https://oeis.org and http://oeis.org.  This includes url shorteners, your own personal website, and this question itself.  If you would like to access some other website and you believe that it is not unfair to allow you to do so, you can leave a comment and I will arbitrate.

Scoring

This is a code golf challenge so the program with the least bytes used in its source code wins.  Standard loopholes are disallowed.

Test Cases

Assuming that your machine has proper internet connection and the OEIS servers are up and running the following inputs and outputs should correspond.

```<code>A172141, 7   -> 980
A173429, 4   -> 276
A190394, 6   -> 16
A002911, 11  -> 960
A052170, 3   -> 24
A060296, 8   -> 3
A178732, 5   -> 27
A000001, 1   -> 1
A000796, 314 -> 3
A001622, 162 -> 8
A002206, -1  -> 1
</code>```

Tip

When accessing the B-files http://oeis.org/b.txt will redirect to the proper B-file.

答:
Julia, 88 bytes

```<code>x\y=match(Regex("$y (.*)"),readall(Requests.get("http://oeis.org/b$(x[2:end]).txt")))[1]
</code>```

Golfed with some help from @Dennis!

Make sure you have Requests.jl installed before running.

Title: Automate the OEIS

Body:
Julia, 88 bytes

x\y=match(Regex("$y (.*)"),readall(Requests.get("http://oeis.org/b$(x[2:end]).txt")))[1]

Golfed with some help from @Dennis!

Make sure you have Requests.jl installed before running.


答:
Python 2, <s>121</s> 110 bytes

s=input()
n=len(s)
r=range(1,n)+range(n,0,-1)
for y in r:print''.join(s[:(x+y-n&(x+y>n))*x]or' '*x for x in r)
```

116 bytes if using raw_input. The program essentially does a mask based on L1-norm/Manhattan distance from the centre, as well as the parity of this distance compared to the parity of the input length.

(Thanks to @Lynn for -9 bytes and paving the way for 2 more)

Title: Lemon-Limify a String

Body:
Python 2, <s>121</s> 110 bytes

s=input()
n=len(s)
r=range(1,n)+range(n,0,-1)
for y in r:print''.join(s[:(x+y-n&(x+y>n))*x]or' '*x for x in r)

116 bytes if using raw_input. The program essentially does a mask based on L1-norm/Manhattan distance from the centre, as well as the parity of this distance compared to the parity of the input length.

(Thanks to @Lynn for -9 bytes and paving the way for 2 more)


问:
Tips for golfing in Cheddar

Cheddar is a high-level, functional + object-oriented programming language created by our user Downgoat designed to make programming easier, faster, and more intuitive.

What general tips do you have for golfing in Cheddar? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Cheddar (e.g. "Remove unnecessary whitespace." is not an answer).

答:
Use Functionized Operators and Bonding

This is a simple one. If you have anything like:

```<code>i->1+i
</code>```

or any similar operation. You can shorten using functionized operators + bonding:

```<code>1&(+)
</code>```

Title: Tips for golfing in Cheddar

Body:
Use Functionized Operators and Bonding

This is a simple one. If you have anything like:

i->1+i

or any similar operation. You can shorten using functionized operators + bonding:

1&(+)


答:
Use Functionized Properties

If you ever use just a property in a function:

```<code>A->A.long.property(n).foo.bar
</code>```

You can use functionized properties to save some bytes:

```<code>@.long.property(n).foo.bar
</code>```

You can reference the variable in the functionized property with $0.

Title: Tips for golfing in Cheddar

Body:
Cheddar is a high-level, functional + object-oriented programming language created by our user Downgoat designed to make programming easier, faster, and more intuitive.

What general tips do you have for golfing in Cheddar? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Cheddar (e.g. "Remove unnecessary whitespace." is not an answer).

Body:
Use Functionized Properties

If you ever use just a property in a function:

A->A.long.property(n).foo.bar

You can use functionized properties to save some bytes:

@.long.property(n).foo.bar

You can reference the variable in the functionized property with $0.


答:
Julia, 16 bytes

```<code>!x=~-x&-~-x>x^.5
</code>```

Credits to @Dennis for the answer and some golfing tips!

Title: Is it a Proth number?

Body:
A Proth number, named after François Proth, is a number that can be expressed as

$$N = k \times 2^n + 1$$

Where \$k\$ is an odd positive integer and \$n\$ is a positive integer such that \$2^n > k\$. Let's use a more concrete example. Take 3. 3 is a Proth number because it can be written as

$$ 3 = (1 \times 2^1) + 1 $$

and \$2^1 > 1\$ is satisfied. 5 Is also a Proth number because it can be written as

$$ 5 = (1 \times 2^2) + 1 $$

and \$2^2 > 1\$ is satisfied. However, 7 is not a Proth number because the only way to write it in the form \$N = k \times 2^n + 1\$ is

$$ 7 = (3 \times 2^1) + 1 $$

and \$2^1 > 3\$ is not satisfied.

Your challenge is fairly simple: you must write a program or function that, given a positive integer, determines if it is a Proth number or not. You may take input in any reasonable format, and should output a truthy value if it is a Proth number and a falsy value if it is not. If your language has any "Proth-number detecting" functions, you may use them.

Test IO

Here are the first 46 Proth numbers up to 1000. (A080075)

```<code>3, 5, 9, 13, 17, 25, 33, 41, 49, 57, 65, 81, 97, 113, 129, 145, 161, 177, 193, 209, 225, 241, 257, 289, 321, 353, 385, 417, 449, 481, 513, 545, 577, 609, 641, 673, 705, 737, 769, 801, 833, 865, 897, 929, 961, 993
</code>```

Every other valid input should give a falsy value.

As usual, this is code-golf, so standard loopholes apply, and the shortest answer in bytes wins!

Number theory fun-fact side-note:

The largest known prime that is not a Mersenne Prime is \$19249 \times 2^{13018586} + 1\$, which just so happens to also be a Proth number!

Body:
Julia, 16 bytes

!x=~-x&-~-x>x^.5

Credits to @Dennis for the answer and some golfing tips!


答:
Javascript ES7, 16 bytes

```<code>x=>x--<(-x&x)**2
</code>```

Port of my Julia answer, which is a port of @Dennis's Jelly answer.

Thanks @Charlie for 2 bytes saved!

Title: Is it a Proth number?

Body:
Javascript ES7, 16 bytes

x=>x--<(-x&x)**2

Port of my Julia answer, which is a port of @Dennis's Jelly answer.

Thanks @Charlie for 2 bytes saved!


答:
Python 2, 44 bytes

x='c=set;print c(`x`)&c(raw_input())';exec x
```

Just for fun, here's a quine-like full program submission. Outputs the string representation of a Python 2 set.

Title: Input ∩ Source Code

Body:
Intro

The challenge is to create a program/function that prints the intersection of its own source code and a given string input. This is code golf and to be more precise:

Let I be the input set

{"a","b","c"}

Let S be the source code set

{"b","f"}

Then the intersection is what they share

I ∩ S = {"b"}

Input

Input is flexible. It should be able to handle the character encoding used for the source code.

Output

Output is flexible. It should be the set of characters that the input and source code share. Also, sets are unordered collections of distinct objects. In summary:

Output is flexible:

Could be any data structure (string or otherwise)

Could unordered

Could have a trailing \n

Should be distinct

Restriction

Similar to quine challenges, the program/function may not read its own source code and 0-byte solutions are not allowed.

Examples

#1

```<code>functor x(I){ return I ∩ self; }

Inputs                                Outputs
------                                -------
enter preformatted text here      ->  {"e","n","t","r","f","o","x"}

["Albrt"," Einstin"]              ->  {"l","r","t","n","s"}
</code>```

#2

```<code>(_)->_&"(_)->&\"\\"

Inputs                                Outputs
------                                -------
"Security at the expense of       ->  "
usability comes at the expense
of security."

(0____0)                          ->  (_)
</code>```

#3

```<code>ಠa益длф

Inputs                                Outputs
------                                -------
Far out in the uncharted backwaters ->"a"
of the unfashionable end of the
Western Spiral arm of the Galaxy lies
a small unregarded yellow sun.
Orbiting this at a distance of roughly
ninety-eight million miles is an
utterly insignificant little blue-green
planet whose ape-descended life forms
are so amazingly primitive that they
still think digital watches are a pretty
neat idea.

(ノಠ益ಠ)ノ彡┻━┻                      ->"ಠ益"
</code>```

Test Cases

```<code>Albert Einstein

\__( O__O)_/

!@#$%^&*()_+{}|:"<>?

1234567890-=[]\;',./

(ノಠ益ಠ)ノ彡┻━┻

“¤>%,oỊȤʠ“ØụĊ5D³ṃṠɼQ»j;Ç;“;}¶”

┬──┬ ノ( ゜-゜ノ)

Far out in the uncharted backwaters of the unfashionable end of the Western Spiral arm of the Galaxy lies a small unregarded yellow sun. Orbiting this at a distance of roughly ninety-eight million miles is an utterly insignificant little blue-green planet whose ape-descended life forms are so amazingly primitive that they still think digital watches are a pretty neat idea.
</code>```

Update

[16-08-10]: sets are unordered collections of distinct objects

[16-08-10]: trailing newline is acceptable

Body:
Python 2, 44 bytes

x='c=set;print c(`x`)&c(raw_input())';exec x

Just for fun, here's a quine-like full program submission. Outputs the string representation of a Python 2 set.


答:
Jelly, 19 bytes

```<code>11ị“bMAanlseovc”iµÞ
</code>```

This is a monadic link that takes a list as argument and sorts it. Try it online!

Background

Jelly uses modular, 1-based indexing. If we repeat the months names often enough to obtain 11 characters, we get the following array.

```<code>J a n u a r y J a n u
F e b r u a r y F e b
M a r c h M a r c h M
A p r i l A p r i l A
M a y M a y M a y M a
J u n e J u n e J u n
J u l y J u l y J u l
A u g u s t A u g u s
S e p t e m b e r S e
O c t o b e r O c t o
N o v e m b e r N o v
D e c e m b e r D e c
</code>```

In the 11th (last) column, all characters are different, so we can use them to identify the order of the months.

How it works

```<code>11ị“bMAanlseovc”iµÞ  Monadic link. Argument: A (array of months)

                 µ   Combine the preceding chain into a link.
                  Þ  Sort A by that link.
11ị                    Select the 11th character of the month's name.
   “bMAanlseovc”       Find the index of that character in "bMAanlseovc".
                       For 'u' ("January"), this returns 0 (not found).
</code>```

Title: Sort the months of the year

Body:
Write a function or program that takes string inputs, fully-spelled, English month names in title case: January, February, March, etc. (null/CR/LF terminated OK, delimited with some non-alpha character if you so choose) and either

compares two inputs, returning a Truthy value if the second input is greater (in month order) than the first. Equal values result in a Falsey value

or sorts an arbitrary sequence (list, delimited string, etc.) of them in chronological order

(The crux of the challenge is defining a method/expression that gives the correct lexicographical sort. Some languages might have a shorter answer with one or the other)

You cannot use any internal time parsing methods (e.g. strptime) to translate the month name into a number or a pre-canned mapping of month names. Use properties of the strings themselves, a parsimonious look-up table you define, or something clever.

Example

Functioning examples, though the first is prohibited by the rules...

```<code>import datetime
def is_later_month(a, b):
    '''
    Example of prohibited code because it relies on language
    features about how to parse month names
    '''
    return datetime.strptime(a, '%B') < datetime.strptime(b, '%B')
</code>```

The below versions are OK though, because we code that info

```<code>months = {
    'January':  1, 'February':  2, 'March':      3,
    'April':    4, 'May':       5, 'June':       6,
    'July':     7, 'August':    8, 'September':  9,
    'October': 10, 'November': 11, 'December':  12,
}
def is_later_month(a, b):
    """
    Returns True/False when comparing two months.
    """
    return months[a] < months[b]
</code>```

Or you could do a sorting function

```<code>months = {'as above...'}
def sort_months(l):
    """
    Sorts list and returns it. Different input and output than the above,
    but equally valid. Sorting versus comparing might be shorter in your
    favorite language.
    """
    return sorted(l, key=lambda x: months[x])
</code>```

Example tests

```<code>assert is_later_month('January', 'February')
assert is_later_month('January', 'December')
assert is_later_month('November', 'December')
assert not is_later_month('July', 'July')
assert not is_later_month('October', 'September')
</code>```

Body:
Jelly, 19 bytes

11ị“bMAanlseovc”iµÞ

This is a monadic link that takes a list as argument and sorts it. Try it online!

Background

Jelly uses modular, 1-based indexing. If we repeat the months names often enough to obtain 11 characters, we get the following array.

J a n u a r y J a n u
F e b r u a r y F e b
M a r c h M a r c h M
A p r i l A p r i l A
M a y M a y M a y M a
J u n e J u n e J u n
J u l y J u l y J u l
A u g u s t A u g u s
S e p t e m b e r S e
O c t o b e r O c t o
N o v e m b e r N o v
D e c e m b e r D e c

In the 11th (last) column, all characters are different, so we can use them to identify the order of the months.

How it works

11ị“bMAanlseovc”iµÞ  Monadic link. Argument: A (array of months)

                 µ   Combine the preceding chain into a link.
                  Þ  Sort A by that link.
11ị                    Select the 11th character of the month's name.
   “bMAanlseovc”       Find the index of that character in "bMAanlseovc".
                       For 'u' ("January"), this returns 0 (not found).


答:
Ruby, 58 bytes

Uses the month sorting trick from @atlasologist's answer.

->a{a.sort_by{|i|"anebarprayunulugepctovec".index i[1,2]}}
```
<p>The comparison function is a bit longer, at <strong>63 bytes</strong></p>
<pre class="lang-ruby prettyprint-override"><code>->a,b{m=->i{"anebarprayunulugepctovec".index i[1,2]};m[a]<m[b]}
</code>```

Title: Sort the months of the year

Body:
Ruby, 58 bytes

Uses the month sorting trick from @atlasologist's answer.

->a{a.sort_by{|i|"anebarprayunulugepctovec".index i[1,2]}}

The comparison function is a bit longer, at 63 bytes

->a,b{m=->i{"anebarprayunulugepctovec".index i[1,2]};m[a]<m[b]}


答:
Python, <s>64</s> <s>61</s> 57 bytes

lambda x,y,g='bMAanlseovc'.find:g((x*4)[10])<g((y*4)[10])
```

The lambda takes two months as input and compares them. Test it on Ideone.

Thanks to @ljeabmreosn for golfing off 3 bytes and paving the way for 3 more!

Title: Sort the months of the year

Body:
Python, <s>64</s> <s>61</s> 57 bytes

lambda x,y,g='bMAanlseovc'.find:g((x*4)[10])<g((y*4)[10])

The lambda takes two months as input and compares them. Test it on Ideone.

Thanks to @ljeabmreosn for golfing off 3 bytes and paving the way for 3 more!


答:
JavaScript (ES6), 132 bytes

s=>{x=' '.repeat(l=s.length);for(n=r='';n++<l;r=r?t+`
${r}
`+t:t)for(i=l,t='';i;t=t?w+t+w:w)w=(i<n|n+i&1?x:s).slice(0,i--);return r}
```

<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>var solution =

s=>{
  x=' '.repeat(l=s.length);
  for(n=r='';n++<l;r=r?t+`\n${r}\n`+t:t)
    for(i=l,t='';i;t=t?w+t+w:w)
      w=(i<n|n+i&1?x:s).slice(0,i--);
  return r
}

result.textContent = solution('Lemon');</code>```

<input type="text" id="input" value="Lemon" oninput="result.textContent=solution(this.value)" />
```</code>```

Title: Lemon-Limify a String

Body:
Write a program or function that takes in a nonempty single-line string. You may assume it only contains printable ASCII excluding space.

Print or return an ASCII art lozenge shape similar to a lemon or lime made from the prefixes of the string.

Suppose the input string is n letters long. Then, such a shape consists of 2n − 1 columns of ASCII art stitched together, each consisting of 2n − 1 lines. Counting from 1, the k-th column is f(k) = min(k, 2n − k) characters wide, and contains f(k) copies of the first f(k) characters of input, centered vertically, with single blank lines separating the copies.

For example, if the input is Lemon, the output should be:

```<code>          Lemon
      Lemo     Lemo
   Lem    Lemon    Lem
 Le   Lemo     Lemo   Le
L  Lem    Lemon    Lem  L
 Le   Lemo     Lemo   Le
   Lem    Lemon    Lem
      Lemo     Lemo
          Lemon
</code>```

If the input is lime the output should be:

```<code>      lime
   lim    lim
 li   lime   li
l  lim    lim  l
 li   lime   li
   lim    lim
      lime
</code>```

And the same pattern is followed for other inputs:

```<code>a

a

Be

 Be
B  B
 Be

/\

 /\
/  /
 /\

cat

   cat
 ca   ca
c  cat  c
 ca   ca
   cat

|||

   |||
 ||   ||
|  |||  |
 ||   ||
   |||

.__.

      .__.
   .__    .__
 ._   .__.   ._
.  .__    .__  .
 ._   .__.   ._
   .__    .__
      .__.

$tring

               $tring
          $trin      $trin
      $tri     $tring     $tri
   $tr    $trin      $trin    $tr
 $t   $tri     $tring     $tri   $t
$  $tr    $trin      $trin    $tr  $
 $t   $tri     $tring     $tri   $t
   $tr    $trin      $trin    $tr
      $tri     $tring     $tri
          $trin      $trin
               $tring
</code>```

Lines in the output may have trailing spaces and there may be one optional trailing newline.

The shortest code in bytes wins.

Body:
JavaScript (ES6), 132 bytes

s=>{x=' '.repeat(l=s.length);for(n=r='';n++<l;r=r?t+`
${r}
`+t:t)for(i=l,t='';i;t=t?w+t+w:w)w=(i<n|n+i&1?x:s).slice(0,i--);return r}

Test

var solution =

s=>{
  x=' '.repeat(l=s.length);
  for(n=r='';n++<l;r=r?t+`\n${r}\n`+t:t)
    for(i=l,t='';i;t=t?w+t+w:w)
      w=(i<n|n+i&1?x:s).slice(0,i--);
  return r
}

result.textContent = solution('Lemon');

<input type="text" id="input" value="Lemon" oninput="result.textContent=solution(this.value)" /><pre id="result"></pre>


问:
Concise Grading
Write a program or a function in your favorite programming language that will take as input a number n (integer or non-integer) between 0 and 100 inclusive, and output the corresponding grade as outlined below:

If 0 < n <= 40, then output E.

If 40 < n <= 55, then output D.

If 55 < n <= 65, then output C.

If 65 < n <= 70, then output C+.

If 70 < n <= 75, then output B-.

if 75 < n <= 80, then output B.

If 80 < n <= 85, then output B+.

If 85 < n <= 90, then output A-.

If 90 < n <= 95, then output A.

If 95 < n <= 100, then output A+.

You are guaranteed that there are no other cases to test, and that n is guaranteed to be within 0 and 100.

The input n can be provided via stdin or as an argument to the program.

Lines in the output are not allowed to have trailing spaces and/or newlines. You must output exactly the corresponding grade, nothing else.

Shortest code in bytes wins!

答:
Python, <s>74</s> <s>66</s> 73 bytes

```<code>lambda n,l="E "*8+"D D D C C C+ B- B B+ A- A A+ A+":l.split()[int(n-1)/5]
</code>```

Unnamed lambda, uses a list of all grades in groups of 5. (I'm sure there's a way to handle n=100 without adding the extra 'A+' at the end, I'm just not sure how)

Edit: Thanks to @LeakyNun for 8 bytes

Title: Concise Grading

Body:
Python, <s>74</s> <s>66</s> 73 bytes

lambda n,l="E "*8+"D D D C C C+ B- B B+ A- A A+ A+":l.split()[int(n-1)/5]

Unnamed lambda, uses a list of all grades in groups of 5. (I'm sure there's a way to handle n=100 without adding the extra 'A+' at the end, I'm just not sure how)

Edit: Thanks to @LeakyNun for 8 bytes


答:
Pyth, 36 bytes

```<code>?<Q41\E+C/-1075Q15?<Q66k-@"-+ "/_Q5d
</code>```

Test suite.

Explanation

Here is the equivalent program in Python 3.

lambda Q:[chr(int(1075-Q)//15)+["-+ "[int(99-Q/5)%3],""][Q<66],"E"][Q<41].split()[0]
```

Ideone it!

Title: Concise Grading

Body:
Write a program or a function in your favorite programming language that will take as input a number n (integer or non-integer) between 0 and 100 inclusive, and output the corresponding grade as outlined below:

If 0 < n <= 40, then output E.

If 40 < n <= 55, then output D.

If 55 < n <= 65, then output C.

If 65 < n <= 70, then output C+.

If 70 < n <= 75, then output B-.

if 75 < n <= 80, then output B.

If 80 < n <= 85, then output B+.

If 85 < n <= 90, then output A-.

If 90 < n <= 95, then output A.

If 95 < n <= 100, then output A+.

You are guaranteed that there are no other cases to test, and that n is guaranteed to be within 0 and 100.

The input n can be provided via stdin or as an argument to the program.

Lines in the output are not allowed to have trailing spaces and/or newlines. You must output exactly the corresponding grade, nothing else.

Shortest code in bytes wins!

Body:
Pyth, 36 bytes

?<Q41\E+C/-1075Q15?<Q66k-@"-+ "/_Q5d

Test suite.

Explanation

Here is the equivalent program in Python 3.

lambda Q:[chr(int(1075-Q)//15)+["-+ "[int(99-Q/5)%3],""][Q<66],"E"][Q<41].split()[0]

Ideone it!


答:
JavaScript (ES6), 57 bytes

```<code>n=>`A+ A A- B+ B B- C+ C C D D D`.split` `[20-n/5|0]||`E`
</code>```

Title: Concise Grading

Body:
JavaScript (ES6), 57 bytes

n=>`A+ A A- B+ B B- C+ C C D D D`.split` `[20-n/5|0]||`E`


Title: Is it a Proth number?

Body:
Haskell, <s>55</s> 46 bytes

f x=length [x|k<-[1,3..x],n<-[1..x],k*2^n+1==x,2^n>k]>0

Edit:
Thanks to nimi, now 46 bytes

f x=or[k*2^n+1==x|k<-[1,3..x],n<-[1..x],2^n>k]


问:
Print an alphabet wave
You are to print this exact text:

```<code>ABABABABABABABABABABABABAB
BCBCBCBCBCBCBCBCBCBCBCBCBC
CDCDCDCDCDCDCDCDCDCDCDCDCD
DEDEDEDEDEDEDEDEDEDEDEDEDE
EFEFEFEFEFEFEFEFEFEFEFEFEF
FGFGFGFGFGFGFGFGFGFGFGFGFG
GHGHGHGHGHGHGHGHGHGHGHGHGH
HIHIHIHIHIHIHIHIHIHIHIHIHI
IJIJIJIJIJIJIJIJIJIJIJIJIJ
JKJKJKJKJKJKJKJKJKJKJKJKJK
KLKLKLKLKLKLKLKLKLKLKLKLKL
LMLMLMLMLMLMLMLMLMLMLMLMLM
MNMNMNMNMNMNMNMNMNMNMNMNMN
NONONONONONONONONONONONONO
OPOPOPOPOPOPOPOPOPOPOPOPOP
PQPQPQPQPQPQPQPQPQPQPQPQPQ
QRQRQRQRQRQRQRQRQRQRQRQRQR
RSRSRSRSRSRSRSRSRSRSRSRSRS
STSTSTSTSTSTSTSTSTSTSTSTST
TUTUTUTUTUTUTUTUTUTUTUTUTU
UVUVUVUVUVUVUVUVUVUVUVUVUV
VWVWVWVWVWVWVWVWVWVWVWVWVW
WXWXWXWXWXWXWXWXWXWXWXWXWX
XYXYXYXYXYXYXYXYXYXYXYXYXY
YZYZYZYZYZYZYZYZYZYZYZYZYZ
ZAZAZAZAZAZAZAZAZAZAZAZAZA
</code>```

Specs

You can print all lowercase instead of all uppercase. However, case must be consistent throughout the output.

You may print one extra trailing linefeed.

Scoring

Since this is an alphabet wave that fluctuates to a small extent, your code should also be small in terms of byte-count. In fact, the smallest code in terms of byte-count wins.

答:
Mathematica, <s>82</s> <s>75</s> <s>67</s> 66 bytes

```<code>Print@FromCharacterCode@PadLeft[{},26,{i-1,i}~Mod~26+65]~Do~{i,26}
</code>```

Technically shorter, although it prints in lowercase instead of uppercase:

Mathematica, 64 bytes

```<code>Print[""<>FromLetterNumber@Table[{i-1,i}~Mod~26+1,13]]~Do~{i,26}
</code>```

Title: Print an alphabet wave

Body:
Mathematica, <s>82</s> <s>75</s> <s>67</s> 66 bytes

Print@FromCharacterCode@PadLeft[{},26,{i-1,i}~Mod~26+65]~Do~{i,26}

Technically shorter, although it prints in lowercase instead of uppercase:

Mathematica, 64 bytes

Print[""<>FromLetterNumber@Table[{i-1,i}~Mod~26+1,13]]~Do~{i,26}


答:
python 3, <s>92</s> 90 bytes

```<code>a=65
b=66
for i in range(312):
    if a>89:b=65
    print(chr(a)+chr(b),end="")
    if (i+1)%12<1:
        a+=1
        b+=1
        print()
</code>```

python 2, 80 bytes

```<code>a=65
b=66
for i in range(312):
    if a>89:b=65
    print chr(a)+chr(b),
    if (i+1)%12<1:
        a+=1
        b+=1
        print
</code>```

This program outputs AB AB AB AB... rather than ABABABAB... I'm not sure if this is allowed, but it's the best I can come up with.

EDIT:

Thanks @User902383 for you comment on @TAsk's post allowing me to shave off 2 bytes.

And thanks @NoOneIsHere for suggesting that I move to python 2 instead of 3, I've included a second program in python 2 with a new byte count.

Title: Print an alphabet wave

Body:
You are to print this exact text:

```<code>ABABABABABABABABABABABABAB
BCBCBCBCBCBCBCBCBCBCBCBCBC
CDCDCDCDCDCDCDCDCDCDCDCDCD
DEDEDEDEDEDEDEDEDEDEDEDEDE
EFEFEFEFEFEFEFEFEFEFEFEFEF
FGFGFGFGFGFGFGFGFGFGFGFGFG
GHGHGHGHGHGHGHGHGHGHGHGHGH
HIHIHIHIHIHIHIHIHIHIHIHIHI
IJIJIJIJIJIJIJIJIJIJIJIJIJ
JKJKJKJKJKJKJKJKJKJKJKJKJK
KLKLKLKLKLKLKLKLKLKLKLKLKL
LMLMLMLMLMLMLMLMLMLMLMLMLM
MNMNMNMNMNMNMNMNMNMNMNMNMN
NONONONONONONONONONONONONO
OPOPOPOPOPOPOPOPOPOPOPOPOP
PQPQPQPQPQPQPQPQPQPQPQPQPQ
QRQRQRQRQRQRQRQRQRQRQRQRQR
RSRSRSRSRSRSRSRSRSRSRSRSRS
STSTSTSTSTSTSTSTSTSTSTSTST
TUTUTUTUTUTUTUTUTUTUTUTUTU
UVUVUVUVUVUVUVUVUVUVUVUVUV
VWVWVWVWVWVWVWVWVWVWVWVWVW
WXWXWXWXWXWXWXWXWXWXWXWXWX
XYXYXYXYXYXYXYXYXYXYXYXYXY
YZYZYZYZYZYZYZYZYZYZYZYZYZ
ZAZAZAZAZAZAZAZAZAZAZAZAZA
</code>```

Specs

You can print all lowercase instead of all uppercase. However, case must be consistent throughout the output.

You may print one extra trailing linefeed.

Scoring

Since this is an alphabet wave that fluctuates to a small extent, your code should also be small in terms of byte-count. In fact, the smallest code in terms of byte-count wins.

Body:
python 3, <s>92</s> 90 bytes

a=65
b=66
for i in range(312):
    if a>89:b=65
    print(chr(a)+chr(b),end="")
    if (i+1)%12<1:
        a+=1
        b+=1
        print()

python 2, 80 bytes

a=65
b=66
for i in range(312):
    if a>89:b=65
    print chr(a)+chr(b),
    if (i+1)%12<1:
        a+=1
        b+=1
        print

This program outputs AB AB AB AB... rather than ABABABAB... I'm not sure if this is allowed, but it's the best I can come up with.

EDIT:

Thanks @User902383 for you comment on @TAsk's post allowing me to shave off 2 bytes.

And thanks @NoOneIsHere for suggesting that I move to python 2 instead of 3, I've included a second program in python 2 with a new byte count.


答:
Brachylog, 28 bytes

```<code>>N>0,2:N^P:K*+?,P>K:2%1,N:K=
</code>```

Try it online!

Verify all testcases at once.
(Slightly modified.)

Explanation

Brachylog, being a derivative of Prolog, is very good at proving things.

Here, we prove these things:

```<code>>N>0,2:N^P:K*+?,P>K:2%1,N:K=

>N>0                           input > N > 0
     2:N^P                     2^N = P
         P:K*+?                P*K+1 = input
                P>K            P > K
                  K:2%1        K%2 = 1
                        N:K=   [N:K] has a solution
</code>```

Title: Is it a Proth number?

Body:
A Proth number, named after François Proth, is a number that can be expressed as

$$N = k \times 2^n + 1$$

Where \$k\$ is an odd positive integer and \$n\$ is a positive integer such that \$2^n > k\$. Let's use a more concrete example. Take 3. 3 is a Proth number because it can be written as

$$ 3 = (1 \times 2^1) + 1 $$

and \$2^1 > 1\$ is satisfied. 5 Is also a Proth number because it can be written as

$$ 5 = (1 \times 2^2) + 1 $$

and \$2^2 > 1\$ is satisfied. However, 7 is not a Proth number because the only way to write it in the form \$N = k \times 2^n + 1\$ is

$$ 7 = (3 \times 2^1) + 1 $$

and \$2^1 > 3\$ is not satisfied.

Your challenge is fairly simple: you must write a program or function that, given a positive integer, determines if it is a Proth number or not. You may take input in any reasonable format, and should output a truthy value if it is a Proth number and a falsy value if it is not. If your language has any "Proth-number detecting" functions, you may use them.

Test IO

Here are the first 46 Proth numbers up to 1000. (A080075)

```<code>3, 5, 9, 13, 17, 25, 33, 41, 49, 57, 65, 81, 97, 113, 129, 145, 161, 177, 193, 209, 225, 241, 257, 289, 321, 353, 385, 417, 449, 481, 513, 545, 577, 609, 641, 673, 705, 737, 769, 801, 833, 865, 897, 929, 961, 993
</code>```

Every other valid input should give a falsy value.

As usual, this is code-golf, so standard loopholes apply, and the shortest answer in bytes wins!

Number theory fun-fact side-note:

The largest known prime that is not a Mersenne Prime is \$19249 \times 2^{13018586} + 1\$, which just so happens to also be a Proth number!

Body:
Brachylog, 28 bytes

>N>0,2:N^P:K*+?,P>K:2%1,N:K=

Try it online!

Verify all testcases at once.
(Slightly modified.)

Explanation

Brachylog, being a derivative of Prolog, is very good at proving things.

Here, we prove these things:

>N>0,2:N^P:K*+?,P>K:2%1,N:K=

>N>0                           input > N > 0
     2:N^P                     2^N = P
         P:K*+?                P*K+1 = input
                P>K            P > K
                  K:2%1        K%2 = 1
                        N:K=   [N:K] has a solution


问:
A tiny adventure
Text adventure games have a pretty set formula; there's a world composed of a series of rooms / spaces, the player can move around these rooms, and there are some items in the rooms. Items can be picked up by the player, put down, used to access other rooms (e.g. keys), and combined with other items to make new items.

Challenge

Your challenge is to write a text adventure runtime in the fewest bytes (code golf). To keep things simple, all you need to do is output a truthy or falsey value depending on whether a given series of commands would win a given game or not (no interactivity, no human friendly output, etc.)

Game Rules

The world is always composed of a corridor with 10 connected rooms. Each room requires a key to enter, but can be exited at any time without a key (so it's some kind of latch lock I guess);

The player begins in room 0, and wins if they ever enter room 9 (once they reach room 9 they can do whatever they like, including go to another room, and they will still have won);

Each room can contain any number of items;

There are up to 26 items, named A-Z, and no item will appear more than once in the world;

The player can pick up items from the current room and place them in their inventory (they can also drop items from their inventory into the current room);

The player's maximum inventory size is finite, and will be provided with the level details;

At the beginning of the game, the player's inventory is always empty;

There is no limit to the maximum number of items in a room (though the implicit limit would be 26, since that is the total number of items);

Items A-J are keys which can be used to enter rooms 0-9 (i.e. the player can move to room 0 if they have item A, to room 1 if they have B, etc. note that keys are not required to leave a room, and the player begins in room 0, so the key "A" is only required if the player wants to return to room 0);

Items in the player's inventory can be combined to create new items (which will be created in the player's inventory) — the permitted combinations will be provided with the level details;

Combining items consumes the original items (i.e. if one of the items was a key, it will no-longer be possible to use that key);

If the player tries to do something impossible (e.g. pick up an item which is not in the current room / drop an item they don't have / combine items they don't have / go to a room they don't have the key for), nothing happens and they can continue;

The player will never give a nonsense command (e.g. go to room 11).

So a simple game might look like this:

```<code>  v
+---+---+---+---+---+---+---+---+---+---+
| C |   | J |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+---+---+
|               CORRIDOR                |
+---------------------------------------+
Inventory capacity: 99
</code>```

Room 0 contains item "C" (which is the key to room 2). Room 2 contains item "J" (which is the key to room 9). The player can win the game by picking up C, moving to room 2, picking up J, then moving to room 9.

A more complex game might be:

```<code>  v
+---+---+---+---+---+---+---+---+---+---+
| C |   | X |YZ |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+---+---+
|               CORRIDOR                |
+---------------------------------------+
Inventory capacity: 10
C+X => D
Y+Z => J
</code>```

Now the player can win by picking up C, moving to room 2, picking up X, combining C with X to create D, then moving to room 3. They can now pick up and combine Y and Z to get J, allowing them to go to room 9.

Input Format

There's a fair bit of input to handle, and that's a pretty boring task, so the input format is very flexible. You will get the following data, and how it should be sent to your program is largely up to you:

The initial contents of each room (list of 0 or more items for each room);

A collection of permitted item combinations (each contains 2 input items and their output item — note that the input items are unordered);

The maximum inventory size (integer, 0 <= size <= 26);

The list of commands the player attempted.

The player's commands can be:

[P]ick up <item> - picks up an item from the room and puts it into the player's inventory (if there is space)

[D]rop <item> - drops an item from the player's inventory into the current room

[C]ombine <item1> <item2> - combines 2 items in the player's inventory to produce a new item

[G]o to <room> - travels to the chosen room if the player has the required key

For example, the input format I used for testing was simple program arguments:

./adventure YZ '' '' '' '' '' '' '' '' ''  1 YZJ         2          PY PZ CYZ G9
#           r0 r1 r2 r3 r4 r5 r6 r7 r8 r9  combinations  inv. size  commands...
# means:
#  room 0 starts with items Y & Z, all other rooms start empty
#  1 combination is possible: Y+Z => J
#  max inventory size is 2
#  player commands are [P]ick up Y, [P]ick up Z, [C]ombine Y and Z, [G]o to room 9
#  (in this example, the player wins)
```

<p>But if some other format makes it easier, that's fine (e.g. special delimiter characters / multiple lines / different ordering / serialised to JSON / etc.)</p>

<h1>Output Format</h1>

<p>Your program should return some truthy output if the player's commands cause them to win the game, and some falsey output otherwise. This could be a recognisable message to stdout, a program return code, or whatever your language of choice provides. All other output will be ignored.</p>

<h1>Test Cases</h1>

<p>The following bash script provides a test harness which will check most situations. It has been written to use the format described above, but modifying it to use a different format is just a case of adding a conversion in the <code>invoke</code> function.</p>

<pre class="lang-sh prettyprint-override"><code>#!/bin/sh

PROG="$1";

if [[ -z "$PROG" ]]; then
    echo "Usage: $0 <program-to-test>";
    exit 1;
fi;

function invoke {
    "$PROG" "$@"
}

RED="\033[1;31m";
GREEN="\033[1;32m";
RESET="\033[m";
FAILURES="0";

function pass {
    if ! invoke "$@" >/dev/null 2>&1; then
        echo "${RED}Expected pass, got fail:${RESET} $*" >&2;
        (( FAILURES = "$FAILURES" + 1 ));
        invoke "$@" 2>&1;
    fi;
}

function fail {
    if invoke "$@" >/dev/null 2>&1; then
        echo "${RED}Expected fail, got pass:${RESET} $*" >&2;
        (( FAILURES = "$FAILURES" + 1 ));
        invoke "$@" 2>&1;
    fi;
}

echo "Running tests...";

#    R0  R1  R2  R3  R4  R5  R6  R7  R8  R9  C      I  Cmd...
pass J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      9  PJ G9;
fail ''  J   ''  ''  ''  ''  ''  ''  ''  ''  0      9  PJ G9;
pass J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      9  PJ PJ G9;
fail J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      9  PJ;
fail J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      9  G9;
pass J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      9  G9 PJ G9;
pass J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      1  PJ G9;
fail J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      0  PJ G9;
fail J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      9  PJ DJ G9;
fail J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      9  PJ PJ DJ G9;
pass J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      9  PJ DJ PJ G9;
pass J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      9  PJ DJ PJ G9;
pass B   CJ  ''  ''  ''  ''  ''  ''  ''  ''  0      2  PB G1 DB PC PJ G9;
fail B   CJ  ''  ''  ''  ''  ''  ''  ''  ''  0      2  PB G1 DB PB PC PJ G9;
pass AJ  ''  ''  ''  ''  ''  ''  ''  ''  ''  0      2  PA PJ G9;
pass B   D   ''  J   ''  ''  ''  ''  ''  ''  0      2  PB G1 PD G3 DB PJ G9;
fail B   D   ''  J   ''  ''  ''  ''  ''  ''  0      2  PB G1 PD G2 DB PJ G9;
fail B   D   ''  J   ''  ''  ''  ''  ''  ''  0      2  PB G1 PD G3 PJ G9;
fail B   D   J   C   ''  ''  ''  ''  ''  ''  0      2  PB G1 PD G3 PJ G9;
pass AJ  ''  ''  ''  ''  ''  ''  ''  ''  ''  0      2  PA PJ G9 G0;
fail ADJ ''  ''  ''  ''  ''  ''  ''  ''  ''  0      3  PA PD PJ G3 DJ G0 PJ G9;
pass ADJ ''  ''  ''  ''  ''  ''  ''  ''  ''  0      3  PA PD PJ G3 DJ G0 G3 PJ G9;
fail ADJ ''  ''  ''  ''  ''  ''  ''  ''  ''  0      3  PA PD PJ G3 DJ G0 DD G3 PJ G9;
pass ADJ ''  ''  ''  ''  ''  ''  ''  ''  ''  0      3  PA PD PJ DD G3 DJ G0 DD G3 PJ G9;
fail ADJ ''  ''  ''  ''  ''  ''  ''  ''  ''  0      1  PA DA DA PD PJ G9;
pass ADJ ''  ''  ''  ''  ''  ''  ''  ''  ''  0      1  PA DA DA PJ G9;
fail ABCDEFGHIKLMNOPQRSTUVWXYZ  J  '' '' '' '' '' '' '' '' 0 26 PA PB PC PD PE PF PG PH PI PJ PK PL PM PN PO PP PQ PR PS PT PU PV PW PX PY PZ G9;
pass ABCDEFGHIJKLMNOPQRSTUVWXYZ '' '' '' '' '' '' '' '' '' 0 26 PA PB PC PD PE PF PG PH PI PJ PK PL PM PN PO PP PQ PR PS PT PU PV PW PX PY PZ G9;
fail YZJ ''  ''  ''  ''  ''  ''  ''  ''  ''  0      2  PY PZ CYZ PJ G9;
pass YZJ ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZW  2  PY PZ CYZ PJ G9;
pass YZJ ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZW  2  PY PZ CYZ PJ CWJ G9;
fail XYZJ '' ''  ''  ''  ''  ''  ''  ''  ''  1 YZW  2  PY PZ CYZ PX PJ G9;
fail XYZJ '' ''  ''  ''  ''  ''  ''  ''  ''  1 YZW  2  PY PZ CYZ PX DY DZ PJ G9;
pass XYZJ '' ''  ''  ''  ''  ''  ''  ''  ''  1 YZW  2  PY PZ CYZ PX DW PJ G9;
pass YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  2  PY PZ CYZ G9;
fail YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  2  CYZ G9;
pass YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  2  PY PZ CYZ CYZ G9;
fail YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  2  PY PZ CYZ DJ CYZ G9;
fail YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  2  PY PZ CYZ DJ PY PZ CYZ G9;
fail WZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  2  PW PZ CYZ G9;
fail WZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  2  PY PZ CYZ G9;
pass YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  2  PY PZ CZY G9;
pass YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 ZYJ  2  PY PZ CYZ G9;
fail YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  1  PY PZ CYZ G9;
fail YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  1  PY PZ CYZ PY PZ CYZ G9;
fail YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  1  PY PZ CYZ PJ G9;
fail YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  1  PJ G9;
pass BW  UV  ''  ''  ''  ''  ''  ''  ''  ''  3 BUR WVS RSJ  2  PB PW G1 DW PU CBU DR PW PV CVW PR CRS G9;
fail BW  AUV ''  ''  ''  ''  ''  ''  ''  ''  3 BUR WVS RSJ  2  PB G1 PU CBU DR PA PB G0 DA PW G1 PV CVW PR CRS G9;
pass BCW AUV ''  ''  ''  ''  ''  ''  ''  ''  3 CUR WVS RSJ  2  PB PC G1 DB PU CCU DR PC PA PB G0 DA PW G1 DB PV CVW PR CRS G9;
fail BCW UV  ''  ''  ''  ''  ''  ''  ''  ''  3 CUR WVS RSJ  2  PB PC G1 DB PU CCU DR PC PA PB G0 DA PW G1 DB PV CVW PR CRS G9;
fail BCW AUV ''  ''  ''  ''  ''  ''  ''  ''  3 CUR WVS RSJ  2  PB PC G1 DB PU CCU PA PB G0 DA PW G1 DB PV CVW PR CRS G9;
fail BCW AUV ''  ''  ''  ''  ''  ''  ''  ''  3 CUR WVS RSJ  2  PB PC G1 DB PU CCU DR PA G0 DA PW G1 DB PV CVW PR CRS G9;
fail BCW AUV ''  ''  ''  ''  ''  ''  ''  ''  3 CUR WVS RSJ  2  PB PC G1 DB PU CCU DR PB G0 DA PW G1 DB PV CVW PR CRS G9;
fail BCW AUV ''  ''  ''  ''  ''  ''  ''  ''  3 CUR WVS RSJ  2  PB PC G1 DB PU CCU DR PA PB G0 DA G1 DB PV CVW PR CRS G9;
fail BCW AUV ''  ''  ''  ''  ''  ''  ''  ''  3 CUR WVS RSJ  2  PB PC G1 DB PU CCU DR PA PB G0 DA PW G1 DB CVW PR CRS G9;
pass BFK LG  M   N   O   CDE PQR U   W   ''  10 BPT CQS TSH HUI IWV VFA GRX MXZ ANY YZJ  5 \
  PB PF PK G1 PL PG G6 DB DK DL G5 PC PD PE G6 DF G2 PM G6 DM DC G3 PN G4 PO G6 DN DO DD DE \
  PB PP CBP PC PQ CCQ CTS G7 PU CUH G8 PW CWI G6 PF CVF PR PM PN CGR CMX CAN CYZ G9
fail BFK LG  M   N   O   CDE PQR U   W   ''  10 BPT CQS TSH HUI IWV VFA GRX MXZ ANY YZJ  5 \
  PB PF PK G1 PL PG G6 DB DK DL G5 PC PD PE G6 DF G6 DM DC G3 PN G4 PO PM G6 DN DO DD DE \
  PB PP CBP PC PQ CCQ CTS G7 PU CUH G8 PW CWI G6 PF CVF PR PM PN CGR CMX CAN CYZ G9

if (( "$FAILURES" == "0" )); then
    echo "${GREEN}All tests passed${RESET}";
else
    echo "${RED}Total failures: $FAILURES${RESET}";
fi;
</code>```

Winning

Standard code golf: shortest code (in bytes) wins. Entries must follow the game rules, which in practice means they must pass all test cases (more tests may be added if necessary).

答:
Python 3, <s>321</s> 311 bytes

-10, thanks Dave

S,F=set,frozenset
def f(r,c,i,m):
 w,v,r,c=0,S(),list(map(S,r)),{F(k):S(x)for*k,x in c}
 for a,*q in m:
  p=F(q)
  if a<'D'and p in c and p<=v:v-=p;v|=c[p]
  elif a=='D'and p<=v:r[w]|=p;v-=p
  elif a=='G'and F(chr(65+int(q[0])))<=v:w=int(q[0])
  elif a>'G'and p<=r[w]and len(v)<i:r[w]-=p;v|=p
  if w==9:return 1
```

Rooms (r), combinations (c) and moves (m) are all lists of strings. Max inventory (i) is an int.

Fairly straight forward implementation.  Used set()s for the room contents and inventory to make updating easy. Used frozensets to key a dictionary of the combinations, so that the order of the 2 input items is irrelevant.

Title: A tiny adventure

Body:
Python 3, <s>321</s> 311 bytes

-10, thanks Dave

S,F=set,frozenset
def f(r,c,i,m):
 w,v,r,c=0,S(),list(map(S,r)),{F(k):S(x)for*k,x in c}
 for a,*q in m:
  p=F(q)
  if a<'D'and p in c and p<=v:v-=p;v|=c[p]
  elif a=='D'and p<=v:r[w]|=p;v-=p
  elif a=='G'and F(chr(65+int(q[0])))<=v:w=int(q[0])
  elif a>'G'and p<=r[w]and len(v)<i:r[w]-=p;v|=p
  if w==9:return 1

Rooms (r), combinations (c) and moves (m) are all lists of strings. Max inventory (i) is an int.

Fairly straight forward implementation.  Used set()s for the room contents and inventory to make updating easy. Used frozensets to key a dictionary of the combinations, so that the order of the 2 input items is irrelevant.


答:
Pyth, 32 bytes

```<code>jsMCm.[tylztsmC*\ dd*;ld+J._zt_J
</code>```

Demonstration

Title: Lemon-Limify a String

Body:
Pyth, 32 bytes

jsMCm.[tylztsmC*\ dd*;ld+J._zt_J

Demonstration


答:
Scala, 64 bytes

Can anyone improve on this?

(('A'to'Z'):+'A').sliding(2).map(_.mkString*13).foreach(println)
```

Title: Print an alphabet wave