问:
Tic-tac-toe with only crosses as quick as possible
As per Luke's request and Peter Taylor's addition to this challenge.

Introduction

Everyone knows the game tic-tac-toe, but in this challenge, we are going to introduce a little twist. We are only going to use crosses. The first person who places three crosses in a row loses. An interesting fact is that the maximum amount of crosses before someone loses, is equal to 6:

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

That means that for a 3 x 3 board, the maximum amount is 6. So for N = 3, we need to output 6.

Another example, for N = 4, or a 4 x 4 board:

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

This is an optimal solution, you can see that the maximum amount of crosses is equal to 9. An optimal solution for a 12 x 12 board is:

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

This results in 74.

The task

Your task is to compute the results as fast as possible. I will run your code on the test case 13. This will be done 5 times and then the average is taken of the run times. That is your final score. The lower, the better.

Test cases

```<code>N     Output
1       1
2       4
3       6
4       9
5       16
6       20
7       26
8       36
9       42
10      52
11      64
12      74
13      86
14      100
15      114
</code>```

More information can be found at https://oeis.org/A181018.

Rules

This is fastest-code, so the fastest submission wins!

You must provide a full program.

Please also provide how I have to run the program. I am not familiar with all programming languages and how they work, so I need a little bit of help here.

Of course, your code needs to compute the correct result for each test case.

Submissions:

feersum (C++11): 28s

Peter Taylor (Java): 14m 31s

答:
Java, 14m 31s

This is essentially the program which I posted to OEIS after using it to extend the sequence, so it's a good reference for other people to beat. I've tweaked it to take the board size as the first command-line argument.

public class A181018 {
    public static void main(String[] args) {
        int n = Integer.parseInt(args[0]);
        System.out.println(calc(n));
    }

    private static int calc(int n) {
        if (n < 0) throw new IllegalArgumentException("n");
        if (n < 3) return n * n;

        // Dynamic programming approach: given two rows, we can enumerate the possible third row.
        // sc[i + rows.length * j] is the greatest score achievable with a board ending in rows[i], rows[j].
        int[] rows = buildRows(n);
        byte[] sc = new byte[rows.length * rows.length];
        for (int j = 0, k = 0; j < rows.length; j++) {
            int qsc = Integer.bitCount(rows[j]);
            for (int i = 0; i < rows.length; i++) sc[k++] = (byte)(qsc + Integer.bitCount(rows[i]));
        }

        int max = 0;
        for (int h = 2; h < n; h++) {
            byte[] nsc = new byte[rows.length * rows.length];
            for (int i = 0; i < rows.length; i++) {
                int p = rows[i];
                for (int j = 0; j < rows.length; j++) {
                    int q = rows[j];
                    // The rows which follow p,q cannot intersect with a certain mask.
                    int mask = (p & q) | ((p << 2) & (q << 1)) | ((p >> 2) & (q >> 1));
                    for (int k = 0; k < rows.length; k++) {
                        int r = rows[k];
                        if ((r & mask) != 0) continue;

                        int pqrsc = (sc[i + rows.length * j] & 0xff) + Integer.bitCount(r);
                        int off = j + rows.length * k;
                        if (pqrsc > nsc[off]) nsc[off] = (byte)pqrsc;
                        if (pqrsc > max) max = pqrsc;
                    }
                }
            }

            sc = nsc;
        }

        return max;
    }

    private static int[] buildRows(int n) {
        // Array length is a tribonacci number.
        int c = 1;
        for (int a = 0, b = 1, i = 0; i < n; i++) c = a + (a = b) + (b = c);

        int[] rows = new int[c];
        int i = 0, j = 1, val;
        while ((val = rows[i]) < (1 << (n - 1))) {
            if (val > 0) rows[j++] = val * 2;
            if ((val & 3) != 3) rows[j++] = val * 2 + 1;
            i++;
        }

        return rows;
    }
}
```

Save to A181018.java; compile as javac A181018.java; run as java A181018 13. On my computer it takes about 20 minutes to execute for this input. It would probably be worth parallelising it.

ContentLicense: CC BY-SA 3.0

Body:
Java, 14m 31s

This is essentially the program which I posted to OEIS after using it to extend the sequence, so it's a good reference for other people to beat. I've tweaked it to take the board size as the first command-line argument.

public class A181018 {
    public static void main(String[] args) {
        int n = Integer.parseInt(args[0]);
        System.out.println(calc(n));
    }

    private static int calc(int n) {
        if (n < 0) throw new IllegalArgumentException("n");
        if (n < 3) return n * n;

        // Dynamic programming approach: given two rows, we can enumerate the possible third row.
        // sc[i + rows.length * j] is the greatest score achievable with a board ending in rows[i], rows[j].
        int[] rows = buildRows(n);
        byte[] sc = new byte[rows.length * rows.length];
        for (int j = 0, k = 0; j < rows.length; j++) {
            int qsc = Integer.bitCount(rows[j]);
            for (int i = 0; i < rows.length; i++) sc[k++] = (byte)(qsc + Integer.bitCount(rows[i]));
        }

        int max = 0;
        for (int h = 2; h < n; h++) {
            byte[] nsc = new byte[rows.length * rows.length];
            for (int i = 0; i < rows.length; i++) {
                int p = rows[i];
                for (int j = 0; j < rows.length; j++) {
                    int q = rows[j];
                    // The rows which follow p,q cannot intersect with a certain mask.
                    int mask = (p & q) | ((p << 2) & (q << 1)) | ((p >> 2) & (q >> 1));
                    for (int k = 0; k < rows.length; k++) {
                        int r = rows[k];
                        if ((r & mask) != 0) continue;

                        int pqrsc = (sc[i + rows.length * j] & 0xff) + Integer.bitCount(r);
                        int off = j + rows.length * k;
                        if (pqrsc > nsc[off]) nsc[off] = (byte)pqrsc;
                        if (pqrsc > max) max = pqrsc;
                    }
                }
            }

            sc = nsc;
        }

        return max;
    }

    private static int[] buildRows(int n) {
        // Array length is a tribonacci number.
        int c = 1;
        for (int a = 0, b = 1, i = 0; i < n; i++) c = a + (a = b) + (b = c);

        int[] rows = new int[c];
        int i = 0, j = 1, val;
        while ((val = rows[i]) < (1 << (n - 1))) {
            if (val > 0) rows[j++] = val * 2;
            if ((val & 3) != 3) rows[j++] = val * 2 + 1;
            i++;
        }

        return rows;
    }
}

Save to A181018.java; compile as javac A181018.java; run as java A181018 13. On my computer it takes about 20 minutes to execute for this input. It would probably be worth parallelising it.


问:
Swap the Alphabet
In this challenge, you will be "reversing" the alphabet or swapping a-z with z-a. This is commonly known as the Atbash cypher.

Because this transformation makes the output look like some foreign language, your code will need to be as short as possible.

Examples

```<code>abcdefghijklmnopqrstuvwxyz
zyxwvutsrqponmlkjihgfedcba

Programming Puzzles & Code Golf
Kiltiznnrmt Kfaaovh & Xlwv Tlou

Hello, World!
Svool, Dliow!
</code>```

Specification

The input may contain multiple lines, and will be ASCII-only

No additional whitespace should be added to the output

Case must be preserved

Leaderboard

var QUESTION_ID=68504,OVERRIDE_USER=40695;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

This is code-golf so shortest code in bytes wins

答:
Factor, 92 bytes

```<code>[ [ 65 90 [a,b] dup >lower 2dup [ reverse ] bi@ append -rot append zip >hashtable at ] map ]
</code>```

An anonymous function. Making it case insensitive is... expensive.

Title: Swap the Alphabet

Body:
Factor, 92 bytes

[ [ 65 90 [a,b] dup >lower 2dup [ reverse ] bi@ append -rot append zip >hashtable at ] map ]

An anonymous function. Making it case insensitive is... expensive.


问:
Open the browser to http://codegolf.stackexchange.com
Your job is to open a browser window of the default browser to http://codegolf.stackexchange.com.

Your code must open the browser itself, and cannot rely on an open one.

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

Moderator note: A large number of answers to this challenge use the URLs http://ppcg.lol or http://ppcg.ga. These URLs did direct to https://codegolf.stackexchange.com at the time, but have since expired. By this meta discussion, they have been allowed to stay, with the note that they are currently invalid.

答:
Ruby, <s>22</s> <s>20</s> 19 bytes  (on OS X)

```<code>`open http:ppcg.ga`
</code>```

Simple.

Thanks to Daniel for 2 bytes off.

ContentLicense: CC BY-SA 4.0

Body:
Ruby, <s>22</s> <s>20</s> 19 bytes  (on OS X)

`open http:ppcg.ga`

Simple.

Thanks to Daniel for 2 bytes off.


问:
Create output twice the length of the code

The Challenge

Write a complete program that writes twice as many bytes to standard output as the length of the program.

Rules

The program must write ASCII characters to the standard output.

The contents of the output doesn't matter.

The output, measured in bytes, must be exactly twice the length of the program, also measured in bytes, unless you fulfill the bonus.

Any trailing newline is included in the output's byte count.

Bonus

Your program can optionally take a number, n, as input. If so, the output must be exactly n * program length bytes. You can assume that n will always be a positive integer. If no input is provided, n must default to 2.

If you do this,  you can subtract 25 bytes from your score.

Shortest program wins.

Restrictions

No standard loopholes.

The program must be at least 1 byte long.

No adding unnecessary whitespace to the source code to change its length. Similarly, comments don't count.

Unless you fulfill the bonus, the program must accept no input. If you do fulfill the bonus, the integer must be the only input.

Lowest score (program length in bytes - bonus) wins.

The shortest answer for each language wins for that language.

Leaderboards

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

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

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

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

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

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

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

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

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

var QUESTION_ID=59436,OVERRIDE_USER=41505;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\-?\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\-?\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
Underload, 12 bytes

```<code>(\/)a:*::**S
</code>```

Outputs

```<code>(\/)(\/)(\/)(\/)(\/)(\/)
</code>```

Try It Online

Explanation

```<code>(\/)            # push \/ to the stack        : \/
    a           # add brackets to TOS         : (\/)
     :*         # duplicate the TOS and join. : (\/)(\/)
       ::       # duplicate a couple of times : (\/)(\/)<>(\/)(\/)<>(\/)(\/)
         **     # join stack items            : (\/)(\/)(\/)(\/)(\/)(\/)
           S    # output TOS
