答:
Retina, 42 bytes

```<code>\d+
$*
T`1p`-_` |-1+
+`.\b.

^(-)?.*
$1$.&
</code>```

Try it online!

Explanation

Adding numbers in unary is the easiest thing in the world, but once you introduce negative numbers, things get fiddly...

```<code>\d+
$*
</code>```

We start by converting the numbers to unary. This is done by matching each number with \d+ and replacing it with $*. This is a Retina-specific substitution feature. The full syntax is count$*character and inserts count copies of character. Both of those can be omitted where count defaults to $& (i.e. the match itself) and character defaults to 1. So for each input n we get n ones, and we still have potential minus signs in there, as well as the space separator. E.g. input 8 -5 gives:

```<code>11111111 -11111
</code>```

Now in order to deal with negative numbers it's easiest to use a separate -1 digit. We'll use - for that purpose.

```<code>T`1p`-_` |-1+
</code>```

This stage does two things. It gets rid of the space, the leading minus signs, and turns the 1s after a minus sign into - themselves. This is done by matching  |-1+ (i.e. either a space or a negative number) and performing a transliteration on it. The transliteration goes from 1p to -_, but here, p expands to all printable ASCII characters and _ means delete. So 1s in those matches get turned into -s and minuses and spaces get removed. Our example now looks like this:

```<code>11111111-----
</code>```

```<code>+`.\b.

</code>```

This stage handles the case where there's one positive and one negative number in the input. If so, there will be 1s and -s in the string and we want them to cancel. This is done by matching two characters with a word-boundary between them (since 1s is considered a word character and - isn't), and replacing the match with nothing. The + instructs Retina to do this repeatedly until the string stops changing.

Now we're left with only 1s or only -s.

```<code>^(-)?.*
$1$.&
</code>```

To convert this back to decimal, we match the entire input, but if possible we capture a - into group 1. We write back group 1 (to prepend a - to negative numbers) and then we write back the length of the match with $.& (also a Retina-specific substitution feature).

Title: Add two numbers

Body:
Retina, 42 bytes

\d+
$*
T`1p`-_` |-1+
+`.\b.

^(-)?.*
$1$.&

Try it online!

Explanation

Adding numbers in unary is the easiest thing in the world, but once you introduce negative numbers, things get fiddly...

\d+
$*

We start by converting the numbers to unary. This is done by matching each number with \d+ and replacing it with $*. This is a Retina-specific substitution feature. The full syntax is count$*character and inserts count copies of character. Both of those can be omitted where count defaults to $& (i.e. the match itself) and character defaults to 1. So for each input n we get n ones, and we still have potential minus signs in there, as well as the space separator. E.g. input 8 -5 gives:

11111111 -11111

Now in order to deal with negative numbers it's easiest to use a separate -1 digit. We'll use - for that purpose.

T`1p`-_` |-1+

This stage does two things. It gets rid of the space, the leading minus signs, and turns the 1s after a minus sign into - themselves. This is done by matching  |-1+ (i.e. either a space or a negative number) and performing a transliteration on it. The transliteration goes from 1p to -_, but here, p expands to all printable ASCII characters and _ means delete. So 1s in those matches get turned into -s and minuses and spaces get removed. Our example now looks like this:

11111111-----

+`.\b.

This stage handles the case where there's one positive and one negative number in the input. If so, there will be 1s and -s in the string and we want them to cancel. This is done by matching two characters with a word-boundary between them (since 1s is considered a word character and - isn't), and replacing the match with nothing. The + instructs Retina to do this repeatedly until the string stops changing.

Now we're left with only 1s or only -s.

^(-)?.*
$1$.&

To convert this back to decimal, we match the entire input, but if possible we capture a - into group 1. We write back group 1 (to prepend a - to negative numbers) and then we write back the length of the match with $.& (also a Retina-specific substitution feature).


问:
What's the second non-repeating character?
Based on this question from Code Review

Given a non-empty string of printable ASCII characters, output the second non-repeating character. For example, for input DEFD, output F.

Input

A single string, in any suitable format.

Output

The second character that doesn't repeat, when reading left-to-right, again in a suitable format.

The output character is case-insensitive.

If no such character exists (e.g., all characters repeat), output an empty string.

Rules

The algorithm should ignore case. That is, D and d count as the same character.

Either a full program or a function are acceptable.

The input string will be guaranteed non-empty (i.e., at least one character in length).

The input string is ASCII. Any valid character could repeat, not just alphanumeric (this includes spaces).

Standard loopholes are forbidden.

This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.

Examples

Input is on first line, output is on second line.

```<code>DEFD
F

FEED
D

This is an example input sentence.
x

...,,,..,,!@
@

ABCDefgHijklMNOPqrsTuVWxyz
B

AAAAAABBBBB

Thisxthis

This this.
.
</code>```

答:
C#, 129 128 bytes

```<code>char c(string i){var s=i.Where((n,m)=>i.ToLower().Where(o=>o==Char.ToLower(n)).Count()<2).ToArray();return s.Length>1?s[1]:' ';}
</code>```

works fine.
I wish i didnt need to lowercase everything

ContentLicense: CC BY-SA 3.0

Body:
C#, 129 128 bytes

char c(string i){var s=i.Where((n,m)=>i.ToLower().Where(o=>o==Char.ToLower(n)).Count()<2).ToArray();return s.Length>1?s[1]:' ';}

works fine.
I wish i didnt need to lowercase everything


问:
I hate Mondays!
You should a program in language X, which will only output its source code (i.e function as a quine) when it is not a monday. On monday it should output some string with a levehnstein distance of 4 from the source code. i.e if the code is aaaa on sunday it should output aaaa and on monday it could output ....aaaa or bbbb or cccc or ..aaaa.. etc

Read about Levehnstein difference here https://en.wikipedia.org/wiki/Levenshtein_distance

Rules

Your solution must be testable

No cheating quines, and any other standard loopholes allowed

Should your language "X" lack access to the date it may assume its a random date at the cost of 35 bytes

This is code golf and I will accept the shortest solution (in bytes) as winner

答:
GolfScript, <s>21</s> 20 + 35 = <s>56</s> 55 bytes (or <s>22 + 0 = 22</s> 20)

With randomizing, no input expected (following the rules completely):

```<code>{7rand 0=2*)".~"*}.~
</code>```

Alternatively, date as input, in format like Javascript's new Date().toString() (bending the rules a little):

```<code>{\.,%"M"=2*)".~"*}.~
</code>```

Each solution looks like this:

```<code>{somecode2*)".~"*}.~

{                }    create a block
                  .   duplicate it
                   ~  execute one copy
 somecode             push 1 if monday or 0 otherwise
         2*           multiply by 2 (2 if monday, 0 otherwise)
           )          add 1 (3 if monday, 1 otherwise)
            ".~"      the tail...
                *     ...copied 1 or 3 times and concatenated together
</code>```

Now the stack looks like this:

```<code>.~  (or .~.~.~)
{somecode2*)".~"*}
</code>```

... and is printed bottom to top.

The somecode part for random:

```<code>7rand 0=

7rand          select a random number from 0 to 6, let 0 be monday
      0=       check if equal to 0 (1 if monday, 0 otherwise)
</code>```

The somecode part for input:

```<code>\.,%"M"=
\             we have the input first and the block on top, so we need to swap them
 .            duplicate the input
  ,           replace the second copy with its length
   %          get every (length)-th character starting from 0, effectively fetching first (M on mondays, something else otherwise)
    "M"=      check if equal to M (1 on mondays, 0 otherwise)
</code>```

Title: I hate Mondays!

Body:
GolfScript, <s>21</s> 20 + 35 = <s>56</s> 55 bytes (or <s>22 + 0 = 22</s> 20)

With randomizing, no input expected (following the rules completely):

{7rand 0=2*)".~"*}.~

Alternatively, date as input, in format like Javascript's new Date().toString() (bending the rules a little):

{\.,%"M"=2*)".~"*}.~

Each solution looks like this:

{somecode2*)".~"*}.~

{                }    create a block
                  .   duplicate it
                   ~  execute one copy
 somecode             push 1 if monday or 0 otherwise
         2*           multiply by 2 (2 if monday, 0 otherwise)
           )          add 1 (3 if monday, 1 otherwise)
            ".~"      the tail...
                *     ...copied 1 or 3 times and concatenated together

Now the stack looks like this:

.~  (or .~.~.~)
{somecode2*)".~"*}

... and is printed bottom to top.

The somecode part for random:

7rand 0=

7rand          select a random number from 0 to 6, let 0 be monday
      0=       check if equal to 0 (1 if monday, 0 otherwise)

The somecode part for input:

\.,%"M"=
\             we have the input first and the block on top, so we need to swap them
 .            duplicate the input
  ,           replace the second copy with its length
   %          get every (length)-th character starting from 0, effectively fetching first (M on mondays, something else otherwise)
    "M"=      check if equal to M (1 on mondays, 0 otherwise)


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

```

答:
PHP 4.1, 9 bytes

This assumes a standard php.ini file, with short_open_tag=On and register_globals=On (default in PHP 4.1).

```<code><?=$A+$B;
</code>```

This assumes that you are acessing the file through a webserver (like Apache).

The keys A and B contain the numbers you want to sum.

An example: http://localhost/sum.php?A=5&B=16. (POST, GET, SESSION and COOKIE can be used too).

Title: Add two numbers

Body:
PHP 4.1, 9 bytes

This assumes a standard php.ini file, with short_open_tag=On and register_globals=On (default in PHP 4.1).

<?=$A+$B;

This assumes that you are acessing the file through a webserver (like Apache).

The keys A and B contain the numbers you want to sum.

An example: http://localhost/sum.php?A=5&B=16. (POST, GET, SESSION and COOKIE can be used too).


答:
C# lambda with Linq, 63 bytes

```<code>s=>(s=s.ToUpper()).Where(c=>s.Count(C=>c==C)<2).Skip(1).First()
</code>```

Title: What's the second non-repeating character?

Body:
Based on this question from Code Review

Given a non-empty string of printable ASCII characters, output the second non-repeating character. For example, for input DEFD, output F.

Input

A single string, in any suitable format.

Output

The second character that doesn't repeat, when reading left-to-right, again in a suitable format.

The output character is case-insensitive.

If no such character exists (e.g., all characters repeat), output an empty string.

Rules

The algorithm should ignore case. That is, D and d count as the same character.

Either a full program or a function are acceptable.

The input string will be guaranteed non-empty (i.e., at least one character in length).

The input string is ASCII. Any valid character could repeat, not just alphanumeric (this includes spaces).

Standard loopholes are forbidden.

This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.

Examples

Input is on first line, output is on second line.

```<code>DEFD
F

