问:
The Versatile Integer Printer
Write a piece of code that is executable in at least three different languages. The code must output the integer 1 in language number one, 2 in language number two, 3 in language number three etc.

Rules:

The output must be only the integer, but trailing newlines are OK.

The code can't take input of any kind

Different major versions of the same language are considered unique. So, your code can be executable in Python 2 and Python 3, however Python 2.5 and Python 2.7 are not considered unique.

You may use a new language if and only if it has an esolang/wiki article, available interpreter and documentation, and has been used by at least two users on PPCG prior to using it in this challenge. It must also adhere to these 4 rules.

The score of your submission is the number of bytes in your code divided by the number of languages it can run in cubed. So, a 54 byte solution that is executable in 3 languages will have a score of 2:

```<code>54 / 3^3 = 2
</code>```

Lower score is better.

答:
4 languages, 97 bytes, 0.37890625

```<code>s="1";s=~-3;2//2;'''/.to_s.ord;"=;print 4;
__DATA__
=1;
";#'''#";print=s=>console.log(3)
print(s)
</code>```

Ruby

This sets s to "1", compares using =~ against -3 in a void context, tries to divide 2 by /2;'''/.to_s.ord then starts a new string containing =;print 4; __DATA__ =1;, hits a comment, then prints s which is still 1.

Python

Sets s to "1" as per above, then sets it again to ~-3 which is 2. We run an integer division of 2//2, then there's a docstring containing /.to_s.ord;"=;print 4; __DATA__ =1; ";#, followed by a comment, finally printing s, which is still 2.

JavaScript

Sets s to "1" then sets it again to ~-3 as per above, then there's 2 on the line followed by a comment. Then we set the variable __DATA__ to 1. There's a short string containing ;#'''# followed by a definition of the function print which hardcodes the output to be 3, which is called on the next line.

Perl

Runs a substitution equivalent to s/"1";s/~-3;2\/\/2;'''\/.to_s.ord;"/, prints 4 and the rest of the string is masked behind the __DATA__ identifier.

Title: The Versatile Integer Printer

Body:
4 languages, 97 bytes, 0.37890625

s="1";s=~-3;2//2;'''/.to_s.ord;"=;print 4;
__DATA__
=1;
";#'''#";print=s=>console.log(3)
print(s)

Ruby

This sets s to "1", compares using =~ against -3 in a void context, tries to divide 2 by /2;'''/.to_s.ord then starts a new string containing =;print 4; __DATA__ =1;, hits a comment, then prints s which is still 1.

Python

Sets s to "1" as per above, then sets it again to ~-3 which is 2. We run an integer division of 2//2, then there's a docstring containing /.to_s.ord;"=;print 4; __DATA__ =1; ";#, followed by a comment, finally printing s, which is still 2.

JavaScript

Sets s to "1" then sets it again to ~-3 as per above, then there's 2 on the line followed by a comment. Then we set the variable __DATA__ to 1. There's a short string containing ;#'''# followed by a definition of the function print which hardcodes the output to be 3, which is called on the next line.

Perl