</code>```

Body:
Underload, 12 bytes

(\/)a:*::**S

Outputs

(\/)(\/)(\/)(\/)(\/)(\/)

Try It Online

Explanation

(\/)            # push \/ to the stack        : \/
    a           # add brackets to TOS         : (\/)
     :*         # duplicate the TOS and join. : (\/)(\/)
       ::       # duplicate a couple of times : (\/)(\/)<>(\/)(\/)<>(\/)(\/)
         **     # join stack items            : (\/)(\/)(\/)(\/)(\/)(\/)
           S    # output TOS


问:
A Tiny Explorer
You are an explorer, mapping an unknown world. Your ship is carried on the wind. Where it goes, who knows?

Each day, in your spyglass, you see features to the north, south, east and west. You always see four such features, corresponding to the cardinal directions. Your spyglass reports ASCII symbols like this:

~~.*, ~~~~, ~.^^, ~#~#

The symbols are in the order (north, south, east, west).

These are the symbols: ~ = sea, . = coast, ^ = mountain, * = tree, # = invalid (no observation, this occurs whenever you see the edge of the world, or the landscape is obscured by fog). Your spyglass sees exactly one unit in every direction.

Each night, you look up at the stars to see how far you've travelled. Looking at the stars reports an ascii symbol like this:

n, s, e, w

corresponding to North, South, East and West, respectively. You always move exactly one unit to the north, south, east or west every night. So you, as explorer will be receiving an endless stream of symbols:

~~.*n~~~~s~~.*s~.**

Your task is to output a 2D map of the world (where ? are unknown parts of the map, north is up, east is right):

```<code>?~~~??????
?~~~??????
?~~~.^^.??
?~~.***.~~
~~.*^^*.~~
~~~..~~~~~
~~~~~~~~~~
~~~~~~~~~~
</code>```

For the sake of simplicity let's assume you start in the bottom left corner of the map. Assume all maps are 8x8.

Here is a simple 3x3 example. Assume the map looks like this:

```<code>~.~
~^~
~.~
</code>```

With the following input: ~#.#n~~^#s

You will get this output:

```<code>~??
~^?
~.?
</code>```

More example inputs and outputs:

input
~#~#n~~~#n~~~#n~~~#n~~~#n~~.#n~~.#n#~~#e#.~~e#.~~e#.~~e#.~~e#~~~e#~~~e#~#~s~~#~s~~#~s~~#~s~~#.s~~#~s~~#~s~##~w~#~~w.#~~w^#~~w.#~~

output

```<code>~~~~~~~~
~....~~~
~.????~~
~~????~~
~~????.~
~~????~~
~~?.^.~~
~~~~~~~~
</code>```

Input:

~#~#e~#~~e~#~~e.#~~e^#~~n.~..n~^~.n~.~~n.~~.n.~~*n~.~.n#.~~w#.~~w#.~~s~*..s..*.s*~.~s.~~~s

Output:

```<code>?~~~~~??
?....~??
?.**.~??
?~..~~??
?~~~~~??
?~~..~??
~~~.^.??
~~~~~~??
</code>```

答:
Kotlin, 242 bytes

{val m=Array(8){Array(8){'?'}}
var d=7
var i=0
for(c in it)(mapOf('n' to{d--},'s' to{d++},'w' to{d-=8},'e' to{d+=8},'#' to{i++})[c]?:{m[d%8+listOf(-1,1,0,0)[i%4]][d/8+listOf(0,0,1,-1)[i%4]]=c
i++})()
m.forEach{for(c in it)print(c);println()}}
```

The newlines can be replaced with semicolons if wished.

Try Here

Title: A Tiny Explorer

Body:
Kotlin, 242 bytes

{val m=Array(8){Array(8){'?'}}
var d=7
var i=0
for(c in it)(mapOf('n' to{d--},'s' to{d++},'w' to{d-=8},'e' to{d+=8},'#' to{i++})[c]?:{m[d%8+listOf(-1,1,0,0)[i%4]][d/8+listOf(0,0,1,-1)[i%4]]=c
i++})()
m.forEach{for(c in it)print(c);println()}}

The newlines can be replaced with semicolons if wished.

Try Here


答:
C#, 33 bytes

```<code>Process.Start("http://ppcg.lol");
</code>```

Opens the default browser to the web address

Title: Open the browser to http://codegolf.stackexchange.com

Body:
Your job is to open a browser window of the default browser to http://codegolf.stackexchange.com.

Your code must open the browser itself, and cannot rely on an open one.

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

Moderator note: A large number of answers to this challenge use the URLs http://ppcg.lol or http://ppcg.ga. These URLs did direct to https://codegolf.stackexchange.com at the time, but have since expired. By this meta discussion, they have been allowed to stay, with the note that they are currently invalid.

Body:
C#, 33 bytes

Process.Start("http://ppcg.lol");

Opens the default browser to the web address


问:
Child Genotypes
The Challenge

Everybody loves genetics, right? In this challenge, you will be given the genotypes of two parents. You must find each possible genotype of a child produced by the parents. You must account for dominant and recessive alleles as well as incomplete dominance and codominance.

An example input for the parents could be:

```<code>R'RxRr
</code>```

Parent one (on the left) has a incompletely dominant R allele and a dominant R allele. Parent two (on the right) has a dominant R allele and a recessive allele.

Each parent is separated from the other by an x. The input will not contain an x allele.