FEED
D

This is an example input sentence.
x

...,,,..,,!@
@

ABCDefgHijklMNOPqrsTuVWxyz
B

AAAAAABBBBB

Thisxthis

This this.
.
</code>```

Body:
C# lambda with Linq, 63 bytes

s=>(s=s.ToUpper()).Where(c=>s.Count(C=>c==C)<2).Skip(1).First()


答:
PowerShell v2+, 17 bytes

```<code>$args-join'+'|iex
</code>```

Takes input as two separate command-line arguments, which get pre-populated into the special array $args. We form a string with the -join operator by concatenating them together with a + in the middle, then pipe that string to Invoke-Expression (similar to eval).

Thanks to @DarthTwon for reminding me that when dealing with such minimal programs, there are multiple methods of taking input all at the same byte-count.

```<code>$args[0]+$args[1]
param($a,$b)$a+$b
</code>```

PowerShell is nothing if not flexible.

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:
PowerShell v2+, 17 bytes

$args-join'+'|iex

Takes input as two separate command-line arguments, which get pre-populated into the special array $args. We form a string with the -join operator by concatenating them together with a + in the middle, then pipe that string to Invoke-Expression (similar to eval).

Thanks to @DarthTwon for reminding me that when dealing with such minimal programs, there are multiple methods of taking input all at the same byte-count.

$args[0]+$args[1]
param($a,$b)$a+$b

PowerShell is nothing if not flexible.


问:
Distinct Sieves
Given a list of integers, create a boolean mask such that the true indices can be used to filter the distinct values from the list. Which index is selected as the true one does not matter as long as only one of them is selected for each set of indices corresponding to identical values.

The input will be a non-empty list of non-negative integers in a format suitable for your language and the output will be a list of boolean values following the specification above. You are allowed to use your own definitions of truthy and falsy values in the output list.

In my examples below, I define 1 to be truthy and 0 to be falsy.

```<code>[5, 4, 7, 1]  Input
[1, 1, 1, 1]  Output
              Select only the values with with true indicies in the sieve
[5  4  7  1]  Contains zero duplicate values

[5, 9, 7, 5, 6, 0, 5]
[0, 1, 1, 1, 1, 1, 0]
[   9, 7, 5, 6, 0   ]
</code>```

Test Cases

When there is an or, it means that there are multiple valid outputs. If there is a trailing ellipsis ... after the or, it means that not all of the possible outputs were listed.

```<code>[0] = [1]

[55] = [1]

[32, 44] = [1, 1]

[0, 0] = [1, 0] or [0, 1]

[9001, 9001, 9001] = [1, 0 , 0] or [0, 1, 0] or [0, 0, 1]

[5, 4, 7, 1] = [1, 1, 1, 1]

[1, 2, 3, 4, 3, 5] = [1, 1, 1, 1, 0, 1] or
                     [1, 1, 0, 1, 1, 1]

[5, 9, 7, 5, 6, 0, 5] = [1, 1, 1, 0, 1, 1, 0] or
                        [0, 1, 1, 1, 1, 1, 0] or
                        [0, 1, 1, 0, 1, 1, 1]

[0, 8, 6, 6, 3, 8, 7, 2] = [1, 1, 1, 0, 1, 0, 1, 1] or
                           [1, 0, 0, 1, 1, 1, 1, 1] or
                           [1, 0, 1, 0, 1, 1, 1, 1] or
                           [1, 1, 0, 1, 1, 0, 1, 1]

[45, 47, 47, 45, 24, 24, 24, 8, 47, 41, 47, 88]
= [1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1] or ...

[154, 993, 420, 154, 154, 689, 172, 417, 790, 175, 790, 790, 154, 172, 175, 175, 420, 417, 154, 175, 172, 175, 172, 993, 689, 993, 993, 790]
= [1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] or ...
</code>```

Rules

This is code-golf so the shortest solution wins.

Builtins are allowed!

You are allowed to use your own definitions of truthy and falsy values in the output list. If you choose to do so, please state your definitions.

The input will be a non-empty list of non-negative integers.

You are free to choose between outputting only one of the sieves or multiple or even all of them. As long as each sieve is valid, it will be accepted.

答:
PowerShell v2+, 40 bytes

```<code>$a=@();$args[0]|%{(1,0)[$_-in$a];$a+=$_}
</code>```

Creates an empty array $a. Then we take the input list via $args[0] and pipe that into a loop |%{...}. Each iteration we select either 1 or 0 from a pseudo-ternary based on whether the current element is in $a or not. Those selections are left on the pipeline. We then add the current element into the array $a. The pipeline elements are gathered up, and output as an array is implicit.

Example:

(output here with a newline separator, since that's the default .ToString() for an array)

```<code>PS C:\Tools\Scripts\golfing> .\distinct-sieves.ps1 1,2,3,4,1,3,5,7
1
1
1
1
0
0
1
1
</code>```

Title: Distinct Sieves

Body:
PowerShell v2+, 40 bytes

$a=@();$args[0]|%{(1,0)[$_-in$a];$a+=$_}

Creates an empty array $a. Then we take the input list via $args[0] and pipe that into a loop |%{...}. Each iteration we select either 1 or 0 from a pseudo-ternary based on whether the current element is in $a or not. Those selections are left on the pipeline. We then add the current element into the array $a. The pipeline elements are gathered up, and output as an array is implicit.

Example:

(output here with a newline separator, since that's the default .ToString() for an array)

PS C:\Tools\Scripts\golfing> .\distinct-sieves.ps1 1,2,3,4,1,3,5,7
1
1
1
1
0
0
1
1


答:
Python, 35 bytes

f=lambda l:l and[l.pop(0)in l]+f(l)
```

Uses True as the falsy value and False for the truthy value. Marks the last appearance of each element.

Selects the first element only if it doesn't appear among the remaining elements, then recurses to the rest of the list as long as it's non-empty. The l.pop(0) extracts the first element while also removing it.

Title: Distinct Sieves

Body:
Given a list of integers, create a boolean mask such that the true indices can be used to filter the distinct values from the list. Which index is selected as the true one does not matter as long as only one of them is selected for each set of indices corresponding to identical values.

The input will be a non-empty list of non-negative integers in a format suitable for your language and the output will be a list of boolean values following the specification above. You are allowed to use your own definitions of truthy and falsy values in the output list.

In my examples below, I define 1 to be truthy and 0 to be falsy.

```<code>[5, 4, 7, 1]  Input
[1, 1, 1, 1]  Output
              Select only the values with with true indicies in the sieve
[5  4  7  1]  Contains zero duplicate values

[5, 9, 7, 5, 6, 0, 5]
[0, 1, 1, 1, 1, 1, 0]
[   9, 7, 5, 6, 0   ]
</code>```

Test Cases

When there is an or, it means that there are multiple valid outputs. If there is a trailing ellipsis ... after the or, it means that not all of the possible outputs were listed.

```<code>[0] = [1]

[55] = [1]

[32, 44] = [1, 1]

[0, 0] = [1, 0] or [0, 1]

[9001, 9001, 9001] = [1, 0 , 0] or [0, 1, 0] or [0, 0, 1]

[5, 4, 7, 1] = [1, 1, 1, 1]

[1, 2, 3, 4, 3, 5] = [1, 1, 1, 1, 0, 1] or
                     [1, 1, 0, 1, 1, 1]

[5, 9, 7, 5, 6, 0, 5] = [1, 1, 1, 0, 1, 1, 0] or
                        [0, 1, 1, 1, 1, 1, 0] or
                        [0, 1, 1, 0, 1, 1, 1]

[0, 8, 6, 6, 3, 8, 7, 2] = [1, 1, 1, 0, 1, 0, 1, 1] or
                           [1, 0, 0, 1, 1, 1, 1, 1] or
                           [1, 0, 1, 0, 1, 1, 1, 1] or
                           [1, 1, 0, 1, 1, 0, 1, 1]

[45, 47, 47, 45, 24, 24, 24, 8, 47, 41, 47, 88]
= [1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1] or ...

[154, 993, 420, 154, 154, 689, 172, 417, 790, 175, 790, 790, 154, 172, 175, 175, 420, 417, 154, 175, 172, 175, 172, 993, 689, 993, 993, 790]
= [1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] or ...
</code>```

Rules

This is code-golf so the shortest solution wins.

Builtins are allowed!

You are allowed to use your own definitions of truthy and falsy values in the output list. If you choose to do so, please state your definitions.

The input will be a non-empty list of non-negative integers.

You are free to choose between outputting only one of the sieves or multiple or even all of them. As long as each sieve is valid, it will be accepted.

Body:
Python, 35 bytes

f=lambda l:l and[l.pop(0)in l]+f(l)

Uses True as the falsy value and False for the truthy value. Marks the last appearance of each element.

Selects the first element only if it doesn't appear among the remaining elements, then recurses to the rest of the list as long as it's non-empty. The l.pop(0) extracts the first element while also removing it.


答:
JavaScript (ES6), 31 bytes

```<code>f=a=>a.map((e,i)=>i-a.indexOf(e))
</code>```

Zero is truthy and other numbers are falsy.

Title: Distinct Sieves

Body:
JavaScript (ES6), 31 bytes

f=a=>a.map((e,i)=>i-a.indexOf(e))

Zero is truthy and other numbers are falsy.


答:
Retina, 23 bytes

```<code>(\d+)((?!.* \1\b))?
$#2
</code>```