Runs a substitution equivalent to s/"1";s/~-3;2\/\/2;'''\/.to_s.ord;"/, prints 4 and the rest of the string is masked behind the __DATA__ identifier.


问:
Count up folks!

Introduction

It may sound strange, but we haven't got ONE challenge for counting from 1 to n, inclusive.

This is not the same thing. That one is a (closed) not well-explained challenge.

This is not the same thing. That one is about counting up indefinitely.

Challenge

Write a program or function that prints every integer from 1 to n inclusive.

Rules

You can get n any way.

You can assume that n will always be a positive integer.

You can get n in any base, but you should always output in decimal.

Output must be separated by any character (or pattern) not in 0123456789. Non-decimal leading or trailing characters are allowed (for example when using arrays such as [1, 2, 3, 4, 5, 6]).

Standard loopholes are denied.

We want to find the shortest approach in each language, not the shortest language, so I will not accept any answer.

You must update your answer(s) after this edit, answers posted before the last edit must comply with the change rule about standard loopholes (I didn't want to deny them, but I didn't want to make the community roar, so I denied them).

You can use any post-dating language version (or language). You cannot use any language or language version made just for this challenge.

Bonuses

20%

Your program must be able to count at least up to 18446744073709551615 (2^64-1). For example, if a new datatype is the only way to support big integers, you must construct it. If your language does not have any way to support huge integers up to 2^64-1, the upper limit of that particular language must be supported instead.

EDIT: I've changed the limit from 2^64 to 2^64-1 to allow more answers.

EDIT: I made the 2^64-1 rule a bonus, since there has not been much interest in this challenge. If your answer supports 2^64-1, you can now edit it to include the bonus. Also, you can post an answer not supporting it, if it is shorter.

答:
Mouse-2002, 47 bytes

```<code>?1(&DUP " "!&DUP &ROT &DUP &ROT =[0^]&SWAP 1+)$
</code>```

I do not know how to replace &DUP &ROT &DUP &ROT ...&SWAP, it's intended to duplicate the two top elements of the stack (...A B → ...B A A B), perform an operation on them, and then restore the stack to what it was before (...A B). Here is the explanation:

? pushes a number (base 10) from input (... → ... <input num>)

1 pushes 1 (... → ... 1)

( starts an infinite loop

&DUP duplicates the ToS (... A → ... A A)

" " prints

! prints the ToS as a number (... A → ...)

&DUP duplicates the ToS (... A → ... A A)

&ROT rotates the top three stack elements (... A B C → ... B C A)

&DUP duplicates the ToS (... A → ... A A)

&ROT rotates the top three stack elements (... A B C → ... B C A)

= checks if the ToS and the SToS are equal

[ skips to the matching ] if the ToS is not positive

0 pushes 0 (... → ... 0)

^ breaks out of the innermost loop if the ToS isn't positive (... A → ...)

&SWAP swaps the top two stack elements (... A B → ... B A)

1 pushes 1 (... → ... 1)

+ adds the top two stack elements (... A B → ... A+B)

) closes the innermost loop

$ terminates the program

ContentLicense: CC BY-SA 3.0

Title: Count up folks!

Body:
Mouse-2002, 47 bytes

?1(&DUP " "!&DUP &ROT &DUP &ROT =[0^]&SWAP 1+)$

I do not know how to replace &DUP &ROT &DUP &ROT ...&SWAP, it's intended to duplicate the two top elements of the stack (...A B → ...B A A B), perform an operation on them, and then restore the stack to what it was before (...A B). Here is the explanation:

? pushes a number (base 10) from input (... → ... <input num>)

1 pushes 1 (... → ... 1)

( starts an infinite loop

&DUP duplicates the ToS (... A → ... A A)

" " prints

! prints the ToS as a number (... A → ...)

&DUP duplicates the ToS (... A → ... A A)

&ROT rotates the top three stack elements (... A B C → ... B C A)

&DUP duplicates the ToS (... A → ... A A)

&ROT rotates the top three stack elements (... A B C → ... B C A)

= checks if the ToS and the SToS are equal

[ skips to the matching ] if the ToS is not positive

0 pushes 0 (... → ... 0)

^ breaks out of the innermost loop if the ToS isn't positive (... A → ...)

&SWAP swaps the top two stack elements (... A B → ... B A)

1 pushes 1 (... → ... 1)

+ adds the top two stack elements (... A B → ... A+B)

) closes the innermost loop

$ terminates the program


答:
Dip, 1 - .2 = .8

```<code>l
</code>```

Body must be at least 30 characters; you entered 13.

Title: Count up folks!

Body:
Introduction

It may sound strange, but we haven't got ONE challenge for counting from 1 to n, inclusive.

This is not the same thing. That one is a (closed) not well-explained challenge.

This is not the same thing. That one is about counting up indefinitely.

Challenge

Write a program or function that prints every integer from 1 to n inclusive.

Rules

You can get n any way.

You can assume that n will always be a positive integer.

You can get n in any base, but you should always output in decimal.

Output must be separated by any character (or pattern) not in 0123456789. Non-decimal leading or trailing characters are allowed (for example when using arrays such as [1, 2, 3, 4, 5, 6]).

Standard loopholes are denied.

We want to find the shortest approach in each language, not the shortest language, so I will not accept any answer.

You must update your answer(s) after this edit, answers posted before the last edit must comply with the change rule about standard loopholes (I didn't want to deny them, but I didn't want to make the community roar, so I denied them).

You can use any post-dating language version (or language). You cannot use any language or language version made just for this challenge.

Bonuses

20%

Your program must be able to count at least up to 18446744073709551615 (2^64-1). For example, if a new datatype is the only way to support big integers, you must construct it. If your language does not have any way to support huge integers up to 2^64-1, the upper limit of that particular language must be supported instead.

EDIT: I've changed the limit from 2^64 to 2^64-1 to allow more answers.

EDIT: I made the 2^64-1 rule a bonus, since there has not been much interest in this challenge. If your answer supports 2^64-1, you can now edit it to include the bonus. Also, you can post an answer not supporting it, if it is shorter.

Body:
Dip, 1 - .2 = .8

l

Body must be at least 30 characters; you entered 13.


问:
Output a googol copies of a string
I am interested in seeing programs which don't ask for any input, print a googol copies of some nonempty string, no less, no more, and then stop. A googol is defined as \$10^{100}\$, i.e., 1 followed by a hundred 0's in decimal.

Example output:

```<code>111111111111111111111111111111111111111111111111111111111111111111111111...
</code>```

or

```<code>Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
...
</code>```

The string can also be entirely composed of white space or special symbols. The only exception to identical copies of a fixed string is if your language decorates the output in some way that can not be prevented, but could be trivially undone in a wrapper script, like prepending a line number to each line. The wrapper script in such cases need not be provided.

You can assume your computer will never run out of time, but other than that, your program must have a reasonable demand of resources. Also, you must respect any restrictions that the programming language of your choice poses, for example, you can not exceed a maximum value allowed for its integer types, and at no point more than 4 GB of memory must be needed.

In other words, the program should in principle be testable by running it on your computer. But because of the extent of this number you will be expected to prove that the number of copies of the string it outputs is exactly 10^100 and that the program stops afterwards. Stopping can be exiting or halting or even terminating due to an error, but if so, the error must not produce any output that could not easily be separated from the program's output.

This is code-golf,  so the solution with the fewest bytes wins.

Example solution (C, ungolfed, 3768 bytes)

```<code>#include <stdio.h>

int main() {
  int a00, a01, a02, a03, ..., a99;
  for(a00 = 0; a00 < 10; a00++)
  for(a01 = 0; a01 < 10; a01++)
  for(a02 = 0; a02 < 10; a02++)
  for(a03 = 0; a03 < 10; a03++)
  ...
  for(a99 = 0; a99 < 10; a99++)
    puts("1");
  return 0;
}
</code>```

答:
Java, 153 bytes

import java.math.*;interface M{static void main(String[]a){for(BigInteger i=BigInteger.ZERO;!i.add(i.ONE).equals(i.TEN.pow(100));)System.out.print(1);}}
```

Output: 1e100 1s

I know there is another Java answer which is also pretty close. Mine's got a main and is still shorter though.

This is my first code-golf entry. Tips appreciated.

ContentLicense: CC BY-SA 4.0

Title: Output a googol copies of a string

Body:
Java, 153 bytes

import java.math.*;interface M{static void main(String[]a){for(BigInteger i=BigInteger.ZERO;!i.add(i.ONE).equals(i.TEN.pow(100));)System.out.print(1);}}

Output: 1e100 1s

I know there is another Java answer which is also pretty close. Mine's got a main and is still shorter though.

This is my first code-golf entry. Tips appreciated.


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

答:
Alphafuck

I'll use upvote * 2 because this language uses pairs

Length 6 snippet

noT INF

This is a infinite loop. Transpiles to -[].

Length 4 snippet

uMhM

Reads a letter and prints it. Transpiles to ,..

This does the same thing: uM hM.

Length 2 snippet

um

Now we're getting into things. This snippet transpiles into Branfuck +, which increments the current memory cell by one.

Length 1 snippet

1

Anything that isn't an letter is ignored. This snippet is basically a comment.

Factoid

Alphafuck is an esolang I made that transpiles to Brainfuck.

Title: Showcase of Languages


问:
Generate a one-path maze
Given an odd integer N (5 <= N <= 51), generate a maze with side length N that follows the following requirements:

The maze must be composed of the characters  | - and +. It must use the | character as a vertical wall, the - character as a horizontal wall, and if that wall turns, the character + should be used.

The width of the path must be one character.

The maze must turn at least four times.

The maze must have outer walls, that break at two points: the start and the end.

The maze must consist of one non-breaking path, from the start to the end.

For example, the following is a valid maze: (N = 5)

```<code>+---+
|   |
| | |
  |
--+--
</code>```

And for N = 7:

```<code>--+---+
  |   |
| | | |
| | | |
| | | |
|   |
+---+--
</code>```

Remember, this is code-golf, so the code with the fewest number of bytes wins.

答:
GNU sed 140 bytes

Includes +1 for -r

```<code>s/1{5}//
h
s/^/+---+\n|   |\n| | |\n  |  \n--+--/
/1/!b
:w
s/^..(..)[^$]*/\1&/gm
s/11//
/1/bw
G
:h
s/\n[^\n]*\n([^\n]*\n)/&\1/
s/1//
/1/bh
</code>```

Try it Online!

Takes input in unary (see this consensus).

Basically it inserts the size 5 maze, then appends the 2nd and 3rd character of each line to the beginning as many times as needed. Then duplicates the 3rd line (alternating | and ) as many times as needed.

The only interesting thing that I used is the m option on line 6 which allows ^ and $ to match respectively (in addition to the normal behavior) the empty string after a newline, and the empty string before a newline.

Title: Generate a one-path maze

Body:
GNU sed 140 bytes

Includes +1 for -r

s/1{5}//
h
s/^/+---+\n|   |\n| | |\n  |  \n--+--/
/1/!b
:w
s/^..(..)[^$]*/\1&/gm
s/11//
/1/bw
G
:h
s/\n[^\n]*\n([^\n]*\n)/&\1/
s/1//
/1/bh

Try it Online!

Takes input in unary (see this consensus).

Basically it inserts the size 5 maze, then appends the 2nd and 3rd character of each line to the beginning as many times as needed. Then duplicates the 3rd line (alternating | and ) as many times as needed.

The only interesting thing that I used is the m option on line 6 which allows ^ and $ to match respectively (in addition to the normal behavior) the empty string after a newline, and the empty string before a newline.


问:
Trick or Treat polyglot
Since Halloween is coming up I thought I might start a fun little code golf challenge!

The challenge is quite simple. You have to write a program that outputs either trick or treat.

"The twist?" you may ask. Well let me explain:

Your program has to do the following:

Be compilable/runnable in two different languages. Different versions of the same language don't count.

When you run the program in one language it should output trick and the other should output treat. The case is irrelevant and padding the string with whitespace characters are allowed (see examples).

This is code-golf,  so the solution with the fewest bytes wins.

A few explanations:

Valid outputs (Just for the words not for running the code in the two languages. Also adding quotes to signalize the beginning or end of the output. Do not include them in your solution!):

```<code>"trick"

"Treat"

"    TReAt"

"
     tRICk          "
</code>```

Invalid outputs:

```<code>"tri ck"

"tr
eat"

"trck"
</code>```

I'm interested to see what you can come up with! Happy Golfing!

I'd like to note that this is my first challenge so if you have suggestions on this question please leave them in the form of a comment.

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=97472,OVERRIDE_USER=23417;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,TAGS_REG = /(<([^>]+)>)/ig;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:400px;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

```

Title: Trick or Treat polyglot

Body:
Scheme / Brainf*ck, 80 bytes

My second attempt.

(print 'trick);++++[>+++++[>+++++<-]<-]>>[>+>+<<-]++++[>++++<-]>.--.>+.----.<++.

What Scheme sees: (print 'trick)

What Brainf*ck sees: ++++[>+++++[>+++++<-]<-]>>[>+>+<<-]++++[>++++<-]>.--.>+.----.<++.

Happy Halloween.


问:
Interlace strings
Your challenge is to write a program or function that, when given two strings of equal length, swaps every other character and outputs/returns the resulting strings in either order.

Examples

```<code>"Hello," "world!" --> "Hollo!" "werld,"
"code" "golf" --> "codf" "gole"
"happy" "angry" --> "hnpry" "aagpy"
"qwerty" "dvorak" --> "qvertk" "dworay"
"1, 2, 3" "a, b, c" --> "1, b, 3" "a, 2, c"
"3.141592653589" "2.718281828459" --> "3.111291623489" "2.748582858559"
"DJMcMayhem" "trichoplax" --> "DrMcMoylex" "tJichapham"
"Doorknob" "Downgoat" --> "Doonkoot" "Dowrgnab"
"Halloween" "Challenge" --> "Hhlloeegn" "Caallwnee"
</code>```

Rules

The strings will only contain ASCII chars (32-126).

The strings will always be the same length, and will never be empty.

You may accept input in any suitable format: separate parameters, items in an array, separated by one or more newlines, even concatenated. The only restriction is that one string must come fully before the other (e.g. a1\nb2\nc3 for "abc", "123" is invalid).

The output may be in either order (i.e. you can start swapping from the first or the second char), and in any valid format mentioned above. (2-item array, separated by newline(s), concatenated, etc.)

Scoring

This is code-golf, so the shortest code in bytes for each language wins.

答:
Vim, <s>18</s>, 17 bytes

```<code>qqyljvPkvPll@qq@q
</code>```

Try it online!

This uses the V interpreter because of backwards compatibility. Input comes in this format:

```<code>string1
string2
</code>```

Explanation:

```<code> qq                 " Start recording in register 'q'
   yl               " Yank one letter
     j              " Move down a row
      vP            " Swap the yanked letter and the letter under the cursor
        k           " Move back up a row
         vP         " Swap the yanked letter and the letter under the cursor
           ll       " Move two letters to the right. This will throw an error once we're done
             @q     " Call macro 'q' recursively
               q    " Stop recording.
                @q  " Start the recursive loop
</code>```

Title: Interlace strings

Body:
Vim, <s>18</s>, 17 bytes

qqyljvPkvPll@qq@q

Try it online!

This uses the V interpreter because of backwards compatibility. Input comes in this format:

string1
string2

Explanation:

 qq                 " Start recording in register 'q'
   yl               " Yank one letter
     j              " Move down a row
      vP            " Swap the yanked letter and the letter under the cursor
        k           " Move back up a row
         vP         " Swap the yanked letter and the letter under the cursor
           ll       " Move two letters to the right. This will throw an error once we're done
             @q     " Call macro 'q' recursively
               q    " Stop recording.
                @q  " Start the recursive loop


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

```<code>øvyNFÀ}})ø
</code>```

Try it online!

Explanation

input = ["code", "golf"] used as example.

```<code>ø             # zip strings into list of pairs
              # STACK: ['cg', 'oo', 'dl', 'ef']
 vy           # for each pair
   NFÀ        # rotate left index times
      }}      # end-if, end-loop
              # STACK: 'cg, 'oo', 'dl', 'fe'
        )ø    # wrap in list and zip
              # OUTPUT: ['codf', 'gole']
</code>```

Title: Interlace strings

Body:
Your challenge is to write a program or function that, when given two strings of equal length, swaps every other character and outputs/returns the resulting strings in either order.

Examples

```<code>"Hello," "world!" --> "Hollo!" "werld,"
"code" "golf" --> "codf" "gole"
"happy" "angry" --> "hnpry" "aagpy"
"qwerty" "dvorak" --> "qvertk" "dworay"
"1, 2, 3" "a, b, c" --> "1, b, 3" "a, 2, c"
"3.141592653589" "2.718281828459" --> "3.111291623489" "2.748582858559"
"DJMcMayhem" "trichoplax" --> "DrMcMoylex" "tJichapham"
"Doorknob" "Downgoat" --> "Doonkoot" "Dowrgnab"
"Halloween" "Challenge" --> "Hhlloeegn" "Caallwnee"
</code>```

Rules

The strings will only contain ASCII chars (32-126).

The strings will always be the same length, and will never be empty.

You may accept input in any suitable format: separate parameters, items in an array, separated by one or more newlines, even concatenated. The only restriction is that one string must come fully before the other (e.g. a1\nb2\nc3 for "abc", "123" is invalid).

The output may be in either order (i.e. you can start swapping from the first or the second char), and in any valid format mentioned above. (2-item array, separated by newline(s), concatenated, etc.)

Scoring

This is code-golf, so the shortest code in bytes for each language wins.

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

øvyNFÀ}})ø

Try it online!

Explanation

input = ["code", "golf"] used as example.

ø             # zip strings into list of pairs
              # STACK: ['cg', 'oo', 'dl', 'ef']
 vy           # for each pair
   NFÀ        # rotate left index times
      }}      # end-if, end-loop
              # STACK: 'cg, 'oo', 'dl', 'fe'
        )ø    # wrap in list and zip
              # OUTPUT: ['codf', 'gole']


答:
Perl, 48 bytes

Bytecount includes 47 bytes of code and -p flag.

say<>=~s%.\K(.)%"s/.{$-[0]}\\K(.)/$1/;\$1"%geer
```
<p>Run with <code>-p</code> and <code>-E</code> flag. Expect each string on a different line :</p>
```perl -pE 'say<>=~s%.\K(.)%"s/.{$-[0]}\\K(.)/$1/;\$1"%geer' <<< "Hello
World"
```

Explanations :

-p : capture input in $_ and prints it at the end. (to get and print the first string)

<> : get a line of input. (to get the second string).

=~ : apply a regex to <> : s%%%geer, where thanks to r the modified string is returned (and then printed thanks to say).

The regex :

.\K(.) finds two characters, and will replace the second one with the result of the evaluation of this code "s/.{$-[0]}\\K(.)/$1/;\$1" :

The first part, s/.{$-[0]}\\K(.)/$1/ applies a regex to $_ : .{$-[0]} skips the first characters to get to the same point as the outer regex (since $-[0] contains the index of the first capture group, so in that case the index of the characters to substitute), and then we capture a char with (.) and replace it with the character of the outer regex ($1). And then we add $1 so the result of "s/.{$-[0]}\\K(.)/$1/;\$1" is the character we captured in the inner regex.

You may have noticed that $1 refer to the character we want to replace in both strings (so two different characters), so we play with /ee modifier of the regex which evaluates the right side of the regex twice : the first one will substitute only the $1 that isn't preceded by the \.

Title: Interlace strings

Body:
Perl, 48 bytes

Bytecount includes 47 bytes of code and -p flag.

say<>=~s%.\K(.)%"s/.{$-[0]}\\K(.)/$1/;\$1"%geer

Run with -p and -E flag. Expect each string on a different line :

perl -pE 'say<>=~s%.\K(.)%"s/.{$-[0]}\\K(.)/$1/;\$1"%geer' <<< "Hello
World"

Explanations :

-p : capture input in $_ and prints it at the end. (to get and print the first string)

<> : get a line of input. (to get the second string).

=~ : apply a regex to <> : s%%%geer, where thanks to r the modified string is returned (and then printed thanks to say).

The regex :

.\K(.) finds two characters, and will replace the second one with the result of the evaluation of this code "s/.{$-[0]}\\K(.)/$1/;\$1" :

The first part, s/.{$-[0]}\\K(.)/$1/ applies a regex to $_ : .{$-[0]} skips the first characters to get to the same point as the outer regex (since $-[0] contains the index of the first capture group, so in that case the index of the characters to substitute), and then we capture a char with (.) and replace it with the character of the outer regex ($1). And then we add $1 so the result of "s/.{$-[0]}\\K(.)/$1/;\$1" is the character we captured in the inner regex.

You may have noticed that $1 refer to the character we want to replace in both strings (so two different characters), so we play with /ee modifier of the regex which evaluates the right side of the regex twice : the first one will substitute only the $1 that isn't preceded by the \.


问:
Add two numbers
Input: Two integers. Preferably decimal integers, but other forms of numbers can be used. These can be given to the code in standard input, as arguments to the program or function, or as a list.

Output: Their sum. Use the same format for output integers as input integers. For example, the input 5 16 would lead to the output 21.

Restrictions: No standard loopholes please. This is code-golf, answer in lowest amount of bytes wins.

Notes: This should be fairly trivial, however I'm interested to see how it can be implemented. The answer can be a complete program or a function, but please identify which one it is.

Test cases:

```<code>1 2 -> 3
14 15 -> 29
7 9 -> 16
-1 8 -> 7
8 -9 -> -1
-8 -9 -> -17
</code>```

Or as CSV:

```<code>a,b,c
1,2,3
14,15,29
7,9,16
-1,8,7
8,-9,-1
-8,-9,-17
</code>```

Leaderboard

var QUESTION_ID=84260,OVERRIDE_USER=8478;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

```

答:
Swift, 1 byte

+

since operator + is defined as function(public func +(lhs: Int, rhs: Int) -> Int)

Title: Add two numbers


答:
Java, 91 bytes

```<code>interface M{static void main(String[]a){System.out.print(new Long(a[0])+new Long(a[1]));}}
</code>```

Usage: java M <num1> <num2>

Tips appreciated.

Title: Add two numbers

Body:
Input: Two integers. Preferably decimal integers, but other forms of numbers can be used. These can be given to the code in standard input, as arguments to the program or function, or as a list.

Output: Their sum. Use the same format for output integers as input integers. For example, the input 5 16 would lead to the output 21.

Restrictions: No standard loopholes please. This is code-golf, answer in lowest amount of bytes wins.

Notes: This should be fairly trivial, however I'm interested to see how it can be implemented. The answer can be a complete program or a function, but please identify which one it is.

Test cases:

```<code>1 2 -> 3
14 15 -> 29
7 9 -> 16
-1 8 -> 7
8 -9 -> -1
-8 -9 -> -17
</code>```

Or as CSV:

```<code>a,b,c
1,2,3
14,15,29
7,9,16
-1,8,7
8,-9,-1
-8,-9,-17
</code>```

Leaderboard

var QUESTION_ID=84260,OVERRIDE_USER=8478;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:
Java, 91 bytes

interface M{static void main(String[]a){System.out.print(new Long(a[0])+new Long(a[1]));}}

Usage: java M <num1> <num2>

Tips appreciated.


答:
V, 12 bytes

```<code>lòyljvPkvPll
</code>```

Try it online!

Nothing too interesting, just a direct port of my vim answer so I can compete with (but not beat) 05AB1E.

Title: Interlace strings

Body:
V, 12 bytes

lòyljvPkvPll

Try it online!

Nothing too interesting, just a direct port of my vim answer so I can compete with (but not beat) 05AB1E.


答:
Pyke, 9 bytes

```<code>,Fo2%I_(,
</code>```

Try it here!

```<code>          - o = 0
,         -   transpose(input)
 F     (  -  for i in ^:
  o2%     -    (o++ %2)
     I_   -   if ^: i = reverse(i)
        , - transpose(^)
</code>```

Title: Interlace strings

Body:
Pyke, 9 bytes

,Fo2%I_(,

Try it here!

          - o = 0
,         -   transpose(input)
 F     (  -  for i in ^:
  o2%     -    (o++ %2)
     I_   -   if ^: i = reverse(i)
        , - transpose(^)


答:
MATL, <s>11</S> <s>10</s> <s>9</s> 8 bytes

Thanks to ETHproductions for 1 byte off!

```<code>"@X@YS&h
</code>```

Input is a 2D array containing the two strings, such as: ['Halloween'; 'Challenge']. The output strings are in reverse order.

Try it online!

Explanation

```<code>        % Input 2D array implicitly
"       % For each column
  @     %   Push current column
  X@    %   Push iteration index, starting at 1
  YS    %   Circularly shift the column by that amount
  &h    %   Concatenate horizontally with (concatenated) previous columns
        % End implicitly
        % Display implicitly
</code>```

Old version: 9 bytes

```<code>tZyP:1&YS
</code>```

Explanation

```<code>        % Take input implicitly
t       % Duplicate
        % STACK: ['Halloween'; 'Challenge'], ['Halloween'; 'Challenge']
Zy      % Size
        % STACK: ['Halloween'; 'Challenge'], [2 9]
P       % Flip array
        % STACK: ['Halloween'; 'Challenge'], [9 2]
:       % Range. Uses first element of the array as input
        % STACK: ['Halloween'; 'Challenge'], [1 2 3 4 5 6 7 8 9]
1&YS    % Circularly shift each column by those amounts respectively
        % STACK: [Caallwnee';'Hhlloeegn']
        % Display implicitly
</code>```

Title: Interlace strings

Body:
MATL, <s>11</S> <s>10</s> <s>9</s> 8 bytes

Thanks to ETHproductions for 1 byte off!

"@X@YS&h

Input is a 2D array containing the two strings, such as: ['Halloween'; 'Challenge']. The output strings are in reverse order.

Try it online!

Explanation

        % Input 2D array implicitly
"       % For each column
  @     %   Push current column
  X@    %   Push iteration index, starting at 1
  YS    %   Circularly shift the column by that amount
  &h    %   Concatenate horizontally with (concatenated) previous columns
        % End implicitly
        % Display implicitly

Old version: 9 bytes

tZyP:1&YS

Explanation

        % Take input implicitly
t       % Duplicate
        % STACK: ['Halloween'; 'Challenge'], ['Halloween'; 'Challenge']
Zy      % Size
        % STACK: ['Halloween'; 'Challenge'], [2 9]
P       % Flip array
        % STACK: ['Halloween'; 'Challenge'], [9 2]
:       % Range. Uses first element of the array as input
        % STACK: ['Halloween'; 'Challenge'], [1 2 3 4 5 6 7 8 9]
1&YS    % Circularly shift each column by those amounts respectively
        % STACK: [Caallwnee';'Hhlloeegn']
        % Display implicitly


答:
PowerShell v2+, 82 bytes

```<code>param($a,$b)$i=0;[char[]]$a|%{$c+=($_,$b[$i])[$i%2];$d+=($b[$i],$_)[$i++%2]};$c;$d
</code>```

<s>Still golfing...</s> Nope. Can't seem to golf this down any without using a regex like other answers (boo on copying algorithms).

So we take $a and $b as strings, set index $i to 0, cast $a as a char-array, and send it through a loop |%{...}. Each iteration, we're string-concatenating onto $c and $d by indexing into an array-select (i.e., so it alternates back and forth). Then, we leave $c and $d on the pipeline, and output via implicit Write-Output happens at program completion.

Title: Interlace strings

Body:
PowerShell v2+, 82 bytes

param($a,$b)$i=0;[char[]]$a|%{$c+=($_,$b[$i])[$i%2];$d+=($b[$i],$_)[$i++%2]};$c;$d

<s>Still golfing...</s> Nope. Can't seem to golf this down any without using a regex like other answers (boo on copying algorithms).

So we take $a and $b as strings, set index $i to 0, cast $a as a char-array, and send it through a loop |%{...}. Each iteration, we're string-concatenating onto $c and $d by indexing into an array-select (i.e., so it alternates back and forth). Then, we leave $c and $d on the pipeline, and output via implicit Write-Output happens at program completion.


答:
Haskell, 41 bytes

```<code>(a:b)#(c:d)=(a,c):d#b
_#_=[]
(unzip.).(#)
</code>```

Returns a pair with the strings. Usage example: ( (unzip.).(#) ) "Hello," "world!"-> ("Hollo!","werld,").

Simple recursive approach: take the first char of each string as a pair and append a recursive call with the (rest of the) strings swapped. unzip makes a pair of lists out of the list of pairs.

Title: Interlace strings

Body:
Haskell, 41 bytes

(a:b)#(c:d)=(a,c):d#b
_#_=[]
(unzip.).(#)

Returns a pair with the strings. Usage example: ( (unzip.).(#) ) "Hello," "world!"-> ("Hollo!","werld,").

Simple recursive approach: take the first char of each string as a pair and append a recursive call with the (rest of the) strings swapped. unzip makes a pair of lists out of the list of pairs.


Title: Interlace strings

Body:
PHP, 79 Bytes

for(;$i<=strlen(($a=$argv)[1]);$y.=$a[2-$i%2][$i++])echo$a[1+$i%2][+$i]??" $y";

Previous Version PHP, 82 Bytes

for(;$i<strlen(($a=$argv)[1]);$y.=$a[2-$i%2][$i++])$x.=$a[1+$i%2][$i];echo"$x $y";


答:
Haskell, 37 bytes

l=(,):flip(,):l
(unzip.).zipWith3($)l
```

<p>Zips the two strings, alternately swapping the characters, then unzips them.</p>

<p>A 37-byte recursive alternative:</p>

<pre class="lang-haskell prettyprint-override"><code>(a:b)?(c:d)=a:d?b
e?_=e
a%b=(a?b,b?a)
</code>```

Title: Interlace strings

Body:
Haskell, 37 bytes

l=(,):flip(,):l
(unzip.).zipWith3($)l

Zips the two strings, alternately swapping the characters, then unzips them.

A 37-byte recursive alternative:

(a:b)?(c:d)=a:d?b
e?_=e
a%b=(a?b,b?a)


问:
Markov Chain Quine
A simple Markov Model will be used in this question. For more information about Markov Chains, see http://setosa.io/ev/markov-chains/.

Take a string. For this example, we will use the word:

```<code>reader
</code>```

Now, for each character, take the characters that appear after each occurence of the character in the string. (`^` represents the start of the string and `$` represents the end)

```<code>`^` -> {'r'}       # After the start of the string, there is an `r`.
'r' -> {'e', `$`}  # After the first `r` (*r*eader), there is an `e`
                   # after the second (reade*r*), there is the end of the string.
'e' -> {'a', 'r'}
'a' -> {'d'}
'd' -> {'e'}
</code>```

Now, starting from the start of the string, pick randomly from one of the characters in the next set. Append this character and then pick from the characters in its next set, and so on until you get to the end. Here are some example words:

```<code>r
rereader
rer
readereader
</code>```

If a character appears after another character multiple times, it is more likely to be chosen. For example, in cocoa can, after a c, there is a two thirds of a chance of getting an o and a one thirds chance of getting an a.

```<code>'c' -> {'o', 'o', 'a'}
</code>```

Challenge

Create a program that takes no input and outputs a random string generated using a Markov Chain, like above, where the input to the chain is the program's source.

The program must have at least two characters, two of which must be the same (To prevent "boring" chains that only have one output)

You can modify the model to use bytes instead of characters if you wish, but change "characters" to "bytes" in rule 1

The program should output strings randomly with the expected frequency in theory

This is code-golf, so the shortest program wins!

答:
JavaScript, <s>217</s> 215 bytes

a="a=q;a=a.replace('q',uneval(a));for(b=c='a';d=a.split(c),c=d[Math.random()*~-d.length+1|0][0];b+=c);alert(b)";a=a.replace('q',uneval(a));for(b=c='a';d=a.split(c),c=d[Math.random()*~-d.length+1|0][0];b+=c);alert(b)```
</div>
</div>
</p>

<p>Note that this uses <code>uneval</code>, which is only supported by Firefox. Sample runs:</p>

```a=ale(a.lend[Ma=d[Macepla.ler(b+=c)b=q;fom(a=q;a=dort(b+1|0],c);a.lit(a)
at(c=c;d[0],c=q;ath+1|0][0];dorerac=ac=d[Ma),c;)*~-d[Ma=alenepl(b+=ac=c;a=c;d[2];d.re(c;fom()
a="a[0],und=d=a)
angt(b),und=d.l(b=a)
a)
ale(a.rth.revanepleplit(b)
ac);fore(b)*~-d.r(b+1|0];fora';a)*~-d.splalith+=dorth+=c=";ath+=a.length+=';ale(b)
a.r(b=c=a)b+1|0],und[0][0];d.splerath.spleneva)";ath.r(ceneplith+=d=aceple(c;)*~-d=';ala';)b='ac;fom(b=c;a.ler(b=d=d[Ma.rt(c=cendor()*~-d='a=";ac;a.spla)b=ceva=';a=d.rt(angt(alength+1|0],c;angt()
al(ac=dorth+1|0][0][0][0][Ma.split()
```

<p>As you can see, it's mostly gibberish, but that is to be expected ;) The OP has created a JSFiddle which demonstrates that the chance of an output being syntactically valid JS is  about 6.3%.</p>

<hr>

<p>If self-reading functions were allowed, this could be 78 bytes of ES6:</p>

<pre class="lang-js prettyprint-override"><code>f=(c="f",p=("f="+f).split(c),q=p[Math.random()*~-p.length+1|0][0])=>q?c+f(q):c
</code>```

Very, very rarely, this outputs syntactically valid JS:

f=>e?c+f():c
f=>e?c=>engt():c
f=>e?c=(e):c
f=>e?c=>e=>ength.split():c
f=p=>q?c+f():c
f(q).sp=",p[Mat(q?c=(),plith.lith.sp.sp[0]).lendom().lith+f=>q=p.lendom(",p=p=>q?c+f():c
f(q),q?c=(c=(q)*~-p[0]):c
f().random(),q?c=(c=p[0]):c
f=>q?c=(q="+f"+f).rath.split(c):c
f="+1|0])=().lith.rat()*~-p=>q?c=p[Mat(c=",q?c=p.rath.splendom()*~-plength.splith.lendom(c):c
```

My favorite of the function names it's created is .splendom() (split + length + random)

Title: Markov Chain Quine

Body:
JavaScript, <s>217</s> 215 bytes

a="a=q;a=a.replace('q',uneval(a));for(b=c='a';d=a.split(c),c=d[Math.random()*~-d.length+1|0][0];b+=c);alert(b)";a=a.replace('q',uneval(a));for(b=c='a';d=a.split(c),c=d[Math.random()*~-d.length+1|0][0];b+=c);alert(b)

Note that this uses uneval, which is only supported by Firefox. Sample runs:

a=ale(a.lend[Ma=d[Macepla.ler(b+=c)b=q;fom(a=q;a=dort(b+1|0],c);a.lit(a)
at(c=c;d[0],c=q;ath+1|0][0];dorerac=ac=d[Ma),c;)*~-d[Ma=alenepl(b+=ac=c;a=c;d[2];d.re(c;fom()
a="a[0],und=d=a)
angt(b),und=d.l(b=a)
a)
ale(a.rth.revanepleplit(b)
ac);fore(b)*~-d.r(b+1|0];fora';a)*~-d.splalith+=dorth+=c=";ath+=a.length+=';ale(b)
a.r(b=c=a)b+1|0],und[0][0];d.splerath.spleneva)";ath.r(ceneplith+=d=aceple(c;)*~-d=';ala';)b='ac;fom(b=c;a.ler(b=d=d[Ma.rt(c=cendor()*~-d='a=";ac;a.spla)b=ceva=';a=d.rt(angt(alength+1|0],c;angt()
al(ac=dorth+1|0][0][0][0][Ma.split()

As you can see, it's mostly gibberish, but that is to be expected ;) The OP has created a JSFiddle which demonstrates that the chance of an output being syntactically valid JS is  about 6.3%.

If self-reading functions were allowed, this could be 78 bytes of ES6:

f=(c="f",p=("f="+f).split(c),q=p[Math.random()*~-p.length+1|0][0])=>q?c+f(q):c

Very, very rarely, this outputs syntactically valid JS:

f=>e?c+f():c
f=>e?c=>engt():c
f=>e?c=(e):c
f=>e?c=>e=>ength.split():c
f=p=>q?c+f():c
f(q).sp=",p[Mat(q?c=(),plith.lith.sp.sp[0]).lendom().lith+f=>q=p.lendom(",p=p=>q?c+f():c
f(q),q?c=(c=(q)*~-p[0]):c
f().random(),q?c=(c=p[0]):c
f=>q?c=(q="+f"+f).rath.split(c):c
f="+1|0])=().lith.rat()*~-p=>q?c=p[Mat(c=",q?c=p.rath.splendom()*~-plength.splith.lendom(c):c

My favorite of the function names it's created is .splendom() (split + length + random)


答:
Ruby, 10 bytes

```<code>->a,b{a+b}
</code>```

An anonymous Proc (I guess, if not a lambda idc) just adds its parameters.
Makes use of implicit return in Ruby.

Usage: ->a,b{a+b}[1,2] or ->a,b{a+b}.call(1,2)

Title: Add two numbers

Body:
Ruby, 10 bytes

->a,b{a+b}

An anonymous Proc (I guess, if not a lambda idc) just adds its parameters.
Makes use of implicit return in Ruby.

Usage: ->a,b{a+b}[1,2] or ->a,b{a+b}.call(1,2)


答:
C, 124 bytes

```<code>main(c,v)char**v;{char a[99],b[99];for(c=0;v[1][c]^0;++c){a[c]=v[1+c%2][c];b[c]=v[2-c%2][c];}a[c]=0;b[c]=0;puts(a);puts(b);}
</code>```

Call with:

```<code>program.exe string1 string2
</code>```

String length is limited to 98 characters.

Title: Interlace strings

Body:
C, 124 bytes

main(c,v)char**v;{char a[99],b[99];for(c=0;v[1][c]^0;++c){a[c]=v[1+c%2][c];b[c]=v[2-c%2][c];}a[c]=0;b[c]=0;puts(a);puts(b);}

Call with:

program.exe string1 string2

String length is limited to 98 characters.


答:
Jelly, <s>9</s> <s>8</s> 6 bytes

Thanks to Dennis for saving 2 bytes!

```<code>Zṙ"J$Z
</code>```

Uses the Jelly encoding.

Try it online!

Title: Interlace strings

Body:
Jelly, <s>9</s> <s>8</s> 6 bytes

Thanks to Dennis for saving 2 bytes!

Zṙ"J$Z

Uses the Jelly encoding.

Try it online!


答:
VBA 117 bytes

```<code>Sub q():Dim x(100):While x(100)=0:Debug.Print:x(0)=x(0)+1:i=0:While x(i)>9:x(i)=0:i=i+1:x(i)=x(i)+1:Wend:Wend:End Sub
</code>```

Invoke with q. Prints a googol newlines to immediate window. Easy to test by changing the "While x(100)" to say "While x(2)", which prints a hundred newlines.

I could use "MsgBox 0" in place of "Debug.Print" (saving 3 characters) but that would involve pressing return on the output more times than feasible, countering the whole idea of "program".

Title: Output a googol copies of a string

Body:
I am interested in seeing programs which don't ask for any input, print a googol copies of some nonempty string, no less, no more, and then stop. A googol is defined as \$10^{100}\$, i.e., 1 followed by a hundred 0's in decimal.

Example output:

```<code>111111111111111111111111111111111111111111111111111111111111111111111111...
</code>```

or

```<code>Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
...
</code>```

The string can also be entirely composed of white space or special symbols. The only exception to identical copies of a fixed string is if your language decorates the output in some way that can not be prevented, but could be trivially undone in a wrapper script, like prepending a line number to each line. The wrapper script in such cases need not be provided.

You can assume your computer will never run out of time, but other than that, your program must have a reasonable demand of resources. Also, you must respect any restrictions that the programming language of your choice poses, for example, you can not exceed a maximum value allowed for its integer types, and at no point more than 4 GB of memory must be needed.

In other words, the program should in principle be testable by running it on your computer. But because of the extent of this number you will be expected to prove that the number of copies of the string it outputs is exactly 10^100 and that the program stops afterwards. Stopping can be exiting or halting or even terminating due to an error, but if so, the error must not produce any output that could not easily be separated from the program's output.

This is code-golf,  so the solution with the fewest bytes wins.

Example solution (C, ungolfed, 3768 bytes)

```<code>#include <stdio.h>

int main() {
  int a00, a01, a02, a03, ..., a99;
  for(a00 = 0; a00 < 10; a00++)
  for(a01 = 0; a01 < 10; a01++)
  for(a02 = 0; a02 < 10; a02++)
  for(a03 = 0; a03 < 10; a03++)
  ...
  for(a99 = 0; a99 < 10; a99++)
    puts("1");
  return 0;
}
</code>```

Body:
VBA 117 bytes

Sub q():Dim x(100):While x(100)=0:Debug.Print:x(0)=x(0)+1:i=0:While x(i)>9:x(i)=0:i=i+1:x(i)=x(i)+1:Wend:Wend:End Sub

Invoke with q. Prints a googol newlines to immediate window. Easy to test by changing the "While x(100)" to say "While x(2)", which prints a hundred newlines.

I could use "MsgBox 0" in place of "Debug.Print" (saving 3 characters) but that would involve pressing return on the output more times than feasible, countering the whole idea of "program".


问:
Produce Dürer's magic square

The challenge

Output an array or string representation of Dürer's famous magic square:

that is,

```<code>16  3  2 13
 5 10 11  8
 9  6  7 12
 4 15 14  1
</code>```

Some properties of this square, which can perhaps be exploited, are:

It contains each integer from 1 to 16 exactly once

The sum of each column or row, as well as the the sum of each of the two diagonals, is the same. This is the defining property of a magic square. The sum is the magic constant of the square.

In addition, for this particular square, the sum of each of the four quadrants also equals the magic constant, as do the sum of the center four squares and the sum of the corner four squares.

Rules

Bultins that generate magic squares are not allowed (such as Matlab's magic or Mathematica's MagicSquare). Any other builtin can be used.

The code can be a program or a function.

There is no input.

The numbers must be in base 10. The output format is flexible as usual. Some possibilities are:

A nested array (either function output, or its string representation, with or without separators, any type of matching brackets):

```<code>[[16, 3, 2, 13], [5, 10, 11, 8], [9, 6, 7, 12], [4, 15, 14, 1]]
</code>```

A 2D array:

```<code>{16, 3, 2, 13; 5, 10, 11, 8; 9, 6, 7, 12; 4, 15, 14, 1}
</code>```

An array of four strings, or a string consisting of four lines. The numbers may be right-aligned

```<code>16  3  2 13
 5 10 11  8
 9  6  7 12
 4 15 14  1
</code>```

or left-aligned

```<code>16 3  2  13
5  10 11  8
9  6  7  12
4  15 14  1
</code>```

A string with two different separators for row and column, such as

```<code>16,3,2,13|5,10,11,8|9,6,7,12|4,15,14,1
</code>```

The output format should clearly differentiate rows and columns. For example, it is not allowed to output a flat array, or a string with all numbers separated by spaces.

Code golf. Shortest wins.

答:
sed 39 bytes

```<code>c16,3,2,13|5,10,11,8|9,6,7,12|4,15,14,1
</code>```

Try it Online!

It can't get much simpler than this. And, unfortunately, I don't think it can get any shorter either.

Title: Produce Dürer's magic square

Body:
sed 39 bytes

c16,3,2,13|5,10,11,8|9,6,7,12|4,15,14,1

Try it Online!

It can't get much simpler than this. And, unfortunately, I don't think it can get any shorter either.


答:
JavaScript (ES6), 43 bytes

```<code>_=>`16,3,2,13
5,10,11,8
9,6,7,12
4,15,14,1`
</code>```

Separated by newlines, then commas. I doubt there's any shorter way...

Title: Produce Dürer's magic square

Body:
The challenge

Output an array or string representation of Dürer's famous magic square:

that is,

```<code>16  3  2 13
 5 10 11  8
 9  6  7 12
 4 15 14  1
</code>```

Some properties of this square, which can perhaps be exploited, are:

It contains each integer from 1 to 16 exactly once

The sum of each column or row, as well as the the sum of each of the two diagonals, is the same. This is the defining property of a magic square. The sum is the magic constant of the square.

In addition, for this particular square, the sum of each of the four quadrants also equals the magic constant, as do the sum of the center four squares and the sum of the corner four squares.

Rules

Bultins that generate magic squares are not allowed (such as Matlab's magic or Mathematica's MagicSquare). Any other builtin can be used.

The code can be a program or a function.

There is no input.

The numbers must be in base 10. The output format is flexible as usual. Some possibilities are:

A nested array (either function output, or its string representation, with or without separators, any type of matching brackets):

```<code>[[16, 3, 2, 13], [5, 10, 11, 8], [9, 6, 7, 12], [4, 15, 14, 1]]
</code>```

A 2D array:

```<code>{16, 3, 2, 13; 5, 10, 11, 8; 9, 6, 7, 12; 4, 15, 14, 1}
</code>```

An array of four strings, or a string consisting of four lines. The numbers may be right-aligned

```<code>16  3  2 13
 5 10 11  8
 9  6  7 12
 4 15 14  1
</code>```

or left-aligned

```<code>16 3  2  13
5  10 11  8
9  6  7  12
4  15 14  1
</code>```

A string with two different separators for row and column, such as

```<code>16,3,2,13|5,10,11,8|9,6,7,12|4,15,14,1
</code>```

The output format should clearly differentiate rows and columns. For example, it is not allowed to output a flat array, or a string with all numbers separated by spaces.

Code golf. Shortest wins.

Body:
JavaScript (ES6), 43 bytes

_=>`16,3,2,13
5,10,11,8
9,6,7,12
4,15,14,1`

Separated by newlines, then commas. I doubt there's any shorter way...


答:
05AB1E, <s>18</s> 17 bytes

Thanks to Emigna for saving a byte!

```<code>•3øÑ¼ž·Üý;•hSH>4ô
</code>```

Uses the CP-1252 encoding. Try it online!

Title: Produce Dürer's magic square

Body:
05AB1E, <s>18</s> 17 bytes

Thanks to Emigna for saving a byte!

•3øÑ¼ž·Üý;•hSH>4ô

Uses the CP-1252 encoding. Try it online!


问:
Is this number a prime?
Believe it or not, we do not yet have a code golf challenge for a simple primality test. While it may not be the most interesting challenge, particularly for "usual" languages, it can be nontrivial in many languages.

Rosetta code features lists by language of idiomatic approaches to primality testing, one using the Miller-Rabin test specifically and another using trial division. However, "most idiomatic" often does not coincide with "shortest." In an effort to make Programming Puzzles and Code Golf the go-to site for code golf, this challenge seeks to compile a catalog of the shortest approach in every language, similar to "Hello, World!" and Golf you a quine for great good!.

Furthermore, the capability of implementing a primality test is part of our definition of programming language, so this challenge will also serve as a directory of proven programming languages.

Task

Write a full program that, given a strictly positive integer n as input, determines whether n is prime and prints a truthy or falsy value accordingly.

For the purpose of this challenge, an integer is prime if it has exactly two strictly positive divisors. Note that this excludes 1, who is its only strictly positive divisor.

Your algorithm must be deterministic (i.e., produce the correct output with probability 1) and should, in theory, work for arbitrarily large integers. In practice, you may assume that the input can be stored in your data type, as long as the program works for integers from 1 to 255.

Input

If your language is able to read from STDIN, accept command-line arguments or any other alternative form of user input, you can read the integer as its decimal representation, unary representation (using a character of your choice), byte array (big or little endian) or single byte (if this is your languages largest data type).

If (and only if) your language is unable to accept any kind of user input, you may hardcode the input in your program.

In this case, the hardcoded integer must be easily exchangeable. In particular, it may appear only in a single place in the entire program.

For scoring purposes, submit the program that corresponds to the input 1.

Output

Output has to be written to STDOUT or closest alternative.

If possible, output should consist solely of a truthy or falsy value (or a string representation thereof), optionally followed by a single newline.

The only exception to this rule is constant output of your language's interpreter that cannot be suppressed, such as a greeting, ANSI color codes or indentation.

Additional rules

This is not about finding the language with the shortest approach for prime testing, this is about finding the shortest approach in every language. Therefore, no answer will be marked as accepted.

Submissions in most languages will be scored in bytes in an appropriate preexisting encoding, usually (but not necessarily) UTF-8.

The language Piet, for example, will be scored in codels, which is the natural choice for this language.

Some languages, like Folders, are a bit tricky to score. If in doubt, please ask on Meta.

Unlike our usual rules, feel free to use a language (or language version) even if it's newer than this challenge. If anyone wants to abuse this by creating a language where the empty program performs a primality test, then congrats for paving the way for a very boring answer.

Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language.

If your language of choice is a trivial variant of another (potentially more popular) language which already has an answer (think BASIC or SQL dialects, Unix shells or trivial Brainfuck derivatives like Headsecks or Unary), consider adding a note to the existing answer that the same or a very similar solution is also the shortest in the other language.

Built-in functions for testing primality are allowed. This challenge is meant to catalog the shortest possible solution in each language, so if it's shorter to use a built-in in your language, go for it.

Unless they have been overruled earlier, all standard code-golf rules apply, including the http://meta.codegolf.stackexchange.com/q/1061.

As a side note, please don't downvote boring (but valid) answers in languages where there is not much to golf; these are still useful to this question as it tries to compile a catalog as complete as possible. However, do primarily upvote answers in languages where the author actually had to put effort into golfing the code.

Catalog

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

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

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

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

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

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

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

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

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

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

```<code>2=∘≢∘∪⍳∨⊢
</code>```

I don't think this one has been posted.

Title: Is this number a prime?

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

2=∘≢∘∪⍳∨⊢

I don't think this one has been posted.


答:
Pyth, 8 bytes

```<code>C.e_FbkC
</code>```

Try it online: Demonstration

Transposes the words, reverses each pair of letters 'current index'-times, transpose again.

Title: Interlace strings

Body:
Your challenge is to write a program or function that, when given two strings of equal length, swaps every other character and outputs/returns the resulting strings in either order.

Examples

```<code>"Hello," "world!" --> "Hollo!" "werld,"
"code" "golf" --> "codf" "gole"
"happy" "angry" --> "hnpry" "aagpy"
"qwerty" "dvorak" --> "qvertk" "dworay"
"1, 2, 3" "a, b, c" --> "1, b, 3" "a, 2, c"
"3.141592653589" "2.718281828459" --> "3.111291623489" "2.748582858559"
"DJMcMayhem" "trichoplax" --> "DrMcMoylex" "tJichapham"
"Doorknob" "Downgoat" --> "Doonkoot" "Dowrgnab"
"Halloween" "Challenge" --> "Hhlloeegn" "Caallwnee"
</code>```

Rules

The strings will only contain ASCII chars (32-126).

The strings will always be the same length, and will never be empty.

You may accept input in any suitable format: separate parameters, items in an array, separated by one or more newlines, even concatenated. The only restriction is that one string must come fully before the other (e.g. a1\nb2\nc3 for "abc", "123" is invalid).

The output may be in either order (i.e. you can start swapping from the first or the second char), and in any valid format mentioned above. (2-item array, separated by newline(s), concatenated, etc.)

Scoring

This is code-golf, so the shortest code in bytes for each language wins.

Body:
Pyth, 8 bytes

C.e_FbkC

Try it online: Demonstration

Transposes the words, reverses each pair of letters 'current index'-times, transpose again.


答:
Python, 55 bytes

lambda a,b:[(-~len(a)/2*s)[::len(a)+1]for s in a+b,b+a]
```

<p>Slicing!</p>

<p>58 bytes:</p>

<pre class="lang-python prettyprint-override"><code>def f(a,b):n=len(a);print[(s*n)[:n*n:n+1]for s in a+b,b+a]
</code>```

64 bytes:

f=lambda a,b,s='',t='':a and f(b[1:],a[1:],s+a[0],t+b[0])or[s,t]
```

<p>Recursively accumulates the characters of the two strings into <code>s</code> and <code>t</code>, and outputs the pair of them at the end. The alternation is done by switching the input strings each recursive call. Outputting a space-separated string was the same length:</p>

<pre class="lang-python prettyprint-override"><code>lambda a,b,s='',t=' ':a and f(b[1:],a[1:],s+a[0],t+b[0])or s+t
</code>```

This narrowly beat out a different recursive strategy of alternately taking characters from each string, with each of the two possible strings as the first one. (65 bytes)

g=lambda a,b:a and a[0]+g(b[1:],a[1:])
lambda a,b:(g(a,b),g(b,a))
```

Title: Interlace strings

Body:
Python, 55 bytes

lambda a,b:[(-~len(a)/2*s)[::len(a)+1]for s in a+b,b+a]

Slicing!

58 bytes:

def f(a,b):n=len(a);print[(s*n)[:n*n:n+1]for s in a+b,b+a]

64 bytes:

f=lambda a,b,s='',t='':a and f(b[1:],a[1:],s+a[0],t+b[0])or[s,t]

Recursively accumulates the characters of the two strings into s and t, and outputs the pair of them at the end. The alternation is done by switching the input strings each recursive call. Outputting a space-separated string was the same length:

lambda a,b,s='',t=' ':a and f(b[1:],a[1:],s+a[0],t+b[0])or s+t

This narrowly beat out a different recursive strategy of alternately taking characters from each string, with each of the two possible strings as the first one. (65 bytes)

g=lambda a,b:a and a[0]+g(b[1:],a[1:])
lambda a,b:(g(a,b),g(b,a))


答:
Python, 42 bytes with I/O golfing

def f(a,b):a[1::2],b[1::2]=b[1::2],a[1::2]
```

<p>Swaps every other character of the two lists. Takes as input two lists of characters, and outputs by modifying them.</p>

<pre class="lang-python prettyprint-override"><code>l=list('cat')
m=list('dog')
print l,m

def f(a,b):a[1::2],b[1::2]=b[1::2],a[1::2]

f(l,m)
print l,m
</code>```

gives

['c', 'a', 't'] ['d', 'o', 'g']
['c', 'o', 't'] ['d', 'a', 'g']
```

Title: Interlace strings

Body:
Python, 42 bytes with I/O golfing

def f(a,b):a[1::2],b[1::2]=b[1::2],a[1::2]

Swaps every other character of the two lists. Takes as input two lists of characters, and outputs by modifying them.

l=list('cat')
m=list('dog')
print l,m

def f(a,b):a[1::2],b[1::2]=b[1::2],a[1::2]

f(l,m)
print l,m

gives

['c', 'a', 't'] ['d', 'o', 'g']
['c', 'o', 't'] ['d', 'a', 'g']


答:
JavaScript (ES6), 55 bytes

```<code>f=([c,...s],[d,...t],o="",p="")=>c?f(t,s,o+c,p+d):[o,p]
</code>```

I wanted to do something clever with using regexp to replace alternate characters but that ended up taking <s>67</s> 57 bytes:

```<code>a=>a.map((s,i)=>a[+!i].replace(/.(.?)/g,(_,c,j)=>s[j]+c))
</code>```

Title: Interlace strings

Body:
JavaScript (ES6), 55 bytes

f=([c,...s],[d,...t],o="",p="")=>c?f(t,s,o+c,p+d):[o,p]

I wanted to do something clever with using regexp to replace alternate characters but that ended up taking <s>67</s> 57 bytes:

a=>a.map((s,i)=>a[+!i].replace(/.(.?)/g,(_,c,j)=>s[j]+c))


答:
C, 150 bytes

I used the typical omissions of header files and main()'s return type and return statement. It throws a warning, but compiles without issue. I also used a GCC-specific trick that allows array declarations with variable expressions.

The program expects the strings from the command line, and as such, the program should be run with ./a.out string1 string2.

```<code>main(int a,char**v){int x=strlen(v[1]);char s[x],t[x],c;strcpy(s,v[1]);strcpy(t,v[2]);for(a=0;a<x;++a)if(a%2)c=s[a],s[a]=t[a],t[a]=c;puts(s),puts(t);}
</code>```

Or more legibly,

```<code>main(int a,char**v){
    int x=strlen(v[1]);
    char s[x],t[x],c;
    strcpy(s,v[1]);strcpy(t,v[2]);
    for(a=0;a<x;++a)
        if(a%2)c=s[a],s[a]=t[a],t[a]=c;
    puts(s),puts(t);
}
</code>```

Title: Interlace strings

Body:
C, 150 bytes

I used the typical omissions of header files and main()'s return type and return statement. It throws a warning, but compiles without issue. I also used a GCC-specific trick that allows array declarations with variable expressions.

The program expects the strings from the command line, and as such, the program should be run with ./a.out string1 string2.

main(int a,char**v){int x=strlen(v[1]);char s[x],t[x],c;strcpy(s,v[1]);strcpy(t,v[2]);for(a=0;a<x;++a)if(a%2)c=s[a],s[a]=t[a],t[a]=c;puts(s),puts(t);}

Or more legibly,

main(int a,char**v){
    int x=strlen(v[1]);
    char s[x],t[x],c;
    strcpy(s,v[1]);strcpy(t,v[2]);
    for(a=0;a<x;++a)
        if(a%2)c=s[a],s[a]=t[a],t[a]=c;
    puts(s),puts(t);
}


答:
Jelly, 20 bytes

```<code>“Ñ¤£Æ¦½¿®µ©¬€¥ÐÇ¢‘s4
</code>```

Try it online!

This simply looks up the Jelly code point of each character, then slices into subarrays of length 4 with s4.

Title: Produce Dürer's magic square

Body:
Jelly, 20 bytes

“Ñ¤£Æ¦½¿®µ©¬€¥ÐÇ¢‘s4

Try it online!

This simply looks up the Jelly code point of each character, then slices into subarrays of length 4 with s4.


答:
JavaScript (ES6), 51 <s>54</s>

Edit 3 bytes saved thx @Neil

Function with array input/output

p=>p.map((w,i)=>w.replace(/./g,(c,j)=>p[i+j&1][j]))
```
<p>I like this one more, but it's 55 (2 strings in input, array in output)</p>
<pre class="lang-js prettyprint-override"><code>(a,b)=>[...a].reduce(([p,q],c,i)=>[q+c,p+b[i]],['',''])
</code>```

Test

f=
p=>p.map((w,i)=>w.replace(/./g,(c,j)=>p[i+j&1][j]))

function go() {
  var a=A.value, b=B.value
  if (a.length == b.length)
    O.textContent = f([a,b]).join('\n')
  else
    O.textContent = '- different length -'

}

go()```
<pre class="snippet-code-html lang-html prettyprint-override"><code><input id=A value='Hello,'><input id=B value='world!'>
<button onclick='go()'>go</button><pre id=O>``````

Title: Interlace strings

Body:
JavaScript (ES6), 51 <s>54</s>

Edit 3 bytes saved thx @Neil

Function with array input/output

p=>p.map((w,i)=>w.replace(/./g,(c,j)=>p[i+j&1][j]))

I like this one more, but it's 55 (2 strings in input, array in output)

(a,b)=>[...a].reduce(([p,q],c,i)=>[q+c,p+b[i]],['',''])

Test

f=
p=>p.map((w,i)=>w.replace(/./g,(c,j)=>p[i+j&1][j]))

function go() {
  var a=A.value, b=B.value
  if (a.length == b.length)
    O.textContent = f([a,b]).join('\n')
  else
    O.textContent = '- different length -'

}

go()

<input id=A value='Hello,'><input id=B value='world!'>
<button onclick='go()'>go</button><pre id=O></pre>


答:
Java, 132 103 100 bytes

Thanks to  Kevin Cruijssen for suggesting returning the array (among other improvements) and saving 29 bytes! Also Olivier Grégoire for 3 bytes!

```<code>char[]c(char[]s,int l){for(int o=l;o-->0;)if(o%2>0){char t=s[o];s[o]=s[l+o+1];s[l+o+1]=t;}return s;}
</code>```

Called like this:

```<code>public static void main(String[] args) {
    System.out.println(c("Hello,world!".toCharArray(), 5)); // 5 is the length of each "String"
}
</code>```

Output:

Hollo,werld!

Takes advantage of the fact that input can basically be formatted in any way (in this case, a single char array of Strings that are delimited by a comma), and pretty lenient output rules as well.

Title: Interlace strings

Body:
Java, 132 103 100 bytes

Thanks to  Kevin Cruijssen for suggesting returning the array (among other improvements) and saving 29 bytes! Also Olivier Grégoire for 3 bytes!

char[]c(char[]s,int l){for(int o=l;o-->0;)if(o%2>0){char t=s[o];s[o]=s[l+o+1];s[l+o+1]=t;}return s;}

Called like this:

public static void main(String[] args) {
    System.out.println(c("Hello,world!".toCharArray(), 5)); // 5 is the length of each "String"
}

Output:

Hollo,werld!

Takes advantage of the fact that input can basically be formatted in any way (in this case, a single char array of Strings that are delimited by a comma), and pretty lenient output rules as well.


答:
Jelly, 5 bytes

```<code>żṚż¥/
</code>```

Input is as separate arguments, output is concatenated.

Try it online! or verify all test cases.

How it works

```<code>żṚż¥/  Main link. Left argument: s (string). Right argument: t (string)

ż      Zipwith; yield the array of pairs of corresponding characters of s and t.
   ¥   Combine the two links to the left into a dyadic chain:
 Ṛ         Reverse the chain's left argument.
  ż        Zip the result with the chain's right argument.
    /  Reduce the return value of the initial ż by the quicklink Ṛż¥.
</code>```

Title: Interlace strings

Body:
Jelly, 5 bytes

żṚż¥/

Input is as separate arguments, output is concatenated.

Try it online! or verify all test cases.

How it works

żṚż¥/  Main link. Left argument: s (string). Right argument: t (string)

ż      Zipwith; yield the array of pairs of corresponding characters of s and t.
   ¥   Combine the two links to the left into a dyadic chain:
 Ṛ         Reverse the chain's left argument.
  ż        Zip the result with the chain's right argument.
    /  Reduce the return value of the initial ż by the quicklink Ṛż¥.


答:
Pyth, 18 bytes

```<code>c4.PC"H#ût"_S16
</code>```

Run the code.

```<code>c4.PC"H#ût"_S16

    C"H#ût"       Convert the packed string to the number 1122196781940
  .P       _S16   Take that-numbered permutation of the reversed range [16,15,...,1]
c4                Chop into piece of length 4
</code>```

Reversing the range was meant to lower the permutation index, since the output starts with 16, but I think it only broke even.

This beat out a more boring strategy of converting the table directly to base 17 and then a string (link) for 20 bytes:

```<code>c4jC"úz(ás¸H"17
</code>```

Title: Produce Dürer's magic square

Body:
Pyth, 18 bytes

c4.PC"H#ût"_S16

Run the code.

c4.PC"H#ût"_S16

    C"H#ût"       Convert the packed string to the number 1122196781940
  .P       _S16   Take that-numbered permutation of the reversed range [16,15,...,1]
c4                Chop into piece of length 4

Reversing the range was meant to lower the permutation index, since the output starts with 16, but I think it only broke even.

This beat out a more boring strategy of converting the table directly to base 17 and then a string (link) for 20 bytes:

c4jC"úz(ás¸H"17


答:
Jelly, 15 bytes

```<code>“¡6ṡƘ[²Ḳi<’ḃ⁴s4
</code>```

TryItOnline!

Pretty boring, sorry:

Prep: Took the square, read it by rows, converted from bijective base 16, convert that to base 250, looked up the code page indexes for those "digits" (¡6ṡƘ[²Ḳi<).

Jelly then reads the indexes to make a base 250 number, converts to bijective base 16 (ḃ⁴) and splits into chunks of size 4 (s4).

If we are allowed to output a different orientation, upside-down is possible in 14:

```<code>“#⁷ƙ¤ṆWȷỤ’ḃ⁴s4
</code>```

Test

In theory, given enough memory for 16! integers the following would give us the correct orientation in 14:

```<code>⁴Œ!“ŒCġŀḌ;’ịs4
</code>```

This would create all permutations of [1,16] with ⁴Œ! and pick the value at index 19800593106060 (1-based) with ị using the base 250 representation ŒCġŀḌ; and split it into chunks of length 4 with s4.

Since then I have added four new atoms (Œ?, Œ¿, œ?, and œ¿) to Jelly to address such situations.

The monad Œ? takes an integer (or iterable of integers) and returns the shortest possible permutation of running natural numbers which would have the given index (or indexes) in a list of lexicographically sorted list of all permutations of those numbers.

...and it does so without creating any permutation lists.

As such the following would now work for 12 (obviously non-competing):

```<code>“ŒCġŀḌ;’Œ?s4
</code>```

Give It A Go!

Title: Produce Dürer's magic square

Body:
Jelly, 15 bytes

“¡6ṡƘ[²Ḳi<’ḃ⁴s4

TryItOnline!

Pretty boring, sorry:

Prep: Took the square, read it by rows, converted from bijective base 16, convert that to base 250, looked up the code page indexes for those "digits" (¡6ṡƘ[²Ḳi<).

Jelly then reads the indexes to make a base 250 number, converts to bijective base 16 (ḃ⁴) and splits into chunks of size 4 (s4).

If we are allowed to output a different orientation, upside-down is possible in 14:

“#⁷ƙ¤ṆWȷỤ’ḃ⁴s4

Test

In theory, given enough memory for 16! integers the following would give us the correct orientation in 14:

⁴Œ!“ŒCġŀḌ;’ịs4

This would create all permutations of [1,16] with ⁴Œ! and pick the value at index 19800593106060 (1-based) with ị using the base 250 representation ŒCġŀḌ; and split it into chunks of length 4 with s4.

Since then I have added four new atoms (Œ?, Œ¿, œ?, and œ¿) to Jelly to address such situations.

The monad Œ? takes an integer (or iterable of integers) and returns the shortest possible permutation of running natural numbers which would have the given index (or indexes) in a list of lexicographically sorted list of all permutations of those numbers.

...and it does so without creating any permutation lists.

As such the following would now work for 12 (obviously non-competing):

“ŒCġŀḌ;’Œ?s4

Give It A Go!


问:
Decode Baby-talk!
When babies open their mouths, they're not just spewing gibberish. They're actually talking in a highly advanced, adult-proof cipher...

The Baby-talk Cipher

When a baby talks, it could look something like gogooa gagooook aagaaoooy
Each single-space separated section represents a character (so the example above represents 3 characters).

To decipher a section, we must count number of As and Os it contains. However, we only count those which are adjacent to another vowel. For example, the A in 'gag' would not count, but both the A and O in 'gaog' would.

Counting the example above would look like this:

```<code>Section    | Num Os | Num As

gogooa     | 2      | 1
gagooook   | 4      | 0
aagaaoooy  | 3      | 4
</code>```

We then use these values to convert the input into plaintext on a Polybius square. This is a 5x5 representation of the English alphabet, omitting 'J' (please note that, in baby-talk, 0-counting rules apply to the table):

```<code>  0 1 2 3 4
0 A B C D E
1 F G H I K
2 L M N O P
3 Q R S T U
4 V W X Y Z
</code>```

Using the number of Os as the column, and number of As as the row, we find which character each section represents:

```<code>Section    | Num Os | Num As | Character

gogooa     | 2      | 1      | (2,1) -> H
gagooook   | 4      | 0      | (4,0) -> E
aagaaoooy  | 3      | 4      | (3,4) -> Y
</code>```

Which tells us that the baby was just saying "HEY".

Notes:

- If a section representing a character has more than 4 As or Os, ignore the extras, because 4 is the maximum value on the table.
- For this task, Y is not a vowel - only A, E, I, O and U.

The Challenge

Your task is to create a full program which takes one input, a word in baby-speak, and prints it in plaintext.

Your program must be able to take input in uppercase, lowercase, and a mix of both.

The input will only contain ASCII alphabet letters (A-Z and a-z), with single spaces to seperate the baby words.

The output text can be in any case.

You should the take the input from STDIN and print the plaintext on STDOUT. If your language does not have these, use the nearest equivalent.

This is code-golf, so the shortest code in bytes wins - but any solution is welcome.

Test Cases

```<code>'GLOOG KAKAAOOO ARGOOO OOOOOGUGUU' -> CODE
'oaka pooopaa gaau augu' -> GOLF
'Aoao U oOOAoa oaoAoo aoAoAOa' -> NAPPY
'GUG gAGaA gOougOou' -> ALE
'OOaGOG GoGOOoGoU gAA bLAA GOUGoOUgAIGAI' -> HELLO
</code>```

答:
Perl, 159 +1 = 160 bytes

+1 byte for -n flag.  Whitespace is not part of the code and is only provided for readability.

```<code>for(split$",lc){
    $b=0;
    @a=sort/([ao](?=[aeiou])|(?<=[aeiou])[ao])/g;
    $b++until$b>$#a||$a[$b]eq o;
    $c=($d=$#a-$b+1)>4?4:$d;
    $b=$b>4?4:$b;
    print+(a..i,k..z)[5*$b+$c];
}
</code>```

The code splits the input by spaces and converts each baby word to lowercase before proceeding.  The regex finds all a or o vowels that are followed by another vowel, or are preceeded by a vowel, and sorts them, a's at the start, o's at the end, then finds the index of the first 'o'.  If the remaining number of matches (aka, the number of 'a's) is greater than 4, then we care about 4 a's, and if there are more than 4 o's, we care about 4 o's.  Then it pulls the appropriate letter out of the matrix and prints it, then moves onto the next baby word.

Title: Decode Baby-talk!

Body:
Perl, 159 +1 = 160 bytes

+1 byte for -n flag.  Whitespace is not part of the code and is only provided for readability.

for(split$",lc){
    $b=0;
    @a=sort/([ao](?=[aeiou])|(?<=[aeiou])[ao])/g;
    $b++until$b>$#a||$a[$b]eq o;
    $c=($d=$#a-$b+1)>4?4:$d;
    $b=$b>4?4:$b;
    print+(a..i,k..z)[5*$b+$c];
}

The code splits the input by spaces and converts each baby word to lowercase before proceeding.  The regex finds all a or o vowels that are followed by another vowel, or are preceeded by a vowel, and sorts them, a's at the start, o's at the end, then finds the index of the first 'o'.  If the remaining number of matches (aka, the number of 'a's) is greater than 4, then we care about 4 a's, and if there are more than 4 o's, we care about 4 o's.  Then it pulls the appropriate letter out of the matrix and prints it, then moves onto the next baby word.


问:
Positional Bathroom Etiquette

Background

Bathroom Etiquette, when pertaining to the available urinals, states that the next urinal to be filled in should be the one that minimizes the total discomfort. The total discomfort equation is given by the following set of equations:

```
<b>dist(x,y)</b> = linear distance between person x and person y in Urinal Units
<b>discomfort(x)</b> = sum(1/(dist(x,y)*dist(x,y))) for all persons y excluding person x
<b>total_Discomfort</b> = sum(discomfort(x)) for all x
```

A more in depth paper dealing with a similar (not the exact same) problem can be found here: (Thanks to @Lembik for alerting me to this amazing whitepaper!)

Input/Output

Given an input of a empty and full urinals, output the resulting set of urinals with the addition of one person. If there is a tie for a position the urinals should fill in left to right. The output should be in the same format as the input.

If given a case with full urinals, return the input.

The input will always have at least one urinal defined.

Test Cases

```
<b>INPUT     -> OUTPUT</b>
1000001   -> 1001001
101010101 -> 111010101
100       -> 101
00000     -> 10000
1111111   -> 1111111
0100      -> 0101
101000    -> 101001
```

Rules

This is code-golf, so shortest code in bytes wins. Standard loop-holes are forbidden.

答:
MATL, <s>19</s> <s>18</s> 17 bytes

```<code>lyf!Gn:-H_^Xs&X<(
</code>```

Try it online! Or verify all test cases (slightly modified code).

Explanation

It suffices to compute the distance from each potential new position to the already occupied ones. The remaining distances are do not depend on the potential new position, and so constitute a constant term, which can be ignored.

Let's take input [1 0 0 0 0 0 1] as an example.

```<code>l      % Push 1
       % STACK: 1
y      % Take input implicitly. Duplicate from below
       % STACK: [1 0 0 0 0 0 1], 1, [1 0 0 0 0 0 1]
f!     % Indices of nonzero elements, as a column array
       % STACK: [1 0 0 0 0 0 1], 1, [1 7]
Gn:    % Push [1 2 ... n], where n is input size (array of possible positions)
       % STACK: [1 0 0 0 0 0 1], 1, [1; 7], [1 2 3 4 5 6 7]
-      % Matrix with all pairs of differences
       % STACK: [1 0 0 0 0 0 1], 1, [1; 7], [0 -1 -2 -3 -4 -5 -6;
                                             6  5  4  3  2  1  0]
H_^    % Raise each entry to -2
       % STACK: [1 0 0 0 0 0 1], 1, [   Inf 1.0000 0.2500 0.1111 0.0625 0.0400 0.0278;
                                     0.0278 0.0400 0.0625 0.1111 0.2500 1.0000    Inf]
Xs     % Sum of each column
       % STACK: [1 0 0 0 0 0 1], 1, [Inf 1.04 0.3125 0.2222 0.3125 1.04 Inf]
&X<    % Index of minimum. Takes the first if there is a tie
       % STACK: [1 0 0 0 0 0 1], 1, 4
(      % Assign: write 1 at the position of the minimizer
       % STACK: [1 0 0 1 0 0 1]
       % Implicitly display
</code>```

Title: Positional Bathroom Etiquette

Body:
MATL, <s>19</s> <s>18</s> 17 bytes

lyf!Gn:-H_^Xs&X<(

Try it online! Or verify all test cases (slightly modified code).

Explanation

It suffices to compute the distance from each potential new position to the already occupied ones. The remaining distances are do not depend on the potential new position, and so constitute a constant term, which can be ignored.

Let's take input [1 0 0 0 0 0 1] as an example.

l      % Push 1
       % STACK: 1
y      % Take input implicitly. Duplicate from below
       % STACK: [1 0 0 0 0 0 1], 1, [1 0 0 0 0 0 1]
f!     % Indices of nonzero elements, as a column array
       % STACK: [1 0 0 0 0 0 1], 1, [1 7]
Gn:    % Push [1 2 ... n], where n is input size (array of possible positions)
       % STACK: [1 0 0 0 0 0 1], 1, [1; 7], [1 2 3 4 5 6 7]
-      % Matrix with all pairs of differences
       % STACK: [1 0 0 0 0 0 1], 1, [1; 7], [0 -1 -2 -3 -4 -5 -6;
                                             6  5  4  3  2  1  0]
H_^    % Raise each entry to -2
       % STACK: [1 0 0 0 0 0 1], 1, [   Inf 1.0000 0.2500 0.1111 0.0625 0.0400 0.0278;
                                     0.0278 0.0400 0.0625 0.1111 0.2500 1.0000    Inf]
Xs     % Sum of each column
       % STACK: [1 0 0 0 0 0 1], 1, [Inf 1.04 0.3125 0.2222 0.3125 1.04 Inf]
&X<    % Index of minimum. Takes the first if there is a tie
       % STACK: [1 0 0 0 0 0 1], 1, 4
(      % Assign: write 1 at the position of the minimizer
       % STACK: [1 0 0 1 0 0 1]
       % Implicitly display


答:
C, 66 bytes

Typical C omissions with regard to declarations, header files, and return statements. This actually works for any number of decimal integers (up to the limitations of one's shell), including none. The program can be invoked with ./a.out 1 2 [...], as an example.

main(c,v,x)char**v;{x=0;while(c-1)x+=atoi(v[--c]);printf("%d",x);}

Or, more legibly:

```<code>main(c,v,x) char**v; {
    x=0;
    while(c-1) x+=atoi(v[--c]);
    printf("%d",x);
}
</code>```

Title: Add two numbers

Body:
Input: Two integers. Preferably decimal integers, but other forms of numbers can be used. These can be given to the code in standard input, as arguments to the program or function, or as a list.

Output: Their sum. Use the same format for output integers as input integers. For example, the input 5 16 would lead to the output 21.

Restrictions: No standard loopholes please. This is code-golf, answer in lowest amount of bytes wins.

Notes: This should be fairly trivial, however I'm interested to see how it can be implemented. The answer can be a complete program or a function, but please identify which one it is.

Test cases:

```<code>1 2 -> 3
14 15 -> 29
7 9 -> 16
-1 8 -> 7
8 -9 -> -1
-8 -9 -> -17
</code>```

Or as CSV:

```<code>a,b,c
1,2,3
14,15,29
7,9,16
-1,8,7
8,-9,-1
-8,-9,-17
</code>```

Leaderboard

var QUESTION_ID=84260,OVERRIDE_USER=8478;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:
C, 66 bytes

Typical C omissions with regard to declarations, header files, and return statements. This actually works for any number of decimal integers (up to the limitations of one's shell), including none. The program can be invoked with ./a.out 1 2 [...], as an example.

main(c,v,x)char**v;{x=0;while(c-1)x+=atoi(v[--c]);printf("%d",x);}

Or, more legibly:

main(c,v,x) char**v; {
    x=0;
    while(c-1) x+=atoi(v[--c]);
    printf("%d",x);
}


答:
JavaScript (ES6), 89 bytes

```<code>a=>a[a.map((e,i)=>!e&&(t=0,a.map((e,j)=>t+=(j-=i)&&e/j/j),t<m&&(m=t,k=i)),k=0,m=1/0),k]=1
</code>```

Outputs by modifying the input array.

Title: Positional Bathroom Etiquette

Body:
Background

Bathroom Etiquette, when pertaining to the available urinals, states that the next urinal to be filled in should be the one that minimizes the total discomfort. The total discomfort equation is given by the following set of equations:

```
<b>dist(x,y)</b> = linear distance between person x and person y in Urinal Units
<b>discomfort(x)</b> = sum(1/(dist(x,y)*dist(x,y))) for all persons y excluding person x
<b>total_Discomfort</b> = sum(discomfort(x)) for all x
```

A more in depth paper dealing with a similar (not the exact same) problem can be found here: (Thanks to @Lembik for alerting me to this amazing whitepaper!)

Input/Output

Given an input of a empty and full urinals, output the resulting set of urinals with the addition of one person. If there is a tie for a position the urinals should fill in left to right. The output should be in the same format as the input.

If given a case with full urinals, return the input.

The input will always have at least one urinal defined.

Test Cases

```
<b>INPUT     -> OUTPUT</b>
1000001   -> 1001001
101010101 -> 111010101
100       -> 101
00000     -> 10000
1111111   -> 1111111
0100      -> 0101
101000    -> 101001
```

Rules

This is code-golf, so shortest code in bytes wins. Standard loop-holes are forbidden.

Body:
JavaScript (ES6), 89 bytes

a=>a[a.map((e,i)=>!e&&(t=0,a.map((e,j)=>t+=(j-=i)&&e/j/j),t<m&&(m=t,k=i)),k=0,m=1/0),k]=1

Outputs by modifying the input array.


Title: Produce Dürer's magic square

Body:
The challenge

Output an array or string representation of Dürer's famous magic square:

that is,

```<code>16  3  2 13
 5 10 11  8
 9  6  7 12
 4 15 14  1
</code>```

Some properties of this square, which can perhaps be exploited, are:

It contains each integer from 1 to 16 exactly once

The sum of each column or row, as well as the the sum of each of the two diagonals, is the same. This is the defining property of a magic square. The sum is the magic constant of the square.

In addition, for this particular square, the sum of each of the four quadrants also equals the magic constant, as do the sum of the center four squares and the sum of the corner four squares.

Rules

Bultins that generate magic squares are not allowed (such as Matlab's magic or Mathematica's MagicSquare). Any other builtin can be used.

The code can be a program or a function.

There is no input.

The numbers must be in base 10. The output format is flexible as usual. Some possibilities are:

A nested array (either function output, or its string representation, with or without separators, any type of matching brackets):

```<code>[[16, 3, 2, 13], [5, 10, 11, 8], [9, 6, 7, 12], [4, 15, 14, 1]]
</code>```

A 2D array:

```<code>{16, 3, 2, 13; 5, 10, 11, 8; 9, 6, 7, 12; 4, 15, 14, 1}
</code>```

An array of four strings, or a string consisting of four lines. The numbers may be right-aligned

```<code>16  3  2 13
 5 10 11  8
 9  6  7 12
 4 15 14  1
</code>```

or left-aligned

```<code>16 3  2  13
5  10 11  8
9  6  7  12
4  15 14  1
</code>```

A string with two different separators for row and column, such as

```<code>16,3,2,13|5,10,11,8|9,6,7,12|4,15,14,1
</code>```

The output format should clearly differentiate rows and columns. For example, it is not allowed to output a flat array, or a string with all numbers separated by spaces.

Code golf. Shortest wins.

Body:
J, <s>37</s> 27 bytes

Saved 10 bytes thanks to miles!

4 4$1+19800593106059 A.i.16

Now with less boring! This takes the 19800593106059 permutation of the list i.16, which is 15 2 1 12 4 9 10 7 8 5 6 11 3 14 13 0. Then, that is incremented, then is shaped into a 4 by 4 list.

Alternate version, with no whitespace:

_4]\1+19800593106059&A.i.16

Output, for posterity:

   _4]\1+19800593106059&A.i.16
16  3  2 13
 5 10 11  8
 9  6  7 12
 4 15 14  1
   4 4$1+19800593106059 A.i.16
16  3  2 13
 5 10 11  8
 9  6  7 12
 4 15 14  1