An incompletely dominant allele will be followed by an apostrophe ('). Codominant alleles just refers to multiple different types of alleles combined together (A and W for example).

Rules

Shortest code wins (measured in bytes).

Each possibly genotype must be separated from the other genotypes by a comma.

Phenotypes don't matter.

Any letter can be used in the input except for x (which differentiates the parents).

Duplicate genotypes should only be printed once.

Duplicates contain the exact same letters of the same case and type of allele. IF you have WY and YW in your answer, they are considered duplicates.

No more than three different letters will be used in one input.

The order of the letters in the output does not matter.

Answer can be in the form of a string or an array.

Examples

Input 1 (the previous example):

```<code>R'RxRr
</code>```

Output 1:

```<code>R'R,R'r,RR,Rr
</code>```

Alternate output 1 (array):

```<code>{R'R,R'r,RR,Rr}
</code>```

Input 2:

```<code>RWxRR
</code>```

Output 2:

```<code>RR,WR
//Or an array, whichever you want
</code>```

Input 3:

```<code>WYxY'y
</code>```

Output 3:

```<code>WY',Wy,YY',Yy
//Once again, an array is fine
</code>```

答:
Pyth, <s>20</s> 18 bytes

```<code>{msSd*Fc:z".'?"1\x
</code>```

Test suite.

```<code>         z          get input
        : ".'?"1    regex match for any character followed by an optional '
       c        \x  chop on the element "x", resulting in [["R'","R"],["R","r"]]
     *F             splat over Cartesian product, resulting in pairs of "genes"
                      from the first "parent" and from the second
 m  d               map over each resulting pair...
   S                sort (so that we can dedup later)
  s                 concatenate
{                   remove duplicates
</code>```

Title: Child Genotypes

Body:
Pyth, <s>20</s> 18 bytes

{msSd*Fc:z".'?"1\x

Test suite.

         z          get input
        : ".'?"1    regex match for any character followed by an optional '
       c        \x  chop on the element "x", resulting in [["R'","R"],["R","r"]]
     *F             splat over Cartesian product, resulting in pairs of "genes"
                      from the first "parent" and from the second
 m  d               map over each resulting pair...
   S                sort (so that we can dedup later)
  s                 concatenate
{                   remove duplicates


答:
JavaScript (ES6), <s>114</s> <s>112</s> <s>104</s> <s>90</s> 88 bytes

```<code>f=>(c=new Set,[z,y]=f.split`x`.map(b=>b.match(/.'?/g)),z.map(e=>y.map(g=>c.add(e+g))),c)
</code>```

Thanks to Doorknob, Downgoat, Kenny Lau and Neil for helping me golf this down a bit :)

Title: Child Genotypes

Body:
The Challenge

Everybody loves genetics, right? In this challenge, you will be given the genotypes of two parents. You must find each possible genotype of a child produced by the parents. You must account for dominant and recessive alleles as well as incomplete dominance and codominance.

An example input for the parents could be:

```<code>R'RxRr
</code>```

Parent one (on the left) has a incompletely dominant R allele and a dominant R allele. Parent two (on the right) has a dominant R allele and a recessive allele.

Each parent is separated from the other by an x. The input will not contain an x allele.

An incompletely dominant allele will be followed by an apostrophe ('). Codominant alleles just refers to multiple different types of alleles combined together (A and W for example).

Rules

Shortest code wins (measured in bytes).

Each possibly genotype must be separated from the other genotypes by a comma.

Phenotypes don't matter.

Any letter can be used in the input except for x (which differentiates the parents).

Duplicate genotypes should only be printed once.

Duplicates contain the exact same letters of the same case and type of allele. IF you have WY and YW in your answer, they are considered duplicates.

No more than three different letters will be used in one input.

The order of the letters in the output does not matter.

Answer can be in the form of a string or an array.

Examples

Input 1 (the previous example):

```<code>R'RxRr
</code>```

Output 1:

```<code>R'R,R'r,RR,Rr
</code>```

Alternate output 1 (array):

```<code>{R'R,R'r,RR,Rr}
</code>```

Input 2:

```<code>RWxRR
</code>```

Output 2:

```<code>RR,WR
//Or an array, whichever you want
</code>```

Input 3:

```<code>WYxY'y
</code>```

Output 3:

```<code>WY',Wy,YY',Yy
//Once again, an array is fine
</code>```

Body:
JavaScript (ES6), <s>114</s> <s>112</s> <s>104</s> <s>90</s> 88 bytes

f=>(c=new Set,[z,y]=f.split`x`.map(b=>b.match(/.'?/g)),z.map(e=>y.map(g=>c.add(e+g))),c)

Thanks to Doorknob, Downgoat, Kenny Lau and Neil for helping me golf this down a bit :)


答:
Ruby, <s>82</s> 77 bytes

Anonymous function, takes the input string as its argument.

Edited to properly account for ABxAB.

-5 bytes from @Doorknob.

```<code>->g{a,b=g.split(?x).map{|s|s.scan /.'?/}
a.product(b).map{|s|s.sort*""}.uniq}
</code>```

Title: Child Genotypes

Body:
Ruby, <s>82</s> 77 bytes

Anonymous function, takes the input string as its argument.

Edited to properly account for ABxAB.

-5 bytes from @Doorknob.

->g{a,b=g.split(?x).map{|s|s.scan /.'?/}
a.product(b).map{|s|s.sort*""}.uniq}


问:
Express a number with only 0-9 and the four operations

Explanation

Befunge is a two-dimensional program that uses stacks.

That means, to do 5 + 6, you write 56+, meaning:

```<code>56+
5    push 5 into stack
 6   push 6 into stack
  +  pop the first two items in the stack and add them up, and push the result into stack

(to those of you who do not know stacks, "push" just means add and "pop" just means take off)
</code>```

However, as the intelligent of you have observed, we cannot push the number 56 directly into the stack.

To do so, we must write 78* instead, which multiplies 7 and 8 and pushes the product into the stack.

Details

Input can be taken in any format, meaning it can be STDIN or not, at the programmer's discretion.

The input will be a positive integer (no bonus for including 0 or negative integers).

The output will be a string consisting of only these characters: 0123456789+-*/ (I would not use % modulo.)

The goal is to find the shortest string that can represent the input, using the format described above.

For example, if the input is 123, then the output would be 67*99*+. The output should be evaluated from left to right.

If there are more than one acceptable outputs (e.g. 99*67*+ is also acceptable), any one can be printed (no bonus for printing all of them).

Further Explanation

If you still do not understand how 67*99*+ evaluates to 123, here is a detailed explanation.

```<code>stack    |operation|explanation
          67*99*+
[6]       6         push 6 to stack
[6,7]      7        push 7 to stack
[42]        *       pop two from stack and multiply, then put result to stack
[42,9]       9      push 9 to stack
[42,9,9]      9     push 9 to stack
[42,81]        *    pop two from stack and multiply, then put result to stack
[123]           +   pop two from stack and add, then put result to stack
</code>```

TL;DR

The program needs to find the shortest string that can represent the input (number), using the format specified above.

Notes

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

Disambiguation

The - can either be x-y or y-x, at the programmer's discretion. However, the choice must be consistent within the solution. Likewise for the /.

Sample program

Lua, 1862 bytes (try it online)

Since I am the author, I will not golf it at all.

Explanation:

```<code>This uses the depth-first search method.
</code>```

More about depth-first search: here.

The program:

```<code>local input = (...) or 81

local function div(a,b)
    if b == 0 then
        return "error"
    end
    local result = a/b
    if result > 0 then
        return math.floor(result)
    else
        return math.ceil(result)
    end
end

local function eval(expr)
    local stack = {}
    for i=1,#expr do
        local c = expr:sub(i,i)
        if c:match('[0-9]') then
            table.insert(stack, tonumber(c))
        else
            local a = table.remove(stack)
            local b = table.remove(stack)
            if a and b then
                if c == '+' then
                    table.insert(stack, a+b)
                elseif c == '-' then
                    table.insert(stack, b-a)
                elseif c == '*' then
                    table.insert(stack, a*b)
                elseif c == '/' then
                    local test = div(b,a)
                    if test == "error" then
                        return -1
                    else
                        table.insert(stack, a+b)
                    end
                end
            else
                return -1
            end
        end
    end
    return table.remove(stack) or -1
end

local samples, temp = {""}, {}

while true do
    temp = {}
    for i=1,#samples do
        local s = samples[i]
        table.insert(temp, s..'0')
        table.insert(temp, s..'1')
        table.insert(temp, s..'2')
        table.insert(temp, s..'3')
        table.insert(temp, s..'4')
        table.insert(temp, s..'5')
        table.insert(temp, s..'6')
        table.insert(temp, s..'7')
        table.insert(temp, s..'8')
        table.insert(temp, s..'9')
        table.insert(temp, s..'+')
        table.insert(temp, s..'-')
        table.insert(temp, s..'*')
        table.insert(temp, s..'/')
    end
    for i=1,#temp do
        if input == eval(temp[i]) then
            print(temp[i])
            return
        end
    end
    samples = temp
end
</code>```

Bonus

A cake for you if you use Befunge (or any variant of it) to write the code.

答:
Python 2, 284 bytes

Disclaimer:  Takes freaking forever for some values ... but should be guaranteed to always return the shortest string, and has no artificially imposed range limit ... even works on negative values. :)

```<code>def f(v):
 i,z=0,'+-*/'
 while 1:
  s=('%x'%i).translate(__import__('string').maketrans('abcd',z),'ef');t=s;q=[];a,p=q.append,q.pop;i+=1
  try:
   while t:
    o,t=t[0],t[1:]
    if o in z:n,m=p(),p();a(eval(`m`+o+`n`))
    else:a(int(o))
   if p()==v and not q:return s
  except:pass
</code>```

Algorithm:

Start with i = 0

Take the string representing the hex value of i, and replace abcd with +-*/ respectively, and remove any ef

Attempt to process string as postfix notation (RPN)

If successful, and result matches input value, return the string used.

Otherwise, increment i and try again.

Body:
Python 2, 284 bytes

Disclaimer:  Takes freaking forever for some values ... but should be guaranteed to always return the shortest string, and has no artificially imposed range limit ... even works on negative values. :)

def f(v):
 i,z=0,'+-*/'
 while 1:
  s=('%x'%i).translate(__import__('string').maketrans('abcd',z),'ef');t=s;q=[];a,p=q.append,q.pop;i+=1
  try:
   while t:
    o,t=t[0],t[1:]
    if o in z:n,m=p(),p();a(eval(`m`+o+`n`))
    else:a(int(o))
   if p()==v and not q:return s
  except:pass

Algorithm:

Start with i = 0

Take the string representing the hex value of i, and replace abcd with +-*/ respectively, and remove any ef

Attempt to process string as postfix notation (RPN)

If successful, and result matches input value, return the string used.

Otherwise, increment i and try again.


问:
Final Fantasy XV UNCOVERED!
Since I am INSANELY hyped for the Final Fantasy XV Uncovered event, I want you to write me a program to tell me when it is!!!

The input

Your take input in the form of HH:MM XDT, where HH is a number in the range 1-12, MM is a number between 0-60, and XDT is a time zone, with X being one of E (eastern, UTC-4), C (central, UTC-5), P (pacific, UTC-7), or M (mountain, UTC-6). This is a time assumed to be PM. Valid inputs include:

```<code>1:00 EDT (1 PM Eastern Daylight Time)
4:05 MDT (4:05 PM Mountain Daylight Time)
12:23 PDT (12:23 PM Pacific Daylight Time)
1:10 CDT (1:10 PM Central Daylight Time)
</code>```

The input may be assumed to be valid.

The output

Your program must do the following:

Convert the given time to PDT and output It is XX:XX PM PDT., where XX:XX is the converted time. Note that you do not need to handle any case where converting the time would cross the AM/PM boundary.

Print one of the following:

If the converted time is before 6:00 PM PDT, print X minutes until the pre-show!, replacing X with the number of minutes until 6:00 PM PDT.

If the converted time is after or equal to 6:00 PM PDT and before 7:00 PM PDT, print Pre-show started X minutes ago; UNCOVERED is starting in Y minutes!, where X is the number of minutes that have passed since 6:00 PM PDT, and Y is the number of minutes until 7:00 PM PDT.

If the converted time is after or equal to 7:00 PM PDT, print UNCOVERED started X minutes ago!, where X is the number of minutes that have passed since 7:00 PM PDT.

Each string printed must be followed by a newline.

Scoring

This is code golf, so the shortest program wins.

答:
Lua, <s>357</s> <s>335</s> 332 bytes

Thanks to @Katenkyo for chopping off 22 bytes.

Golfed:

h,m,t=(...):match("(%d+):(%d+) (.)")f=tonumber h=(f(h)-("PMCE"):find(t))%12+1m=f(m)print("It is "..h..":"..m.." PM PDT.")a=" minutes"b="UNCOVERED"n=(6-h)*60-m r=h<6 and n..a.." until the pre-show!"or h<7 and"Pre-show started "..m..a.." ago; "..b.." is starting in "..(n+60)..a.."!"or b.." started "..(m+(h-7)*60)..a.." ago!"print(r)
```

<p>(Try it online)</p>

<p>Ungolfed:</p>

<pre class="lang-lua prettyprint-override"><code>n = "7:10 CST"

h,m,t = n:match("(%d+):(%d+) (.)")
h = (tonumber(h) - ("PMCE"):find(t))%12 + 1
m = tonumber(m)
print("It is "..h..":"..m.." PM PDT.")

n = (6-h)*60-m

if h<6 then
  r=n.." minutes until the pre-show!"
elseif h<7 then
  r="Pre-show started "..m.." minutes ago; UNCOVERED is starting in "..(n+60).." minutes!"
else
  r="UNCOVERED started "..(m+(h-7)*60).." minutes ago!"
end

print(r)
</code>```

Title: Final Fantasy XV UNCOVERED!

Body:
Lua, <s>357</s> <s>335</s> 332 bytes

Thanks to @Katenkyo for chopping off 22 bytes.

Golfed:

h,m,t=(...):match("(%d+):(%d+) (.)")f=tonumber h=(f(h)-("PMCE"):find(t))%12+1m=f(m)print("It is "..h..":"..m.." PM PDT.")a=" minutes"b="UNCOVERED"n=(6-h)*60-m r=h<6 and n..a.." until the pre-show!"or h<7 and"Pre-show started "..m..a.." ago; "..b.." is starting in "..(n+60)..a.."!"or b.." started "..(m+(h-7)*60)..a.." ago!"print(r)

(Try it online)

Ungolfed:

n = "7:10 CST"

h,m,t = n:match("(%d+):(%d+) (.)")
h = (tonumber(h) - ("PMCE"):find(t))%12 + 1
m = tonumber(m)
print("It is "..h..":"..m.." PM PDT.")

n = (6-h)*60-m

if h<6 then
  r=n.." minutes until the pre-show!"
elseif h<7 then
  r="Pre-show started "..m.." minutes ago; UNCOVERED is starting in "..(n+60).." minutes!"
else
  r="UNCOVERED started "..(m+(h-7)*60).." minutes ago!"
end

print(r)


问:
Golf the xᵗʰ root of x
While bored in high-school (when I was half my current age...), I found that \$f(x) = x^{x^{-1}}\$ had some interesting properties, including e.g. that the maximum \$f\$ for \$0 ≤ x\$ is \$f(e)\$, and that the binding energy per nucleon of an isotope can be approximated as \$6 × f(x ÷ 21)\$...

Anyway, write the shortest function or program that calculates the xth root of x for any number in your language's domain.

Examples cases

For all languages

```<code>     -1   >       -1
   ¯0.2   >    -3125
   ¯0.5   >        4
    0.5   >     0.25
      1   >        1
      2   >    1.414
      e   >    1.444
      3   >    1.442
    100   >    1.047
  10000   >    1.001
</code>```

For languages that handle complex numbers

```<code>   -2   >        -0.7071i
    i   >            4.81
   2i   >    2.063-0.745i
 1+2i   >   1.820-0.1834i
 2+2i   >   1.575-0.1003i
</code>```

For languages that handle infinities

```<code>-1/∞   >   0    (or ∞ or ̃∞)
   0   >   0    (or 1 or ∞)
 1/∞   >   0
   ∞   >   1
  -∞   >   1
</code>```

For languages that handle both infinities and complex numbers

```<code> -∞-2i   >   1      (or ̃∞)
</code>```

 ̃∞ denotes directed infinity.

答:
Lua, 20

```<code>n=(...)print(n^n^-1)
</code>```

How it works:

```<code>n=(...)              Take input and store at n
       print(
             n^n^-1  n^(n^(-1))
                   )
</code>```

Title: Golf the xᵗʰ root of x

Body:
Lua, 20

n=(...)print(n^n^-1)

How it works:

n=(...)              Take input and store at n
       print(
             n^n^-1  n^(n^(-1))
                   )


问:
Create an ABACABA city
Here is the 3rd ABACABA city:

```<code>  _
A|_|
B|__|
A|_|_
C|___|
A|_|
B|__|
A|_|
</code>```

It is made out of the ABACABA sequence, which is basically:

A (1st iteration)

place B - AB

repeat A - ABA (2nd iteration)

Place C - ABAC

Repeat ABA - ABACABA (3rd iteration)

and you get the idea.

The buildings have a height (corresponded by no. of underscores) equal to the letters converted to numbers as A = 1, B = 2 e.t.c.

Input

An iteration number 1<=n<=26.

Output

The ABACABA city of order n, including the letters at the start of the lines.

答:
CJam, <s>37</s> 35 bytes

```<code>SS'_Lri{[H)'_*_2>N@H'A+'|@'|6$]+}fH
</code>```

This is an iterative implementation of the recursive algorithm from @quintopia's answer.

Try it online!

How it works

```<code>SS'_     e# Push two spaces and an underscore.
L        e# Push "".
ri       e# Read an integer I from STDIN.
{        e# For each H in [0 ... I-1]:
  [      e#   Set an array marker.
    H)   e#     Push Push H+1.
    '_*  e#     Push a string of that many underscores.
    _2>  e#   Push a copy and remove the first two underscores.
    N    e#   Push a linefeed.
    @    e#   Rotate the longer string of underscores on top of it.
    h'A+ e#   Add H to the character 'A', pushing the corresponding letter.
    '|  e#    Push a vertical bar.
    @   e#    Rotate the string of underscores on top of it.
    '|  e#    Push another vertical bar.
    6$  e#    Push a copy of the previous iteration (initially "").
  ]     e#   Wrap everything up to the former marker in an array.
}fH     e#
</code>```

Title: Create an ABACABA city

Body:
CJam, <s>37</s> 35 bytes

SS'_Lri{[H)'_*_2>N@H'A+'|@'|6$]+}fH

This is an iterative implementation of the recursive algorithm from @quintopia's answer.

Try it online!

How it works

SS'_     e# Push two spaces and an underscore.
L        e# Push "".
ri       e# Read an integer I from STDIN.
{        e# For each H in [0 ... I-1]:
  [      e#   Set an array marker.
    H)   e#     Push Push H+1.
    '_*  e#     Push a string of that many underscores.
    _2>  e#   Push a copy and remove the first two underscores.
    N    e#   Push a linefeed.
    @    e#   Rotate the longer string of underscores on top of it.
    h'A+ e#   Add H to the character 'A', pushing the corresponding letter.
    '|  e#    Push a vertical bar.
    @   e#    Rotate the string of underscores on top of it.
    '|  e#    Push another vertical bar.
    6$  e#    Push a copy of the previous iteration (initially "").
  ]     e#   Wrap everything up to the former marker in an array.
}fH     e#


问:
Generate the Abacaba sequence
This challenge is about printing the abacaba sequence of a specific depth.

Here is a diagram of the first 5 sequences (a(N) is the abacaba sequence of depth N, upper/lowercase is just to show the pattern, this is not needed in the output of your program):

```<code>a(0) = A
a(1) = aBa
a(2) = abaCaba
a(3) = abacabaDabacaba
a(4) = abacabadabacabaEabacabadabacaba
...
a(25) = abacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabahabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabaiabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabahabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabajabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabahabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabaia...
</code>```

As you can probably tell, the n'th abacaba sequence is the last one with the n'th letter and itself again added to it. (a(n) = a(n - 1) + letter(n) + a(n - 1))

Your task is to make a program or function that takes an integer and prints the abacaba sequence of that depth. The output has to be correct at least for values up to and including 15.

答:
J, <s>30</s> 28 bytes (Try it online!)

I just found out that a(0) = "a", which chopped of 2 bytes.

```<code>u:97+(0:`($:@<:,],$:@<:)@.*)
</code>```

Usage:

```<code>   u:97+(0:`($:@<:,],$:@<:)@.*) 2
abacaba
</code>```

How it works:

```<code>u:97+(0:`($:@<:,],$:@<:)@.*) n NB. pseudocode:
                               NB. input as n
                               NB. function as generate_tree