Input is a space-separated list. (Actually, other formats like [1, 2, 3] will also work as long as there's a space in front of each number except the first.)

Try it online! (Works on multiple linefeed-separated test cases at once.)

We simply turn each element into 0 if there's another copy of it later on in the input and into 1 otherwise.

Title: Distinct Sieves

Body:
Retina, 23 bytes

(\d+)((?!.* \1\b))?
$#2

Input is a space-separated list. (Actually, other formats like [1, 2, 3] will also work as long as there's a space in front of each number except the first.)

Try it online! (Works on multiple linefeed-separated test cases at once.)

We simply turn each element into 0 if there's another copy of it later on in the input and into 1 otherwise.


答:
dc, 2 bytes

```<code>+f
</code>```

Adds top two items on stack (previously taken from stdin), then dumps the stack's contents to stdout.

EDIT: Upon further consideration, it seems there are several ways this might be implemented, depending on the desired I/O behaviour.

```<code>+        # adds top two items and pushes on stack
+n       # adds top two and prints it, no newline, popping it from stack
+dn      # ditto, except leaves result on stack
??+      # takes two inputs from stdin before adding, leaving sum on stack
</code>```

I suppose the most complete form for the sum would be this:

```<code>??+p     # takes two inputs, adds, 'peeks'
         #  (prints top value with newline and leaves result on stack)
</code>```

Wait! Two numbers can be taken on the same line, separated by a space! This gives us:

```<code>?+p
</code>```

Title: Add two numbers

Body:
dc, 2 bytes

+f

Adds top two items on stack (previously taken from stdin), then dumps the stack's contents to stdout.

EDIT: Upon further consideration, it seems there are several ways this might be implemented, depending on the desired I/O behaviour.

+        # adds top two items and pushes on stack
+n       # adds top two and prints it, no newline, popping it from stack
+dn      # ditto, except leaves result on stack
??+      # takes two inputs from stdin before adding, leaving sum on stack

I suppose the most complete form for the sum would be this:

??+p     # takes two inputs, adds, 'peeks'
         #  (prints top value with newline and leaves result on stack)

Wait! Two numbers can be taken on the same line, separated by a space! This gives us:

?+p


答:
Java, 334 characters

```<code>import java.util.Calendar;interface Q{static void main(String[]a){String p="import java.util.Calendar;interface Q{static void main(String[]a){String p=%c%s%1$c;System.out.printf(p,34,p);if(Calendar.getInstance().get(7)==2)System.out.print(0<1);}}";System.out.printf(p,34,p);if(Calendar.getInstance().get(7)==2)System.out.print(0<1);}}
</code>```

Based on @RohanJhunjhunwala 's solution, just using the quine method from over here. The difference of four comes by appending true if it's monday. I think it should be possible to shorten that a bit.

Title: I hate Mondays!

Body:
You should a program in language X, which will only output its source code (i.e function as a quine) when it is not a monday. On monday it should output some string with a levehnstein distance of 4 from the source code. i.e if the code is aaaa on sunday it should output aaaa and on monday it could output ....aaaa or bbbb or cccc or ..aaaa.. etc

Read about Levehnstein difference here https://en.wikipedia.org/wiki/Levenshtein_distance

Rules

Your solution must be testable

No cheating quines, and any other standard loopholes allowed

Should your language "X" lack access to the date it may assume its a random date at the cost of 35 bytes

This is code golf and I will accept the shortest solution (in bytes) as winner

Body:
Java, 334 characters

import java.util.Calendar;interface Q{static void main(String[]a){String p="import java.util.Calendar;interface Q{static void main(String[]a){String p=%c%s%1$c;System.out.printf(p,34,p);if(Calendar.getInstance().get(7)==2)System.out.print(0<1);}}";System.out.printf(p,34,p);if(Calendar.getInstance().get(7)==2)System.out.print(0<1);}}

Based on @RohanJhunjhunwala 's solution, just using the quine method from over here. The difference of four comes by appending true if it's monday. I think it should be possible to shorten that a bit.


问:
Can you Golf Golf?
You are required to generate a random 18-hole golf course.

Example output:

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

Rules:

Your program must output a list of hole lengths for exactly 18 holes

Each hole must have a length of 3, 4 or 5

The hole lengths must add up to 72 for the entire course

Your program must be able to produce every possible hole configuration with some non-zero-probability (the probabilities of each configuration need not be equal, but feel free to claim extra kudos if this is the case)

答:
Mathematica 71 68 66 60

With 6 chars saved by Tally's suggestion.

```<code>RandomSample@RandomChoice@IntegerPartitions[72, {18}, {3, 4, 5}]
</code>```

{5, 4, 3, 3, 5, 3, 5, 5, 3, 3, 4, 5, 3, 5, 4, 4, 5, 3}

All possible outcomes are possible, but they are not equally likely.

Analysis

```<code>IntegerPartitions[72, {18}, {3, 4, 5}]
</code>```

produces all 10 possible partitions (combinations, not permutations) of 72 into 18 elements consisting of 3's, 4's and 5's.

RandomChoice selects one of those.

RandomSample returns a permutation of that choice.

Title: Can you Golf Golf?

Body:
Mathematica 71 68 66 60

With 6 chars saved by Tally's suggestion.

RandomSample@RandomChoice@IntegerPartitions[72, {18}, {3, 4, 5}]

{5, 4, 3, 3, 5, 3, 5, 5, 3, 3, 4, 5, 3, 5, 4, 4, 5, 3}

All possible outcomes are possible, but they are not equally likely.

Analysis

IntegerPartitions[72, {18}, {3, 4, 5}]

produces all 10 possible partitions (combinations, not permutations) of 72 into 18 elements consisting of 3's, 4's and 5's.

RandomChoice selects one of those.

RandomSample returns a permutation of that choice.


答:
Fishing, 22 bytes

```<code>v+CCCCCCCC
  In{In}aP
</code>```

Explained

Sets casting direction down and casting length to 1.

Read input to the first 2 cells on the tape and convert to numbers.

Add the first 2 cells together and print.

Title: Add two numbers

Body:
Fishing, 22 bytes

v+CCCCCCCC
  In{In}aP

Explained

Sets casting direction down and casting length to 1.

Read input to the first 2 cells on the tape and convert to numbers.

Add the first 2 cells together and print.


答:
Batch, <s>25</s> <s>18</s> 16 bytes

```<code>@cmd/cset/a%1+%2
</code>```

Edit: saved <s>7</s> 9 bytes by using my trick from Alternating Sign Sequence.

Title: Add two numbers

Body:
Batch, <s>25</s> <s>18</s> 16 bytes

@cmd/cset/a%1+%2

Edit: saved <s>7</s> 9 bytes by using my trick from Alternating Sign Sequence.


答:
Mathematica, <s>53</s> 31 bytes

Thanks to miles for giving me an idea that saved 22 bytes.

```<code>s[[;;x++]]~FreeQ~#&/@(x=0;s=#)&
</code>```

Title: Distinct Sieves

Body:
Mathematica, <s>53</s> 31 bytes

Thanks to miles for giving me an idea that saved 22 bytes.

s[[;;x++]]~FreeQ~#&/@(x=0;s=#)&


问:
Parse and Process the Key-Language Input
Let's parse and process Key-Language! Given the input of a sequence of keyboard keypresses and/or special keys, write a program, function, etc. that outputs the product when all the actions are processed based on the following keyboard:

```<code>+-------------------------------------------------------+
| ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | - | + |   |
| ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | _ | = |Del|
+-------------------------------------------------------+
|TAB| q | w | e | r | t | y | u | i | o | p | [ | ] | \ |
|   | Q | W | E | R | T | Y | U | I | O | P | { | } | | |
+-------------------------------------------------------+
|CAPS | a | s | d | f | g | h | j | k | l | ; | ' | RET |
|     | A | S | D | F | G | H | J | K | L | : | " |     |
+-------------------------------------------------------+
| SHIFT | z | x | c | v | b | n | m | , | . | / | SHIFT |
|       | Z | X | C | V | B | N | M | < | > | ? |       |
+-------------------------------------------------------+
|                                                       |
|                      SPACEBAR                         |
+-------------------------------------------------------+
</code>```

The keys that output actual characters not consisting of whitespace and are able to be modified by other keys will be known as "character keys", and those that modify the output of other keys or output whitespace will be known as "special keys". The alphabet character keys, which will be shown in the input with uppercase letters, can be modified with either Shift or Caps Lock to produce uppercase letters, and the rest of the character keys can only be modified with Shift to produce their alternate characters. Therefore A in the input corresponds to the a A character key, whose normal output is a and whose modified output, obtainable with either the Shift or Caps Lock key, is A. On the other hand, /, which corresponds to the / ? character key, has a normal  output of / and a modified output of ? obtainable with only with Shift this time.

Rules

The input will always be a string consisting of a sequence of the character keys and special keys. The full special key to string mapping for the input (i.e. the format they are guaranteed to be in the input) and their corresponding actions/outputs are as follows:

 -> Delete the previous character (including whitespace). If called when string is empty, nothing happens. If called 2 or more times in a row, 2 consecutive deletes happen. For instance, "RE" should return an empty string ("") and also "R<RET>E" should return just "E".

<CAPS> -> Enable Caps Lock until <CAPS> appears again, upon which it is disabled, although it is not guaranteed to be disabled by the end of the input. Enabling this only modifies the upcoming alphabet keys resulting in them outputting only uppercase letters. For instance, "<CAPS>RE<CAPS>" results in the output "RE", but <CAPS>.<CAPS> would still result in a ".".

<RET> -> Add a new line.

<SPC> -> Add a single blank space.

<TAB> -> Add 4 spaces.

<SHFT> -> Shift is held down resulting in the alternate character of the upcoming keypress to be output, after which the key is released. For instance, "<SHFT>A" results in the output "A", "<SHFT>1" results in the output "!", and "<SHFT>1234" results in the output "!234" as only the first upcoming keypress is modified and nothing else. It is guaranteed that a character key will succeed a <SHFT>. Therefore, <SHFT><SPC> is not a possible input.

An empty string is also possible as input, for which the output should be nothing.

The use of any built-in that solves this problem directly is disallowed.

The use of standard loopholes is disallowed.

Test Cases

Presented in the format Actual String Input -> Actual String Output followed by an explanation for a few.

1<SHFT>2<TAB><CAPS>R.KAP.<SPC><SHFT>123 -> 1@    R.KAP. !23

Output 1 as the 1 key is pressed without a toggle, then Shift is held down and the 2 key is pressed resulting in the @ output. Then the Shift key is released and Tab is pressed, resulting in a 4 spaced indentation. Following up, the Caps Lock key is pressed, after which the R,.,K,A,P, and . keys are pressed, resulting in the output R.KAP.. Finally, a single space is output followed by shift resulting in !23 being output when the 1,2, and 3 keys are pressed at the end.

<SHFT>ABCDEFG<SHFT>HIJK<SHFT>1<SHFT>2<SHFT>3<SHFT>4567890 -> AbcdefgHijk!@#$567890

The Shift key is held down followed by the A key, resulting in the output A followed by the output bcdefg when the B-G keys are pressed. Then, the Shift key is held down again succeeded by the H key, after which the output is H, followed by ijk when the I-K keys are pressed. Finally, the 1-4 keys are all modified as shift is held down before each keypress resulting in the output !@#$ finished off by 567890 when the 5-0 keys re pressed.

<CAPS>THIS<SPC>IS<SPC>IN<SPC>ALL<SPC>CAPS<CAPS><SPC>NOW<SPC>THIS<SPC>IS<SPC>IN<SPC>ALL<SPC>LOWERCASE -> THIS IS IN ALL CAPS now this is in all lowercase

<TAB><SPC><TAB><SHFT>1 ->          !

<CAPS>WWW<CAPS>.CODEGOLF.STACKEXCHANGE<SHFT>.COM -> WWW.codegolf.stackexchange>com

PROGRAMMING<CAPS><SPC>IS<SPC><CAPS>AWESOME -> programming IS awesome

<RET><RET> -> "" (Empty String)

The delete key is pressed in the beginning after which nothing happens. Then, the Return key is pressed resulting in a new line, which is deleted after the backspace key is pressed again. Finally, the same sequence (new line followed by backspace) is repeated. After all this, the output is an empty string.

<SHFT>HI<SPC>HOW<SPC>ARE<SPC>YOU<SHFT>/<RET><SHFT>I<SPC><SHFT>AM<SPC>O<SHFT>GOOD<SHFT>1 -> Hi how are you?\nI Am Good!

<SHFT>,<CAPS>RET<CAPS><SHFT>. -> <RET>

The string <RET> should be the actual string output. Thus, this should not output a new line.

<CAPS>67890,.;'[]<CAPS> -> 67890,.;'[]

<CAPS><SHFT>A -> A

RE -> "" (Empty String)

U<RET>I -> i

5 -> "" (Empty string)

"" (Empty String) -> "" (Empty String)

This is codegolf so the shortest code in bytes wins!

答:
JavaScript (ES6), 207

Updated to fix the bug with repeated deletes, even some bytes shorter.

s=>s.replace(/<\w+>|./g,x=>(k=x[3])=='L'?o=o.slice(0,-1):k=='P'?l=!l:k=='F'?s=0:o+=k?k<'C'?'    ':k<'D'?' ':`
`:s?l?x.toLowerCase():x:s=")!@#$%^&*("[x]||'_={}|:"<>?'["-+[]\\;',./".indexOf(x)]||x,l=s,o='')&&o
```
<p><em>less golfed</em></p>
<pre class="lang-js prettyprint-override"><code>s=>s.replace( /<\w+>|./g, x =>
  (k=x[3]) == 'L' ? o = o.slice(0,-1)
  : k == 'P' ? l = !l
  : k == 'F' ? s = 0
  : o+= k ? k < 'C' ? '    ' : k < 'D' ? ' ' : '\n'
  : s ? l ? x.toLowerCase() : x
  : s = ")!@#$%^&*("[x] || '_={}|:"<>?' ["-+[]\\;',./".indexOf(x)] || x,
  l = s, o = ''
) && o
</code>```

Test

F=
s=>s.replace(/<\w+>|./g,x=>(k=x[3])=='L'?o=o.slice(0,-1):k=='P'?l=!l:k=='F'?s=0:o+=k?k<'C'?'    ':k<'D'?' ':`
`:s?l?x.toLowerCase():x:s=")!@#$%^&*("[x]||'_={}|:"<>?'["-+[]\\;',./".indexOf(x)]||x,l=s,o='')&&o

console.log=(...x)=>O.textContent+=x.join` `+'\n'

;[["1<SHFT>2<TAB><CAPS>R.KAP.<SPC><SHFT>123", "1@    R.KAP. !23"]
,["<SHFT>ABCDEFG<SHFT>HIJK<SHFT>1<SHFT>2<SHFT>3<SHFT>4567890", "AbcdefgHijk!@#$567890"]
,["<CAPS>THIS<SPC>IS<SPC>IN<SPC>ALL<SPC>CAPS<CAPS><SPC>NOW<SPC>THIS<SPC>IS<SPC>IN<SPC>ALL<SPC>LOWERCASE", "THIS IS IN ALL CAPS now this is in all lowercase"]
,["<TAB><SPC><TAB><SHFT>1", "         !"]
,["<CAPS>WWW<CAPS>.CODEGOLF.STACKEXCHANGE<SHFT>.COM", "WWW.codegolf.stackexchange>com"]
,["PROGRAMMING<CAPS><SPC>IS<SPC><CAPS>AWESOME", "programming IS awesome"]
,["<RET><RET>", ""]
,["<SHFT>HI<SPC>HOW<SPC>ARE<SPC>YOU<SHFT>/<RET><SHFT>I<SPC><SHFT>AM<SPC>O<SHFT>GOOD<SHFT>1", "Hi how are you?\nI Am Good!"]
,["<SHFT>,<CAPS>RET<CAPS><SHFT>.", "<RET>"]
,["<CAPS>67890,.;'[]<CAPS>", "67890,.;'[]"]
,["<CAPS><SHFT>A", "A"]
,["U<RET>I", "i"]
,["RE", ""]
,["", ""]].forEach(t=>{
  var i=t[0],k=t[1],r=F(i)
  console.log(
    k==r?'OK':'KO',i,'\n->',r,k==r?'\n':'(should be ->'+k+')\n'
  )
})```
<pre class="snippet-code-html lang-html prettyprint-override"><code><pre id=O>``````

Body:
JavaScript (ES6), 207

Updated to fix the bug with repeated deletes, even some bytes shorter.

s=>s.replace(/<\w+>|./g,x=>(k=x[3])=='L'?o=o.slice(0,-1):k=='P'?l=!l:k=='F'?s=0:o+=k?k<'C'?'    ':k<'D'?' ':`
`:s?l?x.toLowerCase():x:s=")!@#$%^&*("[x]||'_={}|:"<>?'["-+[]\\;',./".indexOf(x)]||x,l=s,o='')&&o

less golfed

s=>s.replace( /<\w+>|./g, x =>
  (k=x[3]) == 'L' ? o = o.slice(0,-1)
  : k == 'P' ? l = !l
  : k == 'F' ? s = 0
  : o+= k ? k < 'C' ? '    ' : k < 'D' ? ' ' : '\n'
  : s ? l ? x.toLowerCase() : x
  : s = ")!@#$%^&*("[x] || '_={}|:"<>?' ["-+[]\\;',./".indexOf(x)] || x,
  l = s, o = ''
) && o

Test

F=
s=>s.replace(/<\w+>|./g,x=>(k=x[3])=='L'?o=o.slice(0,-1):k=='P'?l=!l:k=='F'?s=0:o+=k?k<'C'?'    ':k<'D'?' ':`
`:s?l?x.toLowerCase():x:s=")!@#$%^&*("[x]||'_={}|:"<>?'["-+[]\\;',./".indexOf(x)]||x,l=s,o='')&&o

console.log=(...x)=>O.textContent+=x.join` `+'\n'

;[["1<SHFT>2<TAB><CAPS>R.KAP.<SPC><SHFT>123", "1@    R.KAP. !23"]
,["<SHFT>ABCDEFG<SHFT>HIJK<SHFT>1<SHFT>2<SHFT>3<SHFT>4567890", "AbcdefgHijk!@#$567890"]
,["<CAPS>THIS<SPC>IS<SPC>IN<SPC>ALL<SPC>CAPS<CAPS><SPC>NOW<SPC>THIS<SPC>IS<SPC>IN<SPC>ALL<SPC>LOWERCASE", "THIS IS IN ALL CAPS now this is in all lowercase"]
,["<TAB><SPC><TAB><SHFT>1", "         !"]
,["<CAPS>WWW<CAPS>.CODEGOLF.STACKEXCHANGE<SHFT>.COM", "WWW.codegolf.stackexchange>com"]
,["PROGRAMMING<CAPS><SPC>IS<SPC><CAPS>AWESOME", "programming IS awesome"]
,["<DEL><RET><DEL><RET><DEL>", ""]
,["<SHFT>HI<SPC>HOW<SPC>ARE<SPC>YOU<SHFT>/<RET><SHFT>I<SPC><SHFT>AM<SPC>O<DEL><SHFT>GOOD<SHFT>1", "Hi how are you?\nI Am Good!"]
,["<SHFT>,<CAPS>RET<CAPS><SHFT>.", "<RET>"]
,["<CAPS>67890,.;'[]<CAPS>", "67890,.;'[]"]
,["<CAPS><SHFT>A", "A"]
,["U<RET><DEL><DEL>I", "i"]
,["RE<DEL><DEL>", ""]
,["", ""]].forEach(t=>{
  var i=t[0],k=t[1],r=F(i)
  console.log(
    k==r?'OK':'KO',i,'\n->',r,k==r?'\n':'(should be ->'+k+')\n'
  )
})

<pre id=O></pre>


答:
><>, <s>7</s> <s>6</s> 3 bytes

```<code>+n;
</code>```

Online interpreter

Or try it on TIO with the -v flag.

Try it online

Title: Add two numbers

Body:
><>, <s>7</s> <s>6</s> 3 bytes

+n;

Online interpreter

Or try it on TIO with the -v flag.

Try it online


问:
It's Life, Jim, but not as we know it
You probably know Conway's Game of Life, the famous cellular automaton invented by mathematician John Conway. Life is a set of rules that, together, allow you to simulate a two-dimensional board of cells. The rules decide which cells on the board live and  which ones die. With some imagination, you could say that Life is a zero-player game: a game with the objective to find patterns with interesting behavior, like the famous glider.

A zero-player game... Until today. You are to write a program that plays the Game of Life - and plays it to win, King of the Hill-style. Your opponent (singular) of course tries to do the same. The winner is either the last bot with any live cells, or the player with the most live cells after 10000 generations.

Game rules

The rules are almost the same as normal (B3/S23) Life:

A live cell with fewer than two friendly neighbors dies from starvation.

A live cell with two or three friendly neighbors survives.

A live cell with more than three friendly neighbors dies from overpopulation.

A dead cell with exactly three neighbors of the same player comes alive to fight for that player provided there are no enemy neighbors.

...but after each generation, both you and your opponent get the opportunity to intervene. You can awake up to a maximum of 30 cells to fight for you. (Who goes first is decided by the server.)

The board is a (x,y) cells square. All squares are initially dead. The borders do not wrap around (this is not a torus-shaped world) and are permanently dead.

This is is a contest in the spirit of Battlebots and Core Wars. There is a central server that will run bots and it can be found here

Protocol

The arena server speaks a simple JSON protocol communicated through argv

Where Values is a JSON encoded string

y_size: the maximum y coords of tiles before they vanish

x_size: the maximum x coords of tiles before they vanish

tick_id: the current tick number

board: a dictionary with keys in the form '(y,x)' and values in the form bot_id (int)

bot_id: tiles in the board with this id are yours

Example:

```<code> {"y_size":2000,"x_size":2000,"board":{},"bot_id":1,"tick_id":1}

</code>```

Telling the server your choice:

Send the server a list of tiles to turn to your colour.

Only those that are empty will be changed

Nested coords list format

[[0,0], [0,1], [100,22]...]

NOTE: Your bot doesn't have to update the tiles at all - the server does the updating itself

Competition rules

If your implementation fails to follow the protocol, the turn it does will be forfeited; The server will assume no change in state

You are not allowed to willfully take advantage of a fault in the arena server.

Have your AI decide on moves in a sane time. Please send your next move as  fast as reasonably possible.

Finally, please be nice to the server. It's there for your enjoyment.

Not following these rules can lead to disqualification.

In the event of a tie, both players have 1 win added to their total

Running the controller yourself

The source for the controller can be found here. There are 2 ways of running the controller:

Competition mode (terminal)

Setup with python3 get_answers.py

Run an all v all competition with each bot pitting it against every other.

Testing mode (GUI)

Run python3 nice_gui.py

Click Pull Answers

If you want to add your own answer to try it before posting, click File -> Add manual answer and find the file and choose the language it's written in.

If your language isn't present ping me and I'll try to get it installed on the server I will run it on (installation and running instructions would be nice too!)

Choose 2 bots to pit against each other

Click Run

Watch the game...

Installation

Requires python3

get_answers requires bs4 and html5lib

controller requires a way of running .sh files (MinGW on windows)

Scoring

The bot with the most wins starting from <s>12/07/2016 (12th July)</s>   14/07/2016 (14th July, couldn't work out how to run a bot) wins.

Help with the controller/gui can be asked in this chat room

This question has been in development since 2014 and was the most upvoted question in the sandbox. Special Thanks goes to Wander Nauta (original author and concept), PPCG Chat (comments and help) and anyone who commented in the sandbox post (more comments).

答:
Java, Troll Bot

Troll Bot has thought about it, and he realizes he does NOT care about the enemy. In fact he just spams these factories to produce more of his guys randomly all over the map. After a while he realized that any additional cells are best used in clumps. These blocks of four cells will stick together and stop gliders in their tracks! He does not think he just fights. Also he is a big supporter of verbose object oriented programming. The troll also assumes that coords are in the format y,x, and he is asking to be tested. Just put him in a file called "TrollBot.java", and he'll be set!

```<code>package trollbot;

/**
 *
 * @author Rohans
 */
public class TrollBot{
public static class coord{
    public int x;
    public int y;
    public coord(int inX,int inY){
        x = inX;
        y = inY;
    }
    @Override
    public String toString(){
        return"["+x+","+y+"]";
    }
}
    /**
     * Input the JSON as the first cla
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       String JSON="{\"bot_id\":1,\"y_size\":1000,\"x_size\":1000,\"board\":{}}";
    String[] JArray=args[0].split(",");
       int botId=Integer.parseInt(JSON.charAt(10)+"");
    int xSize=Integer.parseInt(JArray[2].substring(JArray[2].indexOf(":")+1));
    int ySize=Integer.parseInt(JArray[1].substring(JArray[1].indexOf(":")+1));
    int[][] board = new int[xSize][ySize];//0 indexed
//todo: parse the board to get an idea of state
    String soldiers="[";
//for now just ignore whats on the board and put some troll cells on
    //Attempts to create 3 10 cells factories of cells, hoping it does not place it on top of allies
    //Then puts random 2/2 blocks
  boolean[][] blockspam=new boolean[10][8];
  blockspam[7][1]=true;
  blockspam[5][2]=true;
  blockspam[7][2]=true;
  blockspam[8][2]=true;
  blockspam[5][3]=true;
  blockspam[7][3]=true;
  blockspam[5][4]=true;
  blockspam[3][5]=true;
  blockspam[1][6]=true;
  blockspam[3][6]=true;
  for(int z=0;z<3;z++){
     int xOffSet=(int) (Math.random()*(xSize-11));
     int yOffSet=(int) (Math.random()*(ySize-9));
     //stay away from edges to avoid odd interactions
     for(int i=0;i<blockspam.length;i++){
         for(int j=0;j<blockspam[i].length;j++){
             if(blockspam[i][j])
             soldiers+=new coord(j+yOffSet,i+xOffSet).toString()+",";
         }
     }
  }
  soldiers=soldiers.substring(0,soldiers.length()-1);
  for(int i=0;i<8;i++){
            int y=(int ) (Math.random()*(ySize-1));
            int x = (int) (Math.random()*(xSize-1));
      soldiers+=new coord(y,x).toString()+",";
                          soldiers+=new coord(y+1,x).toString()+",";
                          soldiers+=new coord(y,x+1).toString()+",";
                          soldiers+=new coord(y+1,x).toString()+",";

  }
  soldiers+="\b]";

  System.out.println(soldiers);
  //GO GO GO! Lets rule the board
    }

}
</code>```

Title: It's Life, Jim, but not as we know it

Body:
Java, Troll Bot

Troll Bot has thought about it, and he realizes he does NOT care about the enemy. In fact he just spams these factories to produce more of his guys randomly all over the map. After a while he realized that any additional cells are best used in clumps. These blocks of four cells will stick together and stop gliders in their tracks! He does not think he just fights. Also he is a big supporter of verbose object oriented programming. The troll also assumes that coords are in the format y,x, and he is asking to be tested. Just put him in a file called "TrollBot.java", and he'll be set!

package trollbot;

/**
 *
 * @author Rohans
 */
public class TrollBot{
public static class coord{
    public int x;
    public int y;
    public coord(int inX,int inY){
        x = inX;
        y = inY;
    }
    @Override
    public String toString(){
        return"["+x+","+y+"]";
    }
}
    /**
     * Input the JSON as the first cla
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       String JSON="{\"bot_id\":1,\"y_size\":1000,\"x_size\":1000,\"board\":{}}";
    String[] JArray=args[0].split(",");
       int botId=Integer.parseInt(JSON.charAt(10)+"");
    int xSize=Integer.parseInt(JArray[2].substring(JArray[2].indexOf(":")+1));
    int ySize=Integer.parseInt(JArray[1].substring(JArray[1].indexOf(":")+1));
    int[][] board = new int[xSize][ySize];//0 indexed
//todo: parse the board to get an idea of state
    String soldiers="[";
//for now just ignore whats on the board and put some troll cells on
    //Attempts to create 3 10 cells factories of cells, hoping it does not place it on top of allies
    //Then puts random 2/2 blocks
  boolean[][] blockspam=new boolean[10][8];
  blockspam[7][1]=true;
  blockspam[5][2]=true;
  blockspam[7][2]=true;
  blockspam[8][2]=true;
  blockspam[5][3]=true;
  blockspam[7][3]=true;
  blockspam[5][4]=true;
  blockspam[3][5]=true;
  blockspam[1][6]=true;
  blockspam[3][6]=true;
  for(int z=0;z<3;z++){
     int xOffSet=(int) (Math.random()*(xSize-11));
     int yOffSet=(int) (Math.random()*(ySize-9));
     //stay away from edges to avoid odd interactions
     for(int i=0;i<blockspam.length;i++){
         for(int j=0;j<blockspam[i].length;j++){
             if(blockspam[i][j])
             soldiers+=new coord(j+yOffSet,i+xOffSet).toString()+",";
         }
     }
  }
  soldiers=soldiers.substring(0,soldiers.length()-1);
  for(int i=0;i<8;i++){
            int y=(int ) (Math.random()*(ySize-1));
            int x = (int) (Math.random()*(xSize-1));
      soldiers+=new coord(y,x).toString()+",";
                          soldiers+=new coord(y+1,x).toString()+",";
                          soldiers+=new coord(y,x+1).toString()+",";
                          soldiers+=new coord(y+1,x).toString()+",";

  }
  soldiers+="\b]";

  System.out.println(soldiers);
  //GO GO GO! Lets rule the board
    }

}


问:
Tips for golfing in dc
What general tips do you have for golfing in dc?

dc is a calculator utility for UNIX/Linux that predates the C language. I am interested in how to make my dc programs (calculations?) shorter. I'm looking for ideas that can be applied to general code-golf that are at least a little bit specific to dc (eg. removing comments is not a helpful answer)

Please post one tip per answer.

答:
If-then-else statements

Suppose we want to check the condition a==b (let a and b be stored in their respectively-named registers).

edit:

```<code>[         # Everything is wrapped in one big macro
  [         # An inner macro for our *then* part
              # <-- Stuff to execute if a==b here
  2Q          # Then quit the inner and outer macro
]sE       # `E' is for Execution register ;)
la lb =E  # if a==b, execute E
          # if E is executed, it will quit the whole macro, so the rest is never reached:
          # <-- Stuff to execute if a!=b here
]x        # End macro; Execute
</code>```

Let (foo) be a placeholder, for the purpose of condensing:

```<code>[[(then)2Q]sE(condition)E(else)]x
</code>```

Pretty sure this is the most compact if statement possible (also featured here).

Title: Tips for golfing in dc

Body:
If-then-else statements

Suppose we want to check the condition a==b (let a and b be stored in their respectively-named registers).

edit:

[         # Everything is wrapped in one big macro
  [         # An inner macro for our *then* part
              # <-- Stuff to execute if a==b here
  2Q          # Then quit the inner and outer macro
]sE       # `E' is for Execution register ;)
la lb =E  # if a==b, execute E
          # if E is executed, it will quit the whole macro, so the rest is never reached:
          # <-- Stuff to execute if a!=b here
]x        # End macro; Execute

Let (foo) be a placeholder, for the purpose of condensing:

[[(then)2Q]sE(condition)E(else)]x

Pretty sure this is the most compact if statement possible (also featured here).


答:
Batch, 128 bytes

```<code>@set/am=%date:~3,2%,a=(14-m)/12,y=%date:~6%-a,d=(%date:~0,2%+y+y/4-y/100+y/400+(m+47)*18/7+a*3)%%7
@if %d%==1 echo @:
@type %0
</code>```

Since Windows XP, date doesn't give you the day of the week, so I must directly calculate it from the date. The leap year adjustment wants March-based years so a is used as an adjusting factor. (m+47)*18/7 is quicker than using a month-based lookup table.

Note that you need to invoke the file using its full name (e.g. monday.bat). The echo @: counts as a distance of 4 because of the extra CR/LF; I used @: because the result is still a syntactically valid batch script.

Title: I hate Mondays!

Body:
Batch, 128 bytes

@set/am=%date:~3,2%,a=(14-m)/12,y=%date:~6%-a,d=(%date:~0,2%+y+y/4-y/100+y/400+(m+47)*18/7+a*3)%%7
@if %d%==1 echo @:
@type %0

Since Windows XP, date doesn't give you the day of the week, so I must directly calculate it from the date. The leap year adjustment wants March-based years so a is used as an adjusting factor. (m+47)*18/7 is quicker than using a month-based lookup table.

Note that you need to invoke the file using its full name (e.g. monday.bat). The echo @: counts as a distance of 4 because of the extra CR/LF; I used @: because the result is still a syntactically valid batch script.


Title: Distinct Sieves

Body:
Perl 5

push@o,map{$b=pop@a;(grep{/^$b$/}@a)?1:0}(1..~~@a);


答:
Python 77

Code

```<code>from numpy.random import*;l=[]
while sum(l)!=72:l=randint(3,6,18)
print l
</code>```

Output

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

The import really kills this solution. It uses numpy to generate a 18 numbers between 3 and 5 and keeps generating lists until the sum of the list equals 72.

Title: Can you Golf Golf?

Body:
You are required to generate a random 18-hole golf course.

Example output:

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

Rules:

Your program must output a list of hole lengths for exactly 18 holes

Each hole must have a length of 3, 4 or 5

The hole lengths must add up to 72 for the entire course

Your program must be able to produce every possible hole configuration with some non-zero-probability (the probabilities of each configuration need not be equal, but feel free to claim extra kudos if this is the case)

Body:
Python 77

Code

from numpy.random import*;l=[]
while sum(l)!=72:l=randint(3,6,18)
print l

Output

[3 4 4 5 3 3 3 5 4 4 5 4 5 3 4 4 5 4]

The import really kills this solution. It uses numpy to generate a 18 numbers between 3 and 5 and keeps generating lists until the sum of the list equals 72.


问:
Convert to and from the factorial number system
The Factorial Number System, also called factoradic, is a mixed radix numeral system. The factorials determine the place value of a number.

In this system, the right most digit can be either 0 or 1, the second rightmost digit can be 0, 1 or 2, and so on. This means that an n digit factoradic number can have a maximum value of (n + 1)!.

For example, to convert the factoradic number 24201 to decimal you would do this:

```<code>2 * 5! = 240
4 * 4! = 96
2 * 3! = 12
0 * 2! = 0
1 * 1! = 1
240 + 96 + 12 + 0 + 1 = 349
</code>```

Hence the factoradic number 24201 is 349 base 10.

To convert a decimal number (with 349 as an example) into a factoradic number, you would do this:

Take the largest factorial less than the number. In this case it is 120, or 5!.

```<code>349 / 5! = 2 r 109
109 / 4! = 4 r 13
13 / 3! = 2 r 1
1 / 2! = 0 r 1
1 / 1! = 1 r 0
</code>```

Hence 349 base 10 is the factoradic number 24201.

Your challenge is to create the shortest program or function that converts an input number to the other base.

The input will be a string representation of a non-negative integer. A factoradic number will be preceded by a ! (eg. !24201), while a decimal number will not be preceded by anything. You may assume that the maximum input will be 10! - 1 - 3628799 in decimal and 987654321 in factoradic. This means that letters will not appear in a factoradic input/output.

The program doesn't need to prepend a ! to a factoradic output, and may output a string or an integer. The input may be in any reasonable format.

Test cases:

```<code>Input: 1234
Output: 141120

Input: 746
Output: 101010

Input: !54321
Output: 719

Input: !30311
Output: 381
</code>```

答:
JavaScript (ES 6) <s>139 137 122 113</s> 111

tried a different approach using some array magic; but I ended up at <s>174</s> 172 bytes with that:

```<code>f=x=>{if('!'==x[0]){a=x.split``.reverse();i=b=1;r=0;a.pop();a.map(d=>{r+=d*b;b*=++i})}else{t=[];for(i=b=1;b<=x;b*=++i){t.unshift(b)}r='';t.map(b=>{r+=x/b|0;x%=b})}return r}
</code>```

So I just took my PHP code and translated it. Could remove all the $s and a few ;, but the necessity to initialize vars ate up some of that benefit. Managed to golf both answers down a bit further, though.

golfed

```<code>f=x=>{for(r=0,b=j=1,i=x.length;x|0?b<=x:--i;b*=++j)r+=x[i]*b;if(x|0)for(r='';j>1;x%=b)r+=x/(b/=j--)|0;return r}
</code>```

first version returns '' for decimal 0; add +2 to fix

second version requires string input

both tested in Firefox, Edge and Opera

ungolfed

```<code>f=x=>
{
    for(r=0,b=j=1,i=x.length;x|0?b<=x:--i;b*=++j)
        r+=x[i]*b;
    if(x|0)
        for(r='';j>1;x%=b)
            r+=x/(b/=j--)|0;
    return r
}
</code>```

test suite

```<code><table id=out border=1><tr><th>dec</th><th>result<th>expected</th><th>ok?</th></tr></table>
<script>
    addR=(r,s)=>{var d=document.createElement('td');d.appendChild(document.createTextNode(s));r.appendChild(d)}
    test=(x,e)=>{var y=f(x),r=document.createElement('tr');addR(r,x);addR(r,y);addR(r,e);addR(r,e==y?'Y':'N');document.getElementById('out').appendChild(r)}
    samples={'349':'24201','1234':'141120','746':'101010','719':'54321','381':'30311','24':'1000','0':'0'};
    for(d in samples){test(d,samples[d]);test('!'+samples[d],d)}
</script>
</code>```

Body:
JavaScript (ES 6) <s>139 137 122 113</s> 111

tried a different approach using some array magic; but I ended up at <s>174</s> 172 bytes with that:

f=x=>{if('!'==x[0]){a=x.split``.reverse();i=b=1;r=0;a.pop();a.map(d=>{r+=d*b;b*=++i})}else{t=[];for(i=b=1;b<=x;b*=++i){t.unshift(b)}r='';t.map(b=>{r+=x/b|0;x%=b})}return r}

So I just took my PHP code and translated it. Could remove all the $s and a few ;, but the necessity to initialize vars ate up some of that benefit. Managed to golf both answers down a bit further, though.

golfed

f=x=>{for(r=0,b=j=1,i=x.length;x|0?b<=x:--i;b*=++j)r+=x[i]*b;if(x|0)for(r='';j>1;x%=b)r+=x/(b/=j--)|0;return r}

first version returns '' for decimal 0; add +2 to fix

second version requires string input

both tested in Firefox, Edge and Opera

ungolfed

f=x=>
{
    for(r=0,b=j=1,i=x.length;x|0?b<=x:--i;b*=++j)
        r+=x[i]*b;
    if(x|0)
        for(r='';j>1;x%=b)
            r+=x/(b/=j--)|0;
    return r
}

test suite

<table id=out border=1><tr><th>dec</th><th>result<th>expected</th><th>ok?</th></tr></table>
<script>
    addR=(r,s)=>{var d=document.createElement('td');d.appendChild(document.createTextNode(s));r.appendChild(d)}
    test=(x,e)=>{var y=f(x),r=document.createElement('tr');addR(r,x);addR(r,y);addR(r,e);addR(r,e==y?'Y':'N');document.getElementById('out').appendChild(r)}
    samples={'349':'24201','1234':'141120','746':'101010','719':'54321','381':'30311','24':'1000','0':'0'};
    for(d in samples){test(d,samples[d]);test('!'+samples[d],d)}
</script>


答:
Bash script, 12 bytes

```<code>expr $1 + $2
</code>```

Save as add.sh, then run bash add.sh [argument] [argument].

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:
Bash script, 12 bytes

expr $1 + $2

Save as add.sh, then run bash add.sh [argument] [argument].


问:
Meta Obfuscate a String
There are numerous reasons for trying to obfuscate input. These include preventing decompiling, and being a nuiscance.

With this in mind your challenge should your choose to accept it is to write a meta-obfuscator. Your code must in some Language X receive input as a String, and output a program in language X that outputs the input String.

Rules

Standard loopholes disallowed

It should be hard to tell whether the output prints anything (I.E the code should be heavily obfuscated)

Your program should be testable

Cryptographic approaches are permitted, but it should not be obvious.

Try to submit an interesting solution as this is a popularity contest

Winning Criterion

Although it is up to you to decide which question deserves your upvote. Here are the guidelines.

Hardest to reverse engineer output based on the source code (i.e most encrypted/obfuscated)

Effort and quality of answer

tl;dr
Output a program which prints the input, but make it hard to understand what is going on. Although many people have discussed this (especially for javascript) and even python. I have seen no formal repository of such programs in any arbitrary languages.

答:
Java

Just out of curiosity I decided to write a simple block of code that outputs code that does not look obfuscated.
Here is the generator code

```<code>package metaobfuscate;

import java.util.Random;
import java.util.Scanner;

/**
 *
 * @author rohan
 */
public class MetaObfuscate {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String s = (new Scanner(System.in)).nextLine().toLowerCase();
        int i = 0;
        int numChar = s.length();

        String randomlyGenerated;
        String alphabet = " abcdefghijklmnopqrstuvwxyz!?.";
        do {
            Random rand = new Random(i);
            randomlyGenerated = "";
            i++;
            for (int j = 0; j < numChar; j++) {
                randomlyGenerated += alphabet.charAt((int) (rand.nextDouble() * alphabet.length()));
            }
        } while (!s.equals(randomlyGenerated));
        i--;
        System.out.println("import java.util.Random;\n//Simple demonstration of generating random characters");
        System.out.println("public class RandomNessTest {");
        System.out.println("\t//args are the command line arguments");
        System.out.println("\tpublic static void main(String[] args){");
        System.out.println("\tRandom rand = new Random(" + i + ");//replace the seed with whatever seed you want");
        System.out.println("\t//the seed was generated by random keyboard mashing");
        System.out.println("\tString alphabet = \" abcdefghijklmnopqrstuvwxyz!?.\";");
        System.out.println("\tfor(int i = 0;i<" + numChar + ";i++)");
        System.out.println("\t\tSystem.out.print(alphabet.charAt((int)(rand.nextDouble()*alphabet.length())));");
        System.out.println("\t//print out a few random characters");
        System.out.println("\t}\n}");
    }

}
</code>```

It takes in whatever string you wish to obfuscate and outputs a program that looks reliable as output. It takes exponential runtime with larger strings, but it works great for strings of length 1-5. The outputted program claims to be a tutorial, and is even formatted nicely!

```<code>import java.util.Random;
//Simple demonstration of generating random characters
public class RandomNessTest {
    //args are the command line arguments
    public static void main(String[] args){
    Random rand = new Random(2727915);//replace the seed with whatever seed you want
    //the seed was generated by random keyboard mashing
    String alphabet = " abcdefghijklmnopqrstuvwxyz!?.";
    for(int i = 0;i<5;i++)
        System.out.print(alphabet.charAt((int)(rand.nextDouble()*alphabet.length())));
    //print out a few random characters
    }
}
</code>```

Title: Meta Obfuscate a String

Body:
Java

Just out of curiosity I decided to write a simple block of code that outputs code that does not look obfuscated.
Here is the generator code

package metaobfuscate;

import java.util.Random;
import java.util.Scanner;

/**
 *
 * @author rohan
 */
public class MetaObfuscate {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String s = (new Scanner(System.in)).nextLine().toLowerCase();
        int i = 0;
        int numChar = s.length();

        String randomlyGenerated;
        String alphabet = " abcdefghijklmnopqrstuvwxyz!?.";
        do {
            Random rand = new Random(i);
            randomlyGenerated = "";
            i++;
            for (int j = 0; j < numChar; j++) {
                randomlyGenerated += alphabet.charAt((int) (rand.nextDouble() * alphabet.length()));
            }
        } while (!s.equals(randomlyGenerated));
        i--;
        System.out.println("import java.util.Random;\n//Simple demonstration of generating random characters");
        System.out.println("public class RandomNessTest {");
        System.out.println("\t//args are the command line arguments");
        System.out.println("\tpublic static void main(String[] args){");
        System.out.println("\tRandom rand = new Random(" + i + ");//replace the seed with whatever seed you want");
        System.out.println("\t//the seed was generated by random keyboard mashing");
        System.out.println("\tString alphabet = \" abcdefghijklmnopqrstuvwxyz!?.\";");
        System.out.println("\tfor(int i = 0;i<" + numChar + ";i++)");
        System.out.println("\t\tSystem.out.print(alphabet.charAt((int)(rand.nextDouble()*alphabet.length())));");
        System.out.println("\t//print out a few random characters");
        System.out.println("\t}\n}");
    }

}

It takes in whatever string you wish to obfuscate and outputs a program that looks reliable as output. It takes exponential runtime with larger strings, but it works great for strings of length 1-5. The outputted program claims to be a tutorial, and is even formatted nicely!

import java.util.Random;
//Simple demonstration of generating random characters
public class RandomNessTest {
    //args are the command line arguments
    public static void main(String[] args){
    Random rand = new Random(2727915);//replace the seed with whatever seed you want
    //the seed was generated by random keyboard mashing
    String alphabet = " abcdefghijklmnopqrstuvwxyz!?.";
    for(int i = 0;i<5;i++)
        System.out.print(alphabet.charAt((int)(rand.nextDouble()*alphabet.length())));
    //print out a few random characters
    }
}


问:
Borders of overlapping circles
Given the coordinates of several points on a plane, and the radius of a circle surrounding each point, draw polygons representing the circles and the edges where the circles meet. Straight edges will always fall along circle-circle intersection lines, but might not follow the full length of these lines.

<s>Per mbomb007's suggestion, imagine the behavior of 2D soap bubbles.</s> That's technically wrong, because soap bubbles would always meet at 120° angles to minimize energy, while these circles may meet at any angle.

<s>This is a Voronoi diagram, minus a defined area plane. Thanks Andreas.</s> This is actually a generalization of a Voronoi diagram called a power diagram.

Examples

For example, given two points and two radii, the output might look like this:

Add another point and radius and the output might look like this:

Input

You can structure the input however you wish. Please post results with the following inputs.

Test 1

x: 10, y: 10, r: 10

x: 25, y: 12, r: 8

Test 2

x: 8, y: 10, r: 6

x: 20, y: 8, r: 4

x: 18, y: 20, r: 12

Output

Output should be graphical and should include polygon borders, but nothing else is required. Points and intersections do not need to be represented like they are in the examples.

Constraints

No point will exist within the radius of another circle.

Standard codegolf rules.

No answers with loopholes will be accepted, but feel free to have fun with it.

Title: Borders of overlapping circles

Body:
Python 2, <s>473</s> 355 bytes

L=input()
m=min
a,b,c,d=eval('m(%s-r for u,v,r in L),'*4%('u','v','-u','-v'))
e=(-c-a)/499.
H=lambda x,y:x*x+y*y
I=500
J=int(2-(d+b)/e)
print'P2',I,J,255
i=I*J
P=lambda(u,v,r):H(c+i%I*e+u,b+i/I*e-v)-r*r
while i:i-=1;p,k=m((P(k)/[1,k[2]][P(k)>0],k)for k in L);u,v,r=k;print int(255*m(1,[m([-p/r]+[(P(l)-p)/H(u-l[0],v-l[1])**.5for l in L-{k}]),p][p>0]/2/e))

This reads a set of circles as (x,y,r) tuples on stdin, and outputs an image in PGM format to stdout.  It works roughly by computing a distance function of the diagram at each pixel, and shading each pixel less than one pixel away proportionally to its distance.

{(10,10,10),(25,12,8)}

{(8,10,6),(20,8,4),(18,20,12)}

{(6, 63, 4), (16, 88, 9), (64, 94, 11), (97, 96, 3), (23, 32, 13), (54, 14, 7), (41, 81, 3), (7, 7, 4), (77, 18, 8), (98, 55, 4), (2, 56, 7), (62, 18, 5), (13, 74, 2), (33, 56, 12), (49, 48, 4), (6, 76, 2), (82, 70, 9), (21, 71, 2), (27, 5, 10), (3, 32, 6), (70, 62, 6), (74, 46, 4), (21, 60, 7), (18, 47, 7), (94, 2, 4), (39, 97, 7), (62, 63, 2), (87, 29, 8), (19, 17, 4), (61, 23, 2), (73, 1, 8), (40, 17, 13), (99, 41, 4), (81, 57, 7), (1, 68, 5), (38, 3, 4), (46, 36, 9), (4, 39, 2), (73, 77, 3), (93, 19, 10), (67, 42, 3), (96, 65, 2), (2, 16, 3), (28, 92, 3), (54, 58, 2), (39, 86, 5), (84, 82, 5), (79, 43, 4), (5, 47, 1), (34, 41, 8), (65, 5, 2), (9, 44, 3), (53, 3, 6), (1, 12, 1), (81, 95, 7), (74, 31, 2), (63, 61, 1), (35, 72, 1), (44, 71, 2), (57, 35, 5), (46, 65, 6), (57, 45, 4), (93, 94, 1), (99, 81, 13), (13, 58, 4), (68, 32, 6), (11, 2, 6), (52, 98, 7), (51, 25, 5), (84, 2, 2), (44, 92, 3), (23, 72, 2), (32, 99, 7), (13, 19, 3), (97, 29, 8), (58, 80, 3), (67, 82, 5), (59, 60, 3), (86, 87, 5), (29, 73, 2), (5, 93, 4), (42, 74, 1), (75, 85, 8), (91, 53, 5), (23, 82, 4), (19, 97, 8), (51, 88, 3), (67, 12, 6), (60, 53, 1), (66, 72, 2), (57, 64, 2), (66, 49, 2), (44, 0, 4), (11, 69, 1), (93, 60, 5), (56, 50, 3), (19, 68, 3), (64, 75, 3), (6, 17, 2), (82, 5, 2)}

Here the distance function has been divided by 32 to make it visible:

{(7, 9, 7), (1, 3, 2), (4, 0, 4), (9, 2, 4), (0, 8, 5)}


问:
Print the "even" permutations of symmetric group Sn in cyclic notation

THE TASK

DEFINITIONS

Consider the points {1,2,3,4,5} and all their permutations. We can find the total number of possible permutations of these 5 points by a simple trick: Imaging filling 5 slots with these points, the first slot will have 5 possible numbers, the second 4 (as one has been used to fill the first slot) the third 3 and so on. Thus the total number of Permutations is 5*4*3*2*1; this would be 5! permutations or 120 permutations. We can think of this as the symmetric group S5, and then Symmetric Group Sn would have n! or (n*n-1*n-2...*1) permutations.

An "even" permutation is one where there is an even number of even length cycles. It is easiest to understand when written in cyclic notation, for example (1 2 3)(4 5) permutes 1->2->3->1 and 4->5->4 and has one 3 length cycle (1 2 3) and one 2 length cycle (4 5). When classifying a permutation as odd or even we ignore odd length cycles and say that this permutation [(1 2 3)(4 5)] is odd as it has an odd number {1} of even length cycles.
Even examples:

(1)(2 3)(4 5) = two 2 length cycle | EVEN |

(1 2 3 4 5) = no even length cycles | EVEN | * note that if no even length cycles are present then the permutation is even.

Odd Examples:

(1 2)(3 4 5) = one 2 length cycle | ODD |

(1)(2 3 4 5) = one 4 length cycle | ODD |

As exactly half of the permutations in any Symmetric Group are even we can call the even group the Alternating Group N, So as S5 = 120 A5 = 60 permutations.

NOTATION

Permutations should, for this at least, be written in cyclic notation where each cycle is in different parenthesis and each cycle goes in ascending order. For example (1 2 3 4 5) not (3 4 5 1 2). And for cycles with a single number, such as: (1)(2 3 4)(5) the single / fixed points can be excluded meaning (1)(2 3 4)(5) = (2 3 4). But the identity {the point where all points are fixed (1)(2)(3)(4)(5)} should be written as () just to represent it.

THE CHALLENGE

I would like you to, in as little code possible, take any positive integer as an input {1,2,3,4...} and display all the permutations of the Alternating Group An where n is the input / all the even permutations of Sn. For example:

```<code>Input = 3
()
(1 2 3)
(1 3 2)
</code>```

and

```<code>Input = 4
()
(1 2)(3 4)
(1 3)(2 4)
(1 4)(2 3)
(1 2 3)
(1 3 2)
(1 2 4)
(1 4 2)
(1 3 4)
(1 4 3)
(2 3 4)
(2 4 3)
</code>```

And as with in the examples I would like for all cycles of one length to be elided, and as for the identity: outputs of  nothing, () {not only brackets but with whatever you are using to show different permutations} or id are acceptable.

EXTRA READING

You can find more information here:

https://en.wikipedia.org/wiki/Permutation

https://en.wikipedia.org/wiki/Alternating_group

GOOD LUCK

And as this is codegolf whoever can print the Alternating Group An's permutations in the shortest bytes wins.

答:
Mathematica, <s>84</s> <s>49</s> 31 bytes

```<code>GroupElements@*AlternatingGroup
</code>```

Composition of two functions. Outputs in the form {Cycles[{}], Cycles[{{a, b}}], Cycles[{{c, d}, {e, f}}], ...} representing (), (a b), (c d)(e f), ....

Body:
Mathematica, <s>84</s> <s>49</s> 31 bytes

GroupElements@*AlternatingGroup

Composition of two functions. Outputs in the form {Cycles[{}], Cycles[{{a, b}}], Cycles[{{c, d}, {e, f}}], ...} representing (), (a b), (c d)(e f), ....


Title: Can you Golf Golf?

Body:
R - 41

x=0;while(sum(x)!=72)x=sample(3:5,18,T);x

# [1] 5 3 5 3 3 3 3 3 5 4 5 4 5 4 4 5 5 3

The algorithm is similar to @sgrieve's.


答:
Python 3, Exploder

Puts small exploders around the place, with no regard to whether there is already a block there.

```<code>from random import randint
import sys,json,copy
q=json.loads(sys.argv[1])
x=q["x_size"];y=q["y_size"];F=[[0,1],[1,0],[1,1],[1,2],[2,0],[2,2]];D=[]
for g in [0]*5:
 X=randint(0,x);Y=randint(0,y);A=copy.deepcopy(F)
 for C in A:C[0]+=Y;C[1]+=X
 D+=A
print(D)
</code>```

Title: It's Life, Jim, but not as we know it

Body:
You probably know Conway's Game of Life, the famous cellular automaton invented by mathematician John Conway. Life is a set of rules that, together, allow you to simulate a two-dimensional board of cells. The rules decide which cells on the board live and  which ones die. With some imagination, you could say that Life is a zero-player game: a game with the objective to find patterns with interesting behavior, like the famous glider.

A zero-player game... Until today. You are to write a program that plays the Game of Life - and plays it to win, King of the Hill-style. Your opponent (singular) of course tries to do the same. The winner is either the last bot with any live cells, or the player with the most live cells after 10000 generations.

Game rules

The rules are almost the same as normal (B3/S23) Life:

A live cell with fewer than two friendly neighbors dies from starvation.

A live cell with two or three friendly neighbors survives.

A live cell with more than three friendly neighbors dies from overpopulation.

A dead cell with exactly three neighbors of the same player comes alive to fight for that player provided there are no enemy neighbors.

...but after each generation, both you and your opponent get the opportunity to intervene. You can awake up to a maximum of 30 cells to fight for you. (Who goes first is decided by the server.)

The board is a (x,y) cells square. All squares are initially dead. The borders do not wrap around (this is not a torus-shaped world) and are permanently dead.

This is is a contest in the spirit of Battlebots and Core Wars. There is a central server that will run bots and it can be found here

Protocol

The arena server speaks a simple JSON protocol communicated through argv

Where Values is a JSON encoded string

y_size: the maximum y coords of tiles before they vanish

x_size: the maximum x coords of tiles before they vanish

tick_id: the current tick number

board: a dictionary with keys in the form '(y,x)' and values in the form bot_id (int)

bot_id: tiles in the board with this id are yours

Example:

```<code> {"y_size":2000,"x_size":2000,"board":{},"bot_id":1,"tick_id":1}

</code>```

Telling the server your choice:

Send the server a list of tiles to turn to your colour.

Only those that are empty will be changed

Nested coords list format

[[0,0], [0,1], [100,22]...]

NOTE: Your bot doesn't have to update the tiles at all - the server does the updating itself

Competition rules

If your implementation fails to follow the protocol, the turn it does will be forfeited; The server will assume no change in state

You are not allowed to willfully take advantage of a fault in the arena server.

Have your AI decide on moves in a sane time. Please send your next move as  fast as reasonably possible.

Finally, please be nice to the server. It's there for your enjoyment.

Not following these rules can lead to disqualification.

In the event of a tie, both players have 1 win added to their total

Running the controller yourself

The source for the controller can be found here. There are 2 ways of running the controller:

Competition mode (terminal)

Setup with python3 get_answers.py

Run an all v all competition with each bot pitting it against every other.

Testing mode (GUI)

Run python3 nice_gui.py

Click Pull Answers

If you want to add your own answer to try it before posting, click File -> Add manual answer and find the file and choose the language it's written in.

If your language isn't present ping me and I'll try to get it installed on the server I will run it on (installation and running instructions would be nice too!)

Choose 2 bots to pit against each other

Click Run

Watch the game...

Installation

Requires python3

get_answers requires bs4 and html5lib

controller requires a way of running .sh files (MinGW on windows)

Scoring

The bot with the most wins starting from <s>12/07/2016 (12th July)</s>   14/07/2016 (14th July, couldn't work out how to run a bot) wins.

Help with the controller/gui can be asked in this chat room

This question has been in development since 2014 and was the most upvoted question in the sandbox. Special Thanks goes to Wander Nauta (original author and concept), PPCG Chat (comments and help) and anyone who commented in the sandbox post (more comments).

Body:
Python 3, Exploder

Puts small exploders around the place, with no regard to whether there is already a block there.

from random import randint
import sys,json,copy
q=json.loads(sys.argv[1])
x=q["x_size"];y=q["y_size"];F=[[0,1],[1,0],[1,1],[1,2],[2,0],[2,2]];D=[]
for g in [0]*5:
 X=randint(0,x);Y=randint(0,y);A=copy.deepcopy(F)
 for C in A:C[0]+=Y;C[1]+=X
 D+=A
print(D)


答:
Common Lisp, 15 bytes

```<code>(+(read)(read))
</code>```

Title: Add two numbers

Body:
Common Lisp, 15 bytes

(+(read)(read))


答:
Minecraft 1.10, 221 characters (non-competing)

See, this is what we have to deal with when we make Minecraft maps.

Aside: There's no way to take a string input in Minecraft, so I'm cheating a bit by making you input the numbers into the program itself. (It's somewhat justifiable because quite a few maps, like Lorgon111's Minecraft Bingo, require you to copy and paste commands into chat in order to input a number.)

Thank you abrightmoore for the Block Labels MCEdit filter.

```<code>scoreboard objectives add a dummy
scoreboard players set m a 6
scoreboard players set n a 8
scoreboard players operation r a += m a
scoreboard players operation r a += n a
tellraw @a {"score":{"name":"r","objective":"a"}}
</code>```

Non-competing due to difficulties in input, and I have no idea how to count bytes in this thing (the blytes system is flawed for command blocks).

Title: Add two numbers

Body:
Minecraft 1.10, 221 characters (non-competing)

See, this is what we have to deal with when we make Minecraft maps.

Aside: There's no way to take a string input in Minecraft, so I'm cheating a bit by making you input the numbers into the program itself. (It's somewhat justifiable because quite a few maps, like Lorgon111's Minecraft Bingo, require you to copy and paste commands into chat in order to input a number.)

Thank you abrightmoore for the Block Labels MCEdit filter.

scoreboard objectives add a dummy
scoreboard players set m a 6
scoreboard players set n a 8
scoreboard players operation r a += m a
scoreboard players operation r a += n a
tellraw @a {"score":{"name":"r","objective":"a"}}

Non-competing due to difficulties in input, and I have no idea how to count bytes in this thing (the blytes system is flawed for command blocks).


答:
Perl, 75 bytes

```<code> my$s=<>;chomp$s;my$c;for my$i(split//,$s){my$m=@{[$s=~/$i/gi]};$m<2and++$c>=2and say$i and last}
</code>```

Body:
Based on this question from Code Review

Given a non-empty string of printable ASCII characters, output the second non-repeating character. For example, for input DEFD, output F.

Input

A single string, in any suitable format.

Output

The second character that doesn't repeat, when reading left-to-right, again in a suitable format.

The output character is case-insensitive.

If no such character exists (e.g., all characters repeat), output an empty string.

Rules

The algorithm should ignore case. That is, D and d count as the same character.

Either a full program or a function are acceptable.

The input string will be guaranteed non-empty (i.e., at least one character in length).

The input string is ASCII. Any valid character could repeat, not just alphanumeric (this includes spaces).

Standard loopholes are forbidden.

This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.

Examples

Input is on first line, output is on second line.

```<code>DEFD
F

FEED
D

This is an example input sentence.
x

...,,,..,,!@
@

ABCDefgHijklMNOPqrsTuVWxyz
B

AAAAAABBBBB

Thisxthis

This this.
.
</code>```

Body:
Perl, 75 bytes

 my$s=<>;chomp$s;my$c;for my$i(split//,$s){my$m=@{[$s=~/$i/gi]};$m<2and++$c>=2and say$i and last}


问:
Print a Lego piece
This challenge is a simple ascii-art one. Given two inputs, describing the height and width of a Lego piece, you have print an ASCII art representation of it.

Here is how the Lego pieces are supposed to look:

```<code>(4, 2)

___________
| o o o o |
| o o o o |
-----------

(8, 2)

___________________
| o o o o o o o o |
| o o o o o o o o |
-------------------

(4, 4)

___________
| o o o o |
| o o o o |
| o o o o |
| o o o o |
-----------

(3, 2)

_________
| o o o |
| o o o |
---------

(1, 1)

o
</code>```

If you can't tell from the test-cases, the top and bottom are width*2+3 underscores and dashes, and each row has pipes for the sides, o's for the little things, and everything is separated by spaces.

The only exception for this is (1, 1), which is just a single o.

You will never get 0 for any of the dimensions.

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

var QUESTION_ID=84050,OVERRIDE_USER=31343;function answersUrl(e){return"http://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"http://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

```

答:
Common Lisp, 286 bytes

```<code>(let((columns(read))(rows(read)))(when(and(= columns 1)(= rows 1))(progn(write-char #\o)(exit)))(dotimes(i(+(* columns 2)3))(write-char #\_))(terpri)(dotimes(i rows)(format t "| ")(dotimes(i columns)(format t "o "))(format t "| ")(terpri))(dotimes(i(+(* columns 2)3))(write-char #\-)))
</code>```

Title: Print a Lego piece

Body:
Common Lisp, 286 bytes

(let((columns(read))(rows(read)))(when(and(= columns 1)(= rows 1))(progn(write-char #\o)(exit)))(dotimes(i(+(* columns 2)3))(write-char #\_))(terpri)(dotimes(i rows)(format t "| ")(dotimes(i columns)(format t "o "))(format t "| ")(terpri))(dotimes(i(+(* columns 2)3))(write-char #\-)))