u:                             NB.   convert_to_ASCII(
  97+                          NB.     add_to_all(97,
     (xx`yyyyyyyyyyyyyyy@.z)   NB.       if z then y or x:
                          *    NB.         z: n>0?
      0:                       NB.         x: 0
         ($:@<:,],$:@<:)       NB.         y:
          ppppp,q,rrrrr        NB.           concat(p,q,r):
          $:@<:                NB.             p:
          $:@                  NB.               generate_tree(
             <:                NB.                 n-1)
                ]              NB.             q: n
                  $:@<:        NB.             r: generate_tree(n-1)
</code>```

Title: Generate the Abacaba sequence

Body:
J, <s>30</s> 28 bytes (Try it online!)

I just found out that a(0) = "a", which chopped of 2 bytes.

u:97+(0:`($:@<:,],$:@<:)@.*)

Usage:

   u:97+(0:`($:@<:,],$:@<:)@.*) 2
abacaba

How it works:

u:97+(0:`($:@<:,],$:@<:)@.*) n NB. pseudocode:
                               NB. input as n
                               NB. function as generate_tree
u:                             NB.   convert_to_ASCII(
  97+                          NB.     add_to_all(97,
     (xx`yyyyyyyyyyyyyyy@.z)   NB.       if z then y or x:
                          *    NB.         z: n>0?
      0:                       NB.         x: 0
         ($:@<:,],$:@<:)       NB.         y:
          ppppp,q,rrrrr        NB.           concat(p,q,r):
          $:@<:                NB.             p:
          $:@                  NB.               generate_tree(
             <:                NB.                 n-1)
                ]              NB.             q: n
                  $:@<:        NB.             r: generate_tree(n-1)


答:
Python (335 bytes)

```<code>t=raw_input().replace(*': ').split();x='PMCE'.index(t[2][0]);t[0]=int(t[0])+x;print '%s:%s PM PDT' % tuple(t[:1]);x=t[0]*60+int(t[1]);print ['%s minutes until the pre-show!'%(360-x),'Pre-show started %s minutes ago; UNCOVERED is starting in %s minutes!'%((x-360),(420-x)), 'UNCOVERED started %s minutes ago!'%(x-420)][(x>360)+(x>420)]
</code>```

Output:

```<code>1:00 MDT
2:00 PM PDT
240 minutes until the pre-show!

6:00 CDT
8:00 PM PDT
UNCOVERED started 60 minutes ago!

6:50 PDT
6:50 PM PDT
Pre-show started 50 minutes ago; UNCOVERED is starting in 10 minutes!
</code>```

Title: Final Fantasy XV UNCOVERED!

Body:
Since I am INSANELY hyped for the Final Fantasy XV Uncovered event, I want you to write me a program to tell me when it is!!!

The input

Your take input in the form of HH:MM XDT, where HH is a number in the range 1-12, MM is a number between 0-60, and XDT is a time zone, with X being one of E (eastern, UTC-4), C (central, UTC-5), P (pacific, UTC-7), or M (mountain, UTC-6). This is a time assumed to be PM. Valid inputs include:

```<code>1:00 EDT (1 PM Eastern Daylight Time)
4:05 MDT (4:05 PM Mountain Daylight Time)
12:23 PDT (12:23 PM Pacific Daylight Time)
1:10 CDT (1:10 PM Central Daylight Time)
</code>```

The input may be assumed to be valid.

The output

Your program must do the following:

Convert the given time to PDT and output It is XX:XX PM PDT., where XX:XX is the converted time. Note that you do not need to handle any case where converting the time would cross the AM/PM boundary.

Print one of the following:

If the converted time is before 6:00 PM PDT, print X minutes until the pre-show!, replacing X with the number of minutes until 6:00 PM PDT.

If the converted time is after or equal to 6:00 PM PDT and before 7:00 PM PDT, print Pre-show started X minutes ago; UNCOVERED is starting in Y minutes!, where X is the number of minutes that have passed since 6:00 PM PDT, and Y is the number of minutes until 7:00 PM PDT.

If the converted time is after or equal to 7:00 PM PDT, print UNCOVERED started X minutes ago!, where X is the number of minutes that have passed since 7:00 PM PDT.

Each string printed must be followed by a newline.

Scoring

This is code golf, so the shortest program wins.

Body:
Python (335 bytes)

t=raw_input().replace(*': ').split();x='PMCE'.index(t[2][0]);t[0]=int(t[0])+x;print '%s:%s PM PDT' % tuple(t[:1]);x=t[0]*60+int(t[1]);print ['%s minutes until the pre-show!'%(360-x),'Pre-show started %s minutes ago; UNCOVERED is starting in %s minutes!'%((x-360),(420-x)), 'UNCOVERED started %s minutes ago!'%(x-420)][(x>360)+(x>420)]

Output:

1:00 MDT
2:00 PM PDT
240 minutes until the pre-show!

6:00 CDT
8:00 PM PDT
UNCOVERED started 60 minutes ago!

6:50 PDT
6:50 PM PDT
Pre-show started 50 minutes ago; UNCOVERED is starting in 10 minutes!


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

答:
Pylongolf, 43 bytes

```<code>."Greetings, Planet!"~"!tenalP ,sgniteerG".
</code>```

~ prints the stack nicely, . resets the stack.

"Greetings, Planet!" pushes the sentence into the stack, ~ prints it.

The rest is a blur.

EDIT: I saved 2 bytes by removing the ~ symbols on both sides.

Title: Palindrome Hello, World

Body:
Pylongolf, 43 bytes

."Greetings, Planet!"~"!tenalP ,sgniteerG".

~ prints the stack nicely, . resets the stack.

"Greetings, Planet!" pushes the sentence into the stack, ~ prints it.

The rest is a blur.

EDIT: I saved 2 bytes by removing the ~ symbols on both sides.


答:
Perl 5, <s>66</s> <s>57</s> 76 bytes

Should work everywhere, but needs that import :(

8 bytes saved with @msh210 comment.

```<code>use Browser::Open open_browser;open_browser"http:codegolf.stackexchange.com"
</code>```

Also, for funsies :

Perl 5 (Windows), <s>34</s> 48 bytes

```<code>system "start http://codegolf.stackexchange.com"
</code>```

Perl 5 (Unix), <s>31</s> 49 bytes

```<code>system "xdg-open http:codegolf.stackexchange.com"
</code>```

Body:
Perl 5, <s>66</s> <s>57</s> 76 bytes

Should work everywhere, but needs that import :(

8 bytes saved with @msh210 comment.

use Browser::Open open_browser;open_browser"http:codegolf.stackexchange.com"

Also, for funsies :

Perl 5 (Windows), <s>34</s> 48 bytes

system "start http://codegolf.stackexchange.com"

Perl 5 (Unix), <s>31</s> 49 bytes

system "xdg-open http:codegolf.stackexchange.com"


问:
Showcase of Languages

Notes

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

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

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

How this works

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

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

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

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

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

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

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

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

Current answers, sorted alphabetically by language name

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

答:
Cookie

Cookie is still in development, so these may not work!

Factoid: Cookie's name is inspired by @Dennis Jelly, and I wanted to keep with the sweet food thing. However, I forgot browser cookies, and you will be unable to find it on Github easily.

Cookie is stack oriented, and uses Javascript - specifically Node.js

1 byte snippet:

```<code>p
</code>```

Checks if the number is prime, and outputs true or false.

I was really tempted to also add these two snippets:

```<code>c
</code>```

and

```<code>C
</code>```

Both do similar things. s converts a character to a ASCII number, while S does the reverse.

2 byte snippet:

```<code>))
</code>```

Yup, it's a double increment. ) increments the stack value by one.

3 byte snippet

```<code>wJ"
</code>```

Not much here. w starts a write and " closes it, so J is written.

A polite request, please don't ask me why I chose J. :P

Title: Showcase of Languages

Body:
Cookie

Cookie is still in development, so these may not work!

Factoid: Cookie's name is inspired by @Dennis Jelly, and I wanted to keep with the sweet food thing. However, I forgot browser cookies, and you will be unable to find it on Github easily.

Cookie is stack oriented, and uses Javascript - specifically Node.js

1 byte snippet:

p

Checks if the number is prime, and outputs true or false.

I was really tempted to also add these two snippets:

c

and

C

Both do similar things. s converts a character to a ASCII number, while S does the reverse.

2 byte snippet:

))

Yup, it's a double increment. ) increments the stack value by one.

3 byte snippet

wJ"

Not much here. w starts a write and " closes it, so J is written.

A polite request, please don't ask me why I chose J. :P


问:
Recreate a 'Snake' game in a console/terminal

Games are fun

This Code Golf here was so fun I had to make a version for other classic games similar in complexity: Shortest Way of creating a basic Space Invaders Game in Python

This time, however, try to recreate the classic 'Snake' game, in which you start out as a small shape, constantly moving to collecting pieces to increase your score. When you collect a piece, your 'tail' grows, which follows the path you have made. The objective is to last the longest without crashing into your own tail, or into the walls

Qualifications:

You, the characters that make up the tail, the walls, and the pieces you collect should all be different characters

Show a HUD with the score. The score increases by 1 point for each piece you collect

The player loses when they collide with their own tail or the wall

A piece spawns in a random area immediately after a piece is collected, not to mention at the start of the game

Speed of the game doesn't matter, as long as it is consistent

<s>The 'cells' should be 2x1 characters, since the height of block characters is ~twice the width</s> Can be 1x1, because 2x1 is just ugly and I didn't really think of that

The keys for changing the direction should be awsd, left, up, down, right respectively

The starting direction should always be up

You must show the edges of the wall. The score may overlap the wall

Shortest code that meets the above criteria wins. Imaginary Bonus Points for creativity.

答:
Applesoft Basic - 478 (462)

This was my first ever code golf, but it was written back in 1989, and it mostly implements the snake game as requested (but without food, the snakes just continuously grow, and it's actually two players, not one) using only two lines of Applesoft Basic.

There were a number of two-line program contests at the time, such as in Dr. Dobbs journal.  I spent 6 months figuring out how to fit this into two lines which have a limit of 255 characters (and only one branch)

More info at:  http://davesource.com/Projects/SpeedWaller/

The program typed in is exactly two lines:

```<code>1ONSCRN(X,Y)<>7ANDB<>0ANDSCRN(U,V)<>7GOTO2:HOME:GR:X=10:Y=20:U=30:V=Y:I=201:J=202:K=203:M=205:W=215:A=193:S=211:Z=218:O=1:Q=-1:P=49152:COLOR=7:HLIN0,39AT0:HLIN0,39AT39:VLIN0,39AT0:VLIN0,39AT39:VTAB22: ?"WASZ IJKM  "C:ONB=0GOTO2:CALL-678:RUN
2PLOTX,Y:PLOTU,V:B=PEEK(P):G=B<>ZANDB<>W:H=B<>AANDB<>S:O=G*(O*H+(B=S)-(B=A)):L=H*(L*G+(B=Z)-(B=W)):G=B<>IANDB<>M:H=B<>JANDB<>K:Q=G*(Q*H+(B=K)-(B=J)):R=H*(R*G+(B=M)-(B=I)):X=X+O:Y=Y+L:U=U+Q:V=V+R:FORN=1TO99:NEXT:C=C+1:VTAB22:HTAB12:?C:GOTO1
</code>```

The listing when formatted looks like this:

```<code>1 ONSCRN(X,Y)<>7 AND B<>0 AND SCRN(U,V) <> 7 GOTO 2: HOME : GR :
  X=10 : Y=20 : U=30 : V=Y : I=201 : J=202 : K=203 : M=205 : W=215 :
  A=193 : S=211 : Z=218 : O=1 : Q=-1 : P=49152 : COLOR=7 : HLIN 0,39
  AT 0 : HLIN 0,39 AT 39 : VLIN 0,39 AT 0 : VLIN 0,39 AT 39 : VTAB 22 :
  ? "WASZ IJKM  "C : ON B=0 GOTO 2 : CALL -678 : RUN
2 PLOT X,Y : PLOT U,V : B=PEEK(P) : G= B<>Z AND B<>W: H=B<>A AND B<>S :
  O=G*(O*H+(B=S)-(B=A)) : L=H*(L*G+(B=Z)-(B=W)) : G=B<>I AND B<>M :
  H=B<>J AND B<>K : Q=G*(Q*H+(B=K)-(B=J)) : R=H*(R*G+(B=M)-(B=I)) :
  X=X+O : Y=Y+L : U=U+Q : V=V+R : FOR N=1 TO 99 : NEXT : C=C+1 :
  VTAB 22 : HTAB 12 : ? C : GOTO 1
</code>```

The game is actually two players and includes "instructions" at the bottom of the page showing the keys as well as a counter so you can see how many steps you survived.  It's 478 characters, 16 of those are the instructions and counter output, so 462 if you want to shave those off.

Body:
Applesoft Basic - 478 (462)

This was my first ever code golf, but it was written back in 1989, and it mostly implements the snake game as requested (but without food, the snakes just continuously grow, and it's actually two players, not one) using only two lines of Applesoft Basic.

There were a number of two-line program contests at the time, such as in Dr. Dobbs journal.  I spent 6 months figuring out how to fit this into two lines which have a limit of 255 characters (and only one branch)

More info at:  http://davesource.com/Projects/SpeedWaller/

The program typed in is exactly two lines:

1ONSCRN(X,Y)<>7ANDB<>0ANDSCRN(U,V)<>7GOTO2:HOME:GR:X=10:Y=20:U=30:V=Y:I=201:J=202:K=203:M=205:W=215:A=193:S=211:Z=218:O=1:Q=-1:P=49152:COLOR=7:HLIN0,39AT0:HLIN0,39AT39:VLIN0,39AT0:VLIN0,39AT39:VTAB22: ?"WASZ IJKM  "C:ONB=0GOTO2:CALL-678:RUN
2PLOTX,Y:PLOTU,V:B=PEEK(P):G=B<>ZANDB<>W:H=B<>AANDB<>S:O=G*(O*H+(B=S)-(B=A)):L=H*(L*G+(B=Z)-(B=W)):G=B<>IANDB<>M:H=B<>JANDB<>K:Q=G*(Q*H+(B=K)-(B=J)):R=H*(R*G+(B=M)-(B=I)):X=X+O:Y=Y+L:U=U+Q:V=V+R:FORN=1TO99:NEXT:C=C+1:VTAB22:HTAB12:?C:GOTO1

The listing when formatted looks like this:

1 ONSCRN(X,Y)<>7 AND B<>0 AND SCRN(U,V) <> 7 GOTO 2: HOME : GR :
  X=10 : Y=20 : U=30 : V=Y : I=201 : J=202 : K=203 : M=205 : W=215 :
  A=193 : S=211 : Z=218 : O=1 : Q=-1 : P=49152 : COLOR=7 : HLIN 0,39
  AT 0 : HLIN 0,39 AT 39 : VLIN 0,39 AT 0 : VLIN 0,39 AT 39 : VTAB 22 :
  ? "WASZ IJKM  "C : ON B=0 GOTO 2 : CALL -678 : RUN
2 PLOT X,Y : PLOT U,V : B=PEEK(P) : G= B<>Z AND B<>W: H=B<>A AND B<>S :
  O=G*(O*H+(B=S)-(B=A)) : L=H*(L*G+(B=Z)-(B=W)) : G=B<>I AND B<>M :
  H=B<>J AND B<>K : Q=G*(Q*H+(B=K)-(B=J)) : R=H*(R*G+(B=M)-(B=I)) :
  X=X+O : Y=Y+L : U=U+Q : V=V+R : FOR N=1 TO 99 : NEXT : C=C+1 :
  VTAB 22 : HTAB 12 : ? C : GOTO 1

The game is actually two players and includes "instructions" at the bottom of the page showing the keys as well as a counter so you can see how many steps you survived.  It's 478 characters, 16 of those are the instructions and counter output, so 462 if you want to shave those off.


答:
VBScript, 57 bytes

I used to have lots of fun creating tiny programs in VBScript, back in 2010.

I've remembered this language and used the code on: https://stackoverflow.com/a/13401872/2729937

It still works on Windows 7, at least.

```<code>set S=CreateObject("WScript.Shell")
S.run("www.ppcg.ga")
</code>```

This is a bit different from the usual start www.ppcg.lol, in the sense that it executes the www.ppcg.ga directly, with an implicit start.

An alternative way would be "cmd.exe /C start www.ppcg.ga".

Body:
Your job is to open a browser window of the default browser to http://codegolf.stackexchange.com.

Your code must open the browser itself, and cannot rely on an open one.

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

Moderator note: A large number of answers to this challenge use the URLs http://ppcg.lol or http://ppcg.ga. These URLs did direct to https://codegolf.stackexchange.com at the time, but have since expired. By this meta discussion, they have been allowed to stay, with the note that they are currently invalid.

Body:
VBScript, 57 bytes

I used to have lots of fun creating tiny programs in VBScript, back in 2010.

I've remembered this language and used the code on: https://stackoverflow.com/a/13401872/2729937

It still works on Windows 7, at least.

set S=CreateObject("WScript.Shell")
S.run("www.ppcg.ga")

This is a bit different from the usual start www.ppcg.lol, in the sense that it executes the www.ppcg.ga directly, with an implicit start.

An alternative way would be "cmd.exe /C start www.ppcg.ga".


答:
Rebol 2,  16 15  bytes

```<code>browse"ppcg.ga"
</code>```

if you accept an error before opening the page on Linux, no error on Windows

20 bytes  without an error

```<code>browse http:ppcg.lol
</code>```

Body:
Rebol 2,  16 15  bytes

browse"ppcg.ga"

if you accept an error before opening the page on Linux, no error on Windows

20 bytes  without an error

browse http:ppcg.lol


答:
JavaScript (ES6), 143

There are 2 newline inside the backticks that are significant and counted.

n=>`  _
`+(r=n=>n?[...r(n-1),n,...r(n-1)]:[])(n).map((x,i,t,u=n=>'|'+'_'.repeat(n>0&&n))=>String.fromCharCode(x+64)+u(x)+u(t[i+1]-x-1)).join`
`
```

<p>... or 138 if the letters can be lowercase.</p>

<pre class="lang-js prettyprint-override"><code>n=>`  _
`+(r=n=>n?[...r(n-1),n,...r(n-1)]:[])(n).map((x,i,t,u=n=>'|'+'_'.repeat(n>0&&n))=>(x+9).toString(36)+u(x)+u(t[i+1]-x-1)).join`
</code>```

Less golfed

n=>{
  // recursive function for ABACABA returning an array of integers
  var r=n=>n?[...r(n-1),n,...r(n-1)]:[]
  // function to build "|__..."
  // if argument <=0 just returns the vertical bar
  var u=n=>'|'+'_'.repeat(n>0&&n)
  var t = r(n)
  t = t.map((x,i)=>
    // current building + extension to the len of next building if needed
    String.fromCharCode(x+64)+u(x)+u(t[i+1]-x-1)
  )
  return ' _\n' // the top line is fixed
    + t.join('\n')
}
```

<p><strong>Test</strong></p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>solution=
n=>`  _
`+(r=n=>n?[...r(n-1),n,...r(n-1)]:[])(n).map((x,i,t,u=n=>'|'+'_'.repeat(n>0&&n))=>String.fromCharCode(x+64)+u(x)+u(t[i+1]-x-1)).join`
`

function update() {
  var n=+N.value
  if (n>=0 && n<=26) O.textContent=solution(n)
}

update()</code>```

#N { width: 2em }```
<pre class="snippet-code-html lang-html prettyprint-override"><code>N:<input id=N value=4 oninput='update()'><pre id=O>``````

Title: Create an ABACABA city

Body:
Here is the 3rd ABACABA city:

```<code>  _
A|_|
B|__|
A|_|_
C|___|
A|_|
B|__|
A|_|
</code>```

It is made out of the ABACABA sequence, which is basically:

A (1st iteration)

place B - AB

repeat A - ABA (2nd iteration)

Place C - ABAC

Repeat ABA - ABACABA (3rd iteration)

and you get the idea.

The buildings have a height (corresponded by no. of underscores) equal to the letters converted to numbers as A = 1, B = 2 e.t.c.

Input

An iteration number 1<=n<=26.

Output

The ABACABA city of order n, including the letters at the start of the lines.

Body:
JavaScript (ES6), 143

There are 2 newline inside the backticks that are significant and counted.

n=>`  _
`+(r=n=>n?[...r(n-1),n,...r(n-1)]:[])(n).map((x,i,t,u=n=>'|'+'_'.repeat(n>0&&n))=>String.fromCharCode(x+64)+u(x)+u(t[i+1]-x-1)).join`
`

... or 138 if the letters can be lowercase.

n=>`  _
`+(r=n=>n?[...r(n-1),n,...r(n-1)]:[])(n).map((x,i,t,u=n=>'|'+'_'.repeat(n>0&&n))=>(x+9).toString(36)+u(x)+u(t[i+1]-x-1)).join`

Less golfed

n=>{
  // recursive function for ABACABA returning an array of integers
  var r=n=>n?[...r(n-1),n,...r(n-1)]:[]
  // function to build "|__..."
  // if argument <=0 just returns the vertical bar
  var u=n=>'|'+'_'.repeat(n>0&&n)
  var t = r(n)
  t = t.map((x,i)=>
    // current building + extension to the len of next building if needed
    String.fromCharCode(x+64)+u(x)+u(t[i+1]-x-1)
  )
  return ' _\n' // the top line is fixed
    + t.join('\n')
}

Test

solution=
n=>`  _
`+(r=n=>n?[...r(n-1),n,...r(n-1)]:[])(n).map((x,i,t,u=n=>'|'+'_'.repeat(n>0&&n))=>String.fromCharCode(x+64)+u(x)+u(t[i+1]-x-1)).join`
`

function update() {
  var n=+N.value
  if (n>=0 && n<=26) O.textContent=solution(n)
}

update()

#N { width: 2em }

N:<input id=N value=4 oninput='update()'><pre id=O></pre>


答:
JavaScript (ES6), 257 bytes

```<code>s=>(t=` minutes`,a=s.match(/(\d+):(\d+) (.)/),h=+a[1]+"PMCE".search(a[3]),m=420-h*60-a[2],`It is ${h}:${a[2]} PM PDT
${h<6?m-60+t+` until the pre-show`:h<7?`Pre-show started ${60-m+t} ago; UNCOVERED is starting in ${m+t}`:`UNCOVERED started ${-m+t} ago`}!`)
</code>```

Title: Final Fantasy XV UNCOVERED!

Body:
JavaScript (ES6), 257 bytes

s=>(t=` minutes`,a=s.match(/(\d+):(\d+) (.)/),h=+a[1]+"PMCE".search(a[3]),m=420-h*60-a[2],`It is ${h}:${a[2]} PM PDT
${h<6?m-60+t+` until the pre-show`:h<7?`Pre-show started ${60-m+t} ago; UNCOVERED is starting in ${m+t}`:`UNCOVERED started ${-m+t} ago`}!`)


答:
C, 333 bytes

```<code>#define p printf
char s[9];main(t){gets(s);s[5]=0;s[1]-=2+s[6]%2-s[6]%3;s[1]<48&&(s[1]+=10,--*s);
t=*s*600+s[1]*60+s[3]*10+s[4]-32568;p("It is %s PM PDT.",s);
t<0?p("%d minutes until the pre-show!",-t):t<60?p(
"Pre-show started %d minutes ago; UNCOVERED is starting in %d minutes!",t,60-t):
p("UNCOVERED started %d minutes ago!",t-60);}
</code>```

333 bytes after removing the unnecessary newlines (all but the one after the #define).

Title: Final Fantasy XV UNCOVERED!

Body:
C, 333 bytes

#define p printf
char s[9];main(t){gets(s);s[5]=0;s[1]-=2+s[6]%2-s[6]%3;s[1]<48&&(s[1]+=10,--*s);
t=*s*600+s[1]*60+s[3]*10+s[4]-32568;p("It is %s PM PDT.",s);
t<0?p("%d minutes until the pre-show!",-t):t<60?p(
"Pre-show started %d minutes ago; UNCOVERED is starting in %d minutes!",t,60-t):
p("UNCOVERED started %d minutes ago!",t-60);}

333 bytes after removing the unnecessary newlines (all but the one after the #define).


答:
PHP (OSX), 33 bytes

```<code><?php exec("open http:ppcg.lol");
</code>```

PHP (Windows), 34 bytes

```<code><?php exec("start http:ppcg.lol");
</code>```

Body:
PHP (OSX), 33 bytes

<?php exec("open http:ppcg.lol");

PHP (Windows), 34 bytes

<?php exec("start http:ppcg.lol");


答:
Labyrinth, 10 bytes - 25 = -15

Another Labyrinth collaboration with Sp3000.

```<code>?02
`\
~"@
</code>```

This prints 10n linefeeds to STDOUT.

Try it online!

Explanation

The most interesting part is probably how the default value of 2 is handled.

If an input number is given, the following code is executed:

```<code>?   Read integer from STDIN.
0   Multiply by 10. This is because digits in Labyrinth work by multiplying the top of
    the stack by 10 and then adding themselves, such that multi-digit numbers can be
    written into the code more easily.
    The top of the stack is now positive (and contains the number of characters to be
    printed) so the instruction pointer (IP) turns right/south towards the \.
</code>```

If no input number is given, ? pushes a 0 instead, and this happens:

```<code>?   Push 0.
0   Multiply by 10, which is still 0. Since the top of the stack is now 0, the IP
    keeps moving forward/east instead.
2   Multiply by 10, add 2, which sets the top of the stack to 2. The IP hits a
    dead end so it turns around.
0   Multiply by 10 to give 20. Now the top of the stack is positive and IP
    turns left/south towards the \. Again, the top of the stack is the number
    of characters to be printed.
</code>```

Now all we need to do is print one character each while decrementing the top of the stack to zero. The cheapest character to be printed in Labyrinth is a linefeed, because \ prints one without affecting the stack at all. As an additional trick, we decrement via multiply by -1, bitwise NOT, to ensure that the top of the stack is negative in the top left corner of the loop (otherwise the IP would move towards the ? again).

The loop is then simply:

```<code>\   Print linefeed.
`   Multiply by -1.
~   Bitwise NOT.
"   No-op. This cell acts a junction. While the top of the stack is positive
    the IP will turn left/north, otherwise it will move forward/east.
</code>```

When the IP leaves the loop it hits the @ which terminates the program.

For completeness, here are also two 7-byte versions without the bonus:

```<code>7:(
@`!
</code>```

prints

```<code>-7-6-5-4-3-2-1
</code>```

Try it online!

And

```<code>>11!:
@
</code>```

prints

```<code>11001011111011
</code>```

Try it online!

The former is a very simply (but compact) loop which prints -n while decrementing n from 7 down to 0.

The latter is a simple modification of Sp3000's solution to this challenge (which makes the execution a little bit crazier though).

Title: Create output twice the length of the code

Body:
The Challenge

Write a complete program that writes twice as many bytes to standard output as the length of the program.

Rules

The program must write ASCII characters to the standard output.

The contents of the output doesn't matter.

The output, measured in bytes, must be exactly twice the length of the program, also measured in bytes, unless you fulfill the bonus.

Any trailing newline is included in the output's byte count.

Bonus

Your program can optionally take a number, n, as input. If so, the output must be exactly n * program length bytes. You can assume that n will always be a positive integer. If no input is provided, n must default to 2.

If you do this,  you can subtract 25 bytes from your score.

Shortest program wins.

Restrictions

No standard loopholes.

The program must be at least 1 byte long.

No adding unnecessary whitespace to the source code to change its length. Similarly, comments don't count.

Unless you fulfill the bonus, the program must accept no input. If you do fulfill the bonus, the integer must be the only input.

Lowest score (program length in bytes - bonus) wins.

The shortest answer for each language wins for that language.

Leaderboards

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

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

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

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

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

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

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

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

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

var QUESTION_ID=59436,OVERRIDE_USER=41505;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\-?\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\-?\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Body:
Labyrinth, 10 bytes - 25 = -15

Another Labyrinth collaboration with Sp3000.

?02
`\
~"@

This prints 10n linefeeds to STDOUT.

Try it online!

Explanation

The most interesting part is probably how the default value of 2 is handled.

If an input number is given, the following code is executed:

?   Read integer from STDIN.
0   Multiply by 10. This is because digits in Labyrinth work by multiplying the top of
    the stack by 10 and then adding themselves, such that multi-digit numbers can be
    written into the code more easily.
    The top of the stack is now positive (and contains the number of characters to be
    printed) so the instruction pointer (IP) turns right/south towards the \.

If no input number is given, ? pushes a 0 instead, and this happens:

?   Push 0.
0   Multiply by 10, which is still 0. Since the top of the stack is now 0, the IP
    keeps moving forward/east instead.
2   Multiply by 10, add 2, which sets the top of the stack to 2. The IP hits a
    dead end so it turns around.
0   Multiply by 10 to give 20. Now the top of the stack is positive and IP
    turns left/south towards the \. Again, the top of the stack is the number
    of characters to be printed.

Now all we need to do is print one character each while decrementing the top of the stack to zero. The cheapest character to be printed in Labyrinth is a linefeed, because \ prints one without affecting the stack at all. As an additional trick, we decrement via multiply by -1, bitwise NOT, to ensure that the top of the stack is negative in the top left corner of the loop (otherwise the IP would move towards the ? again).

The loop is then simply:

\   Print linefeed.
`   Multiply by -1.
~   Bitwise NOT.
"   No-op. This cell acts a junction. While the top of the stack is positive
    the IP will turn left/north, otherwise it will move forward/east.

When the IP leaves the loop it hits the @ which terminates the program.

For completeness, here are also two 7-byte versions without the bonus:

7:(
@`!

prints

-7-6-5-4-3-2-1

Try it online!

And

>11!:
@

prints

11001011111011

Try it online!

The former is a very simply (but compact) loop which prints -n while decrementing n from 7 down to 0.

The latter is a simple modification of Sp3000's solution to this challenge (which makes the execution a little bit crazier though).


答:
R, 28 bytes

```<code>browseURL("http://ppcg.lol")
</code>```

(in utils package)

Body:
R, 28 bytes

browseURL("http://ppcg.lol")

(in utils package)


问:
Identify arborally satisfied point sets
An arborally satisfied point set is a 2D set of points such that, for any axis-aligned rectangle that can be formed using two points in the set as opposite corners, that rectangle contains or touches at least one other point.  Here is an equivalent definition from Wikipedia:

A point set is said to be arborally satisfied if the following property holds: for any pair of points that do not both lie on the same horizontal or vertical line, there exists a third point which lies in the rectangle spanned by the first two points (either inside or on the boundary).

The following image illustrates how the rectangles are formed.  This point set is NOT arborally satisfied because this rectangle needs to contain at least one more point.

In ASCII art, this point set can be represented as:

```<code>......
....O.
......
.O....
......
</code>```

A slight modification can make this arborally satisfied:

```<code>......
....O.
......
.O..O.
......
</code>```

Above, you can see that all rectangles (of which there is only one) contain at least three points.

Here is another example of a more complex point set that is arborally satisfied:

For any rectangle that can be drawn spanning two points, that rectangle contains at least one other point.

The Challenge

Given a rectangular grid of points (which I represent with O) and empty space (which I represent with .), output a truthy value if it is arborally satisfied, or a falsey value if it is not.  This is code-golf.

Additional rules:

You can choose to have the characters O and . swapped out with any other pair of printable ASCII characters.  Simply specify which character mapping your program uses.

The grid will always be rectangular.  A trailing newline is allowable.

More Examples

Arborally satisfied:

```<code>.OOO.
OO...
.O.OO
.O..O
....O

..O..
OOOO.
...O.
.O.O.
...OO

O.O.
..O.
OOOO
.O.O
OO..

...
...
...

...
..O
...

O.....
O.O..O
.....O

OOO.OO
</code>```

Not Arborally Satisfied:

```<code>..O..
O....
...O.
.O...
....O

..O..
O.OO.
...O.
.O.O.
...OO

O.....
..O...
.....O
</code>```

答:
C, 289 bytes

```<code>a[99][99],x,X,y,Y,z,Z,i,c;main(k){for(;x=getchar(),x+1;x-10||(y=0,i++))a[y++][i]=x;for(;X<i;X++)for(x=0;a[x][X]-10;x++)for(Y=X+1;Y<i;Y++)for(y=0;a[y][Y]-10;y++)if(x-y&&!(a[x][X]-79||a[y][Y]-79)){c=0;for(Z=X;Z<=Y;Z++)for(z=x<y?x:y;z<=(x>y?x:y);)a[z++][Z]-79||c++;c-2||(k=0);}putchar(k+48);}
</code>```

Requires trailing newline, which is permitted (without the newline, the code would be two bytes larger). Outputs 0 (not arborally satisfied) or 1 (arborally satisfied).

Title: Identify arborally satisfied point sets

Body:
C, 289 bytes

a[99][99],x,X,y,Y,z,Z,i,c;main(k){for(;x=getchar(),x+1;x-10||(y=0,i++))a[y++][i]=x;for(;X<i;X++)for(x=0;a[x][X]-10;x++)for(Y=X+1;Y<i;Y++)for(y=0;a[y][Y]-10;y++)if(x-y&&!(a[x][X]-79||a[y][Y]-79)){c=0;for(Z=X;Z<=Y;Z++)for(z=x<y?x:y;z<=(x>y?x:y);)a[z++][Z]-79||c++;c-2||(k=0);}putchar(k+48);}

Requires trailing newline, which is permitted (without the newline, the code would be two bytes larger). Outputs 0 (not arborally satisfied) or 1 (arborally satisfied).


答:
Fortran, 263 251 247 235 234 216 bytes

1D version (similar to the one by Don Muesli):

```<code>#define R read(*,'(a)',advance='no',eor=1)c
#define F(x)R;if(c/='#')a(x+i)=c
program t
character::a(64)='?',c
integer::k(4)=[8,-8,1,-1],i=57
do
F(-8)
F(8)
F(1)
F(-1)
R
i=i+k(index('snew',c))
enddo
1 print'(8a)',a
end
</code>```

2D version:

```<code>#define R read(*,'(a)',advance='no',eor=1)c
#define F(x,y)R;if(c/='#')a(x+m,y+l)=c
#define G(x,y)j=index(x,c);if(j==2)j=-1;y=y+j
program t
character::a(8,8)='?',c
l=8;m=1
do
F(,-1)
F(,1)
F(1,)
F(-1,)
R
G('sn',l)
G('ew',m)
enddo
1 print'(8a)',a
end
</code>```

To enable free form and pre-processing, the file needs the extension .F90, e.g. explorer.F90. The input is read from STDIN:

```<code>echo "~#~#e~#~~e~#~~e.#~~e^#~~n.~..n~^~.n~.~~n.~~.n.~~*n~.~.n#.~~w#.~~w#.~~s~*..s..*.s*~.~s.~~~s" | ./a.out
?~~~~~??
?....~??
?.**.~??
?~..~~??
?~~~~~??
??~..~??
~~~.^.??
~~~~~~??
</code>```

Title: A Tiny Explorer

Body:
You are an explorer, mapping an unknown world. Your ship is carried on the wind. Where it goes, who knows?

Each day, in your spyglass, you see features to the north, south, east and west. You always see four such features, corresponding to the cardinal directions. Your spyglass reports ASCII symbols like this:

~~.*, ~~~~, ~.^^, ~#~#

The symbols are in the order (north, south, east, west).

These are the symbols: ~ = sea, . = coast, ^ = mountain, * = tree, # = invalid (no observation, this occurs whenever you see the edge of the world, or the landscape is obscured by fog). Your spyglass sees exactly one unit in every direction.

Each night, you look up at the stars to see how far you've travelled. Looking at the stars reports an ascii symbol like this:

n, s, e, w

corresponding to North, South, East and West, respectively. You always move exactly one unit to the north, south, east or west every night. So you, as explorer will be receiving an endless stream of symbols:

~~.*n~~~~s~~.*s~.**

Your task is to output a 2D map of the world (where ? are unknown parts of the map, north is up, east is right):

```<code>?~~~??????
?~~~??????
?~~~.^^.??
?~~.***.~~
~~.*^^*.~~
~~~..~~~~~
~~~~~~~~~~
~~~~~~~~~~
</code>```

For the sake of simplicity let's assume you start in the bottom left corner of the map. Assume all maps are 8x8.

Here is a simple 3x3 example. Assume the map looks like this:

```<code>~.~
~^~
~.~
</code>```

With the following input: ~#.#n~~^#s

You will get this output:

```<code>~??
~^?
~.?
</code>```

More example inputs and outputs:

input
~#~#n~~~#n~~~#n~~~#n~~~#n~~.#n~~.#n#~~#e#.~~e#.~~e#.~~e#.~~e#~~~e#~~~e#~#~s~~#~s~~#~s~~#~s~~#.s~~#~s~~#~s~##~w~#~~w.#~~w^#~~w.#~~

output

```<code>~~~~~~~~
~....~~~
~.????~~
~~????~~
~~????.~
~~????~~
~~?.^.~~
~~~~~~~~
</code>```

Input:

~#~#e~#~~e~#~~e.#~~e^#~~n.~..n~^~.n~.~~n.~~.n.~~*n~.~.n#.~~w#.~~w#.~~s~*..s..*.s*~.~s.~~~s

Output:

```<code>?~~~~~??
?....~??
?.**.~??
?~..~~??
?~~~~~??
?~~..~??
~~~.^.??
~~~~~~??
</code>```

Body:
Fortran, 263 251 247 235 234 216 bytes

1D version (similar to the one by Don Muesli):

#define R read(*,'(a)',advance='no',eor=1)c
#define F(x)R;if(c/='#')a(x+i)=c
program t
character::a(64)='?',c
integer::k(4)=[8,-8,1,-1],i=57
do
F(-8)
F(8)
F(1)
F(-1)
R
i=i+k(index('snew',c))
enddo
1 print'(8a)',a
end

2D version:

#define R read(*,'(a)',advance='no',eor=1)c
#define F(x,y)R;if(c/='#')a(x+m,y+l)=c
#define G(x,y)j=index(x,c);if(j==2)j=-1;y=y+j
program t
character::a(8,8)='?',c
l=8;m=1
do
F(,-1)
F(,1)
F(1,)
F(-1,)
R
G('sn',l)
G('ew',m)
enddo
1 print'(8a)',a
end

To enable free form and pre-processing, the file needs the extension .F90, e.g. explorer.F90. The input is read from STDIN:

echo "~#~#e~#~~e~#~~e.#~~e^#~~n.~..n~^~.n~.~~n.~~.n.~~*n~.~.n#.~~w#.~~w#.~~s~*..s..*.s*~.~s.~~~s" | ./a.out
?~~~~~??
?....~??
?.**.~??
?~..~~??
?~~~~~??
??~..~??
~~~.^.??
~~~~~~??


答:
Hexagony, 6 bytes

```<code>o!!!!@
</code>```

Prints

```<code>111111111111
</code>```

Try it online!

Explanation

Probably one of the simplest Hexagony programs I've written. The unfolded code is

```<code> o !
! ! !
 @ .
</code>```

and is simply executed in reading order. o sets the current memory edge to 111 (any letter from d to z would do). Then the ! print that four times and @ terminates the program.

I might try for the bonus later, but I have some doubts that it will fit in side-length 4 (and side-length 5 might end up costing more than the bonus gives).

Body:
Hexagony, 6 bytes

o!!!!@

Prints

111111111111

Try it online!

Explanation

Probably one of the simplest Hexagony programs I've written. The unfolded code is

 o !
! ! !
 @ .

and is simply executed in reading order. o sets the current memory edge to 111 (any letter from d to z would do). Then the ! print that four times and @ terminates the program.

I might try for the bonus later, but I have some doubts that it will fit in side-length 4 (and side-length 5 might end up costing more than the bonus gives).


答:
Brian & Chuck, 9 bytes

```<code>{?
#.{-?
</code>```

Try it online! There's a single unprintable \x12 (code point 18) before the first { which gets decremented each iteration, giving an output of 18 ?s.

Body:
Brian & Chuck, 9 bytes

{?
#.{-?

Try it online! There's a single unprintable \x12 (code point 18) before the first { which gets decremented each iteration, giving an output of 18 ?s.


Title: Tic-tac-toe with only crosses as quick as possible

Body:
As per Luke's request and Peter Taylor's addition to this challenge.

Introduction

Everyone knows the game tic-tac-toe, but in this challenge, we are going to introduce a little twist. We are only going to use crosses. The first person who places three crosses in a row loses. An interesting fact is that the maximum amount of crosses before someone loses, is equal to 6:

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

That means that for a 3 x 3 board, the maximum amount is 6. So for N = 3, we need to output 6.

Another example, for N = 4, or a 4 x 4 board:

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

This is an optimal solution, you can see that the maximum amount of crosses is equal to 9. An optimal solution for a 12 x 12 board is:

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

This results in 74.

The task

Your task is to compute the results as fast as possible. I will run your code on the test case 13. This will be done 5 times and then the average is taken of the run times. That is your final score. The lower, the better.

Test cases

```<code>N     Output
1       1
2       4
3       6
4       9
5       16
6       20
7       26
8       36
9       42
10      52
11      64
12      74
13      86
14      100
15      114
</code>```

More information can be found at https://oeis.org/A181018.

Rules

This is fastest-code, so the fastest submission wins!

You must provide a full program.

Please also provide how I have to run the program. I am not familiar with all programming languages and how they work, so I need a little bit of help here.

Of course, your code needs to compute the correct result for each test case.

Submissions:

feersum (C++11): 28s

Peter Taylor (Java): 14m 31s

Body:
C++11, 28s

This also uses a dynamic programming approach based on rows. It took 28 seconds to run with argument 13 for me. My favorite trick is the next function which uses some bit bashing for finding the lexicographically next row arrangement satisfying a mask and the no-3-in-a-row rule.

Instructions

Install the latest MinGW-w64 with SEH and Posix threads

Compile the program with g++ -std=c++11 -march=native -O3 <filename>.cpp -o <executable name>

Run with <executable name> <n>

#include <vector>
#include <stddef.h>
#include <iostream>
#include <string>

#ifdef _MSC_VER
#include <intrin.h>
#define popcount32 _mm_popcnt_u32
#else
#define popcount32 __builtin_popcount
#endif

using std::vector;

using row = uint32_t;
using xcount = uint8_t;

uint16_t rev16(uint16_t x) { // slow
    static const uint8_t revbyte[] {0,128,64,192,32,160,96,224,16,144,80,208,48,176,112,240,8,136,72,200,40,168,104,232,24,152,88,216,56,184,120,248,4,132,68,196,36,164,100,228,20,148,84,212,52,180,116,244,12,140,76,204,44,172,108,236,28,156,92,220,60,188,124,252,2,130,66,194,34,162,98,226,18,146,82,210,50,178,114,242,10,138,74,202,42,170,106,234,26,154,90,218,58,186,122,250,6,134,70,198,38,166,102,230,22,150,86,214,54,182,118,246,14,142,78,206,46,174,110,238,30,158,94,222,62,190,126,254,1,129,65,193,33,161,97,225,17,145,81,209,49,177,113,241,9,137,73,201,41,169,105,233,25,153,89,217,57,185,121,249,5,133,69,197,37,165,101,229,21,149,85,213,53,181,117,245,13,141,77,205,45,173,109,237,29,157,93,221,61,189,125,253,3,131,67,195,35,163,99,227,19,147,83,211,51,179,115,243,11,139,75,203,43,171,107,235,27,155,91,219,59,187,123,251,7,135,71,199,39,167,103,231,23,151,87,215,55,183,119,247,15,143,79,207,47,175,111,239,31,159,95,223,63,191,127,255};
    return uint16_t(revbyte[x >> 8]) | uint16_t(revbyte[x & 0xFF]) << 8;
}

// returns the next number after r that does not overlap the mask or have three 1's in a row
row next(row r, uint32_t m) {
    m |= r >> 1 & r >> 2;
    uint32_t x = (r | m) + 1;
    uint32_t carry = x & -x;
    return (r | carry) & -carry;
}

template<typename T, typename U> void maxequals(T& m, U v) {
    if (v > m)
        m = v;
}

struct tictac {
    const int n;
    vector<row> rows;
    size_t nonpal, nrows_c;
    vector<int> irow;
    vector<row> revrows;

    tictac(int n) : n(n) { }

    row reverse(row r) {
        return rev16(r) >> (16 - n);
    }

    vector<int> sols_1row() {
        vector<int> v(1 << n);
        for (uint32_t m = 0; !(m >> n); m++) {
            auto m2 = m;
            int n0 = 0;
            int score = 0;
            for (int i = n; i--; m2 >>= 1) {
                if (m2 & 1) {
                    n0 = 0;
                } else {
                    if (++n0 % 3)
                        score++;
                }
            }
            v[m] = score;
        }
        return v;
    }

    void gen_rows() {
        vector<row> pals;
        for (row r = 0; !(r >> n); r = next(r, 0)) {
            row rrev = reverse(r);
            if (r < rrev) {
                rows.push_back(r);
            } else if (r == rrev) {
                pals.push_back(r);
            }
        }
        nonpal = rows.size();
        for (row r : pals) {
            rows.push_back(r);
        }
        nrows_c = rows.size();
        for (int i = 0; i < nonpal; i++) {
            rows.push_back(reverse(rows[i]));
        }
        irow.resize(1 << n);
        for (int i = 0; i < rows.size(); i++) {
            irow[rows[i]] = i;
        }
        revrows.resize(1 << n);
        for (row r = 0; !(r >> n); r++) {
            revrows[r] = reverse(r);
        }
    }

    // find banned locations for 1's given 2 above rows
    uint32_t mask(row a, row b) {
        return ((a & b) | (a >> 1 & b) >> 1 | (a << 1 & b) << 1) /*& ((1 << n) - 1)*/;
    }

    int calc() {
        if (n < 3) {
            return n * n;
        }
        gen_rows();
        int tdim = n < 5 ? n : (n + 3) / 2;
        size_t nrows = rows.size();
        xcount* t = new xcount[2 * nrows * nrows_c]{};
#define tb(nr, i, j) t[nrows * (nrows_c * ((nr) & 1) + (i)) + (j)]

        // find optimal solutions given 2 rows for n x k grids where 3 <= k <= ceil(n/2) + 1

        {
            auto s1 = sols_1row();
            for (int i = 0; i < nrows_c; i++) {
                row a = rows[i];
                for (int j = 0; j < nrows; j++) {
                    row b = rows[j];
                    uint32_t m = mask(b, a) & ~(1 << n);
                    tb(3, i, j) = s1[m] + popcount32(a << 16 | b);
                }
            }
        }
        for (int r = 4; r <= tdim; r++) {
            for (int i = 0; i < nrows_c; i++) {
                row a = rows[i];
                for (int j = 0; j < nrows; j++) {
                    row b = rows[j];
                    bool rev = j >= nrows_c;
                    auto cj = rev ? j - nrows_c : j;
                    uint32_t m = mask(a, b);
                    for (row c = 0; !(c >> n); c = next(c, m)) {
                        row cc = rev ? revrows[c] : c;
                        int count = tb(r - 1, i, j) + popcount32(c);
                        maxequals(tb(r, cj, irow[cc]), count);
                    }
                }
            }
        }
        int ans = 0;
        if (tdim == n) { // small sizes
            for (int i = 0; i < nrows_c; i++) {
                for (int j = 0; j < nrows; j++) {
                    maxequals(ans, tb(n, i, j));
                }
            }
        } else {
            int tdim2 = n + 2 - tdim;
            // get final answer by joining two halves' solutions down the middle
            for (int i = 0; i < nrows_c; i++) {
                int apc = popcount32(rows[i]);
                for (int j = 0; j < nrows; j++) {
                    row b = rows[j];
                    int top = tb(tdim2, i, j);
                    int bottom = j < nrows_c ? tb(tdim, j, i) : tb(tdim, j - nrows_c, i < nonpal ? i + nrows_c : i);
                    maxequals(ans, top + bottom - apc - popcount32(b));
                }
            }
        }
        delete[] t;
        return ans;
    }
};

int main(int argc, char** argv) {
    int n;
    if (argc < 2 || (n = std::stoi(argv[1])) < 0 || n > 16) {
        return 1;
    }
    std::cout << tictac{ n }.calc() << '\n';
    return 0;
}


问:
Chaotic Number Shuffling
You have a deck of cards, consisting of cards with non-negative numbers on them, and you haven't shuffled it yet, and no player trusts the other players to be fair at shuffling. You devise a way to shuffle the deck that is completely deterministic, but chaotic enough that the other players are okay with using it. Here's how you perform a single shuffle:

Start with the deck face down. There are a series of M empty piles (where M is the maximum number in the deck) labeled as the 1st, 2nd, 3rd, ... ,Mth pile, and there is also an empty storage pile.

While the deck is not empty, do the following: Take the first card off the top of the deck, let N be its number and put the card face down on the top of the storage pile. If there are at least N cards left in the deck, deal the top N cards face down such that the top card goes in the 1st pile, the second card from the top goes in the 2nd pile, etc. until the Nth card gets put in the Nth pile. If there are fewer than N cards in the deck, deal all of them.

Construct the new deck by putting the first pile on the storage pile, then the second pile on the new pile, then the third pile on that new pile, then the fourth pile on that one, until all piles are in your deck.

This method is pretty intuitive when doing by hand, but after a few games some players want a computer to do it, due to the deep-seated mistrust within the group and a few lucky draws. They refuse to use other deck shuffling programs that would work better. Write a program that takes as input a list of non-negative integers (in some format you specify) and shuffles it once using this method, outputting the result. You may assume the integers and the length of the list are less than 2^16.

Here are some worked-out examples (layout is deck|storage|1st|2nd|3rd|...|Mth, cards go from bottom to top):

```<code>9,8,7,6,5,4,3,2,1,0|||||||||||
9,8,7,6,5,4,3,2,1|0||||||||||
9,8,7,6,5,4,3|0,1|2|||||||||
9,8,7|0,1,3|2,4|5|6|||||||
|0,1,3,7|2,4,8|5,9|6|||||||
0,1,3,7,2,4,8,5,9,6||||||||||| (starting another iteration)
0,1,3|6|9|5|8|4|2|7||||
|6,3|9,1|5,0|8|4|2|7||||
6,3,9,1,5,0,8,4,2,7|||||||||||
</code>```

Here is a long string of successive shuffles:

```<code>[9,8,7,6,5,4,3,2,1,0]->[0,1,3,7,2,4,8,5,9,6]->[6,3,9,1,5,0,8,4,2,7]->
[7,3,2,6,4,8,0,5,1,9]->[9,1,5,0,8,4,6,2,3,7]->[7,1,3,9,2,6,4,8,0,5]->
[5,9,0,3,8,1,4,7,6,2]->[2,4,9,6,1,5,7,8,3,0]->[0,3,1,9,8,6,4,7,2,5]->
[5,9,2,1,7,3,4,0,6,8]->[8,5,6,0,4,3,7,1,2,9]->[9,2,1,7,3,4,0,6,5,8]
</code>```

Another few:

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

答:
Ruby, 91 bytes

There is probably a better way to create an array of arrays. There's probably a shorter way to do all the shuffling, too. We'll see what future answers and comments bring to the table and all golfing suggestions are welcome.

->d{z=(1..d.size).map{[]};([d[-1]+1,d.size].min.times{|i|z[i]<<d.pop})while d[0];z.flatten}
```

<p><strong>Ungolfing:</strong></p>

<pre class="lang-ruby prettyprint-override"><code>def shuffle(deck)
  # an array of arrays
  z = (1..deck.size).map{[]}

  # while there are still cards in the deck
  while deck[0]
    # if we're almost out of cards, use how many are left
    # else, put in deck[-1] + 1 in the piles (that is, including deck[-1])
    card = [deck[-1] + 1, deck.size].min
    card.times do |i|
      z[i] << deck.pop
    end
  end

  # flatten all of those arrays done and return
  return z.flatten
end
</code>```

Title: Chaotic Number Shuffling

Body:
Ruby, 91 bytes

There is probably a better way to create an array of arrays. There's probably a shorter way to do all the shuffling, too. We'll see what future answers and comments bring to the table and all golfing suggestions are welcome.

->d{z=(1..d.size).map{[]};([d[-1]+1,d.size].min.times{|i|z[i]<<d.pop})while d[0];z.flatten}

Ungolfing:

def shuffle(deck)
  # an array of arrays
  z = (1..deck.size).map{[]}

  # while there are still cards in the deck
  while deck[0]
    # if we're almost out of cards, use how many are left
    # else, put in deck[-1] + 1 in the piles (that is, including deck[-1])
    card = [deck[-1] + 1, deck.size].min
    card.times do |i|
      z[i] << deck.pop
    end
  end

  # flatten all of those arrays done and return
  return z.flatten
end