答:
APL (Dyalog Unicode), <s>45</s> 25 bytes

Anonymous tacit function. Requires ⎕IO←0, which is standard on many APL systems.

1 0∘.{×⍵:⍵-(~⍺)∇⍺∇⍵-1⋄⍺}⍳
```

Try it online!

This works by combining F and M into a single dyadic function with a Boolean left argument which selects the function to apply. We use 1 for F and 0 for M so that we can use this selector as return value for F (0) and M (0). We then observe that both functions need to call themselves first (on the argument minus one) and then the other function on the result of that, so first we recurse with the given selector and then with the logically negated selector.

⍳ ɩndices; zero through argument minus one

1 0∘.{…} outer (Cartesian) "product" (but with the below function instead of multiplication) using [1,0] as left arguments (⍺) and the indices as right arguments (⍵):

 ×⍵ if the right argument is strictly positive (lit. the sign of the right argument):

  ⍵-1 subtract one from the right argument

  ⍺∇ call self with that as right argument and the left argument as left argument

  (~⍺)∇ call self with that as right arg and the logical negation of the left arg as left arg

  ⍵- subtract that from the right argument and return the result

 ⋄ else:

  ⍺ return the left argument

Title: Female and Male Sequences

Body:
This question is probably harder than all of those "generate a sequence of numbers" tasks, because this requires TWO sequences working in unison.

Really looking forward to the answers!

In his book "Gödel, Escher, Bach: An Eternal Golden Braid", Douglas Hofstadter has a quite few sequences of numbers inside, all of them rely on the previous term in some way. For information on all of the sequences, see this Wikipedia page.

One pair of sequences that's really interesting is the Female and Male sequences, which are defined like so:

for n > 0.

Here's the Female sequence and the Male sequence.

Your task is, when given an integer n as input, return a list of the Female sequence and the Male sequence, with the amount of terms equal to n, in two lines of output, with the Female sequence on the first line and the Male sequence on the second.

Sample inputs and outputs:
Input: 5
Output: [1, 1, 2, 2, 3]  [0, 0, 1, 2, 2]

Input: 10
Output: [1, 1, 2, 2, 3, 3, 4, 5, 5, 6]  [0, 0, 1, 2, 2, 3, 4, 4, 5, 6]

NOTE: The separation between lists signifies a line break.

This is code-golf, so shortest code in bytes wins. Also, put an explanation in as well for your code.

Leaderboard

var QUESTION_ID=80608,OVERRIDE_USER=49561;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:
APL (Dyalog Unicode), <s>45</s> 25 bytes

Anonymous tacit function. Requires ⎕IO←0, which is standard on many APL systems.

1 0∘.{×⍵:⍵-(~⍺)∇⍺∇⍵-1⋄⍺}⍳

Try it online!

This works by combining F and M into a single dyadic function with a Boolean left argument which selects the function to apply. We use 1 for F and 0 for M so that we can use this selector as return value for F (0) and M (0). We then observe that both functions need to call themselves first (on the argument minus one) and then the other function on the result of that, so first we recurse with the given selector and then with the logically negated selector.

⍳ ɩndices; zero through argument minus one

1 0∘.{…} outer (Cartesian) "product" (but with the below function instead of multiplication) using [1,0] as left arguments (⍺) and the indices as right arguments (⍵):

 ×⍵ if the right argument is strictly positive (lit. the sign of the right argument):

  ⍵-1 subtract one from the right argument

  ⍺∇ call self with that as right argument and the left argument as left argument

  (~⍺)∇ call self with that as right arg and the logical negation of the left arg as left arg

  ⍵- subtract that from the right argument and return the result

 ⋄ else:

  ⍺ return the left argument


问:
Female and Male Sequences
This question is probably harder than all of those "generate a sequence of numbers" tasks, because this requires TWO sequences working in unison.

Really looking forward to the answers!

In his book "Gödel, Escher, Bach: An Eternal Golden Braid", Douglas Hofstadter has a quite few sequences of numbers inside, all of them rely on the previous term in some way. For information on all of the sequences, see this Wikipedia page.

One pair of sequences that's really interesting is the Female and Male sequences, which are defined like so:

for n > 0.

Here's the Female sequence and the Male sequence.

Your task is, when given an integer n as input, return a list of the Female sequence and the Male sequence, with the amount of terms equal to n, in two lines of output, with the Female sequence on the first line and the Male sequence on the second.

Sample inputs and outputs:
Input: 5
Output: [1, 1, 2, 2, 3]  [0, 0, 1, 2, 2]

Input: 10
Output: [1, 1, 2, 2, 3, 3, 4, 5, 5, 6]  [0, 0, 1, 2, 2, 3, 4, 4, 5, 6]

NOTE: The separation between lists signifies a line break.

This is code-golf, so shortest code in bytes wins. Also, put an explanation in as well for your code.

Leaderboard

var QUESTION_ID=80608,OVERRIDE_USER=49561;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

```

答:
Jelly, <s>22</s> 20 bytes

```<code>ṙṪḢạL}ṭ
çƓḤ¤Ð¡1ṫ-Ṗ€G
</code>```

Try it online!

How it works

```<code>çƓḤ¤Ð¡1ṫ-Ṗ€G  Main link. No user arguments. Left argument defaults to 0.
   ¤          Combine the two links to the left into a niladic chain.
 Ɠ              Read an integer from STDIN.
  Ḥ             Unhalve/double it.
ç   Ð¡1       Call the helper link that many times. Return all results.
              In the first call, the left and right argument are 0 and 1 resp.
              After each iteration, the left argument is set to the return value
              and the right argument to the prior value of the left one.
       ṫ-     Tail -1; keep the last two items of the list of results.
         Ṗ€   Discard the last item of each list.
           G  Grid; format the pair of lists.

ṙṪḢạL}ṭ       Helper link. Arguments: x, y (lists)

ṙ             Rotate x k units to the left, for each k in y.
 Ṫ            Tail; extract the last rotation.
  Ḣ           Head; extract the last element.
              This essentially computes x[y[-1]] (Python notation), avoiding
              Jelly's 1-based indexing.
    L}        Yield the length of y.
   ạ          Take the absolute difference of the results to both sides.
      ṭ       Tack; append the difference to y and return the result.
</code>```

ContentLicense: CC BY-SA 3.0

Title: Female and Male Sequences

Body:
Jelly, <s>22</s> 20 bytes

ṙṪḢạL}ṭ
çƓḤ¤Ð¡1ṫ-Ṗ€G

Try it online!

How it works

çƓḤ¤Ð¡1ṫ-Ṗ€G  Main link. No user arguments. Left argument defaults to 0.
   ¤          Combine the two links to the left into a niladic chain.
 Ɠ              Read an integer from STDIN.
  Ḥ             Unhalve/double it.
ç   Ð¡1       Call the helper link that many times. Return all results.
              In the first call, the left and right argument are 0 and 1 resp.
              After each iteration, the left argument is set to the return value
              and the right argument to the prior value of the left one.
       ṫ-     Tail -1; keep the last two items of the list of results.
         Ṗ€   Discard the last item of each list.
           G  Grid; format the pair of lists.

ṙṪḢạL}ṭ       Helper link. Arguments: x, y (lists)

ṙ             Rotate x k units to the left, for each k in y.
 Ṫ            Tail; extract the last rotation.
  Ḣ           Head; extract the last element.
              This essentially computes x[y[-1]] (Python notation), avoiding
              Jelly's 1-based indexing.
    L}        Yield the length of y.
   ạ          Take the absolute difference of the results to both sides.
      ṭ       Tack; append the difference to y and return the result.


问:
Find a function with cycles of every length
A function is said to have a cycle of length n if there exists an x in its domain such that fn(x) = x and fm(x) ≠ x for 0 < m < n, where the superscript n denotes n-fold application of f. Note that a cycle of length 1 is a fixed point f(x) = x.

Your task is to implement a bijective function from the integers to themselves, which has exactly one cycle of every positive length n. A bijective function is a one-to-one correspondence, i.e. every integer mapped to exactly once. Having exactly one cycle of length n means that there are exactly n distinct numbers x for which fn(x) = x and fm(x) ≠ x for 0 < m < n.

Here is an example of what such a function might look like around x = 0:

```<code>x     ... -7 -6 -5 -4 -3 -2 -1  0  1  2  3  4  5  6  7 ...
f(x)  ...  2  4  6 -3 -1  1 -4  0 -2  5  7 -7 -6  3 -5 ...
</code>```

This excerpt contains cycles of length 1 to 5:

```<code>n   cycle
1    0
2   -2  1
3   -4 -3 -1
4   -5  6  3  7
5   -7  2  5 -6  4
...
</code>```

Note that above I'm using "function" only in the mathematical sense. You may write either a function or a full program in your language of choice, as long as it takes a single (signed) integer as input and returns a single (signed) integer. As usual you may take input via STDIN, command-line argument, function argument etc. and output via STDOUT, function return value or function (out) argument etc.

Of course, many languages don't (easily) support arbitrary-precision integers. It's fine if your implementation only works on the range of your language's native integer type, as long as that covers at least the range [-127, 127] and that it would work for arbitrary integers if the language's integer type was replaced with arbitrary-precision integers.

Standard code-golf rules apply.

答:
JavaScript (ES6), 73 bytes

```<code>f=(n,i=0,j=0,k=0,l=1,m=i<0?-i:~i)=>n-i?f(n,m,k++?j:i,k%=l,l+!k):++k-l?m:j
</code>```

Works by enumerating the sequence (0, -1, 1, -2, 2, -3, 3, ...) until it finds n, counting cycles as it goes. i contains the current entry; j contains the start of the current cycle, k the index within the cycle, l the length of the current cycle and m the next entry in the sequence. Once we find n we then take j if we're at the end of a cycle or m if not.

Body:
JavaScript (ES6), 73 bytes

f=(n,i=0,j=0,k=0,l=1,m=i<0?-i:~i)=>n-i?f(n,m,k++?j:i,k%=l,l+!k):++k-l?m:j

Works by enumerating the sequence (0, -1, 1, -2, 2, -3, 3, ...) until it finds n, counting cycles as it goes. i contains the current entry; j contains the start of the current cycle, k the index within the cycle, l the length of the current cycle and m the next entry in the sequence. Once we find n we then take j if we're at the end of a cycle or m if not.


问:
Surjective, Injective, Bijective, or Nothing?
Given a mapping from the integers from 1 to N to the integers from 1 to N, determine if the mapping is surjective, injective, bijective, or nothing.

You may choose any character/digit for the four outputs.

Specs

Input format: n, arrays of pairs (n is the highest number in the domain and range)

For example, if the first number is 3, then both the domain and the co-domain are {1,2,3}.

For example, {i+1 | i from 1 to 9} (n=10) is represented by 10, [[1,2],[2,3],...,[9,10]].

The input may contain duplicate.

Testcases

```<code>2, [[1,2],[2,1]] => bijective
2, [[1,1],[1,2]] => surjective
3, [[1,1]] => injective
3, [[1,2],[2,3]] => injective
4, [[1,2],[2,2],[3,2],[4,2]] => nothing
2, [[1,2],[1,2]] => injective
3, [[1,1],[1,2],[1,3]] => surjective
2, [[1,1],[1,1],[2,2]] => bijective
</code>```

答:
Pyth - <s>10</s> <s>9</s> 13 bytes

```<code>im&{IdqSQSdE2
</code>```

Takes domain and codomain separately as allowed by comments in OP.

Test Suite.

Body:
Pyth - <s>10</s> <s>9</s> 13 bytes

im&{IdqSQSdE2

Takes domain and codomain separately as allowed by comments in OP.

Test Suite.


问:
Mean bits: an average challenge
Given an integer N >= 1, output the mean number of bits in an integer from 0 to N - 1

Specification

The output can be calculated as the sum of the number of bits in the binary representation of each integer from 0 to N-1, divided by N.

The binary representation of an integer has no leading zeroes in this context, with the exception of zero, which is represented as 0 in binary.

The output should be accurate to at least 7 significant figures.

Example

N = 6

```<code>0: 0   : 1 bit
1: 1   : 1 bit
2: 10  : 2 bits
3: 11  : 2 bits
4: 100 : 3 bits
5: 101 : 3 bits
</code>```

Mean number of bits = (1 + 1 + 2 + 2 + 3 + 3) / 6 = 2

Test cases

Input => output

```<code>1 => 1
2 => 1
3 => 1.3333333
4 => 1.5
5 => 1.8
6 => 2
7 => 2.1428571
</code>```

Leaderboard Snippet

(from here)

var QUESTION_ID=80586,OVERRIDE_USER=20283;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:400px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Note that the sum (before dividing to find the mean) is a sequence on OEIS.

Title: Mean bits: an average challenge

Body:
Haskell, 50 bytes

r x|x<1=0|1<2=1+r(x/2)
f n=(sum(r<$>[0..n-1])+1)/n


问:
Javascript left-pad golf

Introduction

In the wake of the left-pad npm package fallout, let's have a code golf for implementing left-pad.

The left-pad function consists of 2 default arguments and 1 additional argument, in the form string, length, (padchar). If the padchar is not given, this is standardized to a space character. Let's take an example with two arguments:

```<code>left_pad("abc", 6)
</code>```

First, we observe the length of the string, which is 3. After this, we need to pad this string in the left until the length of the full string has reached the length given in the function. In this case 6. Since the padchar is not given, we need to pad this with spaces:

```<code>   abc
</code>```

This is a string with 3 spaces and the initial string, resulting into a string with length 6. Here is an example with the padchar given:

```<code>left_pad("abc", 6, "-")
</code>```

We just do the same as the example above, but replace the spaces with the padchar. In this case, the hyphen:

```<code>---abc
</code>```

The Task

Given the string, length, and maybe the additional argument padchar, output the left-padded string. You can assume that the length number is equal or greater than the length of the string. The padchar will always consist of 1 character.

Test cases

```<code>left_pad("string", length, ("padchar")) === "left-padded string"

left_pad("foo", 5) === "  foo"
left_pad("foobar", 6) === "foobar"
left_pad("1", 2, "0") === "01"
left_pad("1", 2, "-") === "-1"
</code>```

This is code-golf, so the submission with the smallest number of bytes wins!

答:
JavaScript ES7, 16 bytes

```<code>''.padStart.bind
</code>```

built-ins ftw! Only works on Firefox 48 and above. Valid as this feature was added March 12.

This takes input like:

```<code>(''.padStart.bind)(arg1)(arg2,arg3)
</code>```

Title: Javascript left-pad golf

Body:
JavaScript ES7, 16 bytes

''.padStart.bind

built-ins ftw! Only works on Firefox 48 and above. Valid as this feature was added March 12.

This takes input like:

(''.padStart.bind)(arg1)(arg2,arg3)


Title: Mean bits: an average challenge

Body:
Given an integer N >= 1, output the mean number of bits in an integer from 0 to N - 1

Specification

The output can be calculated as the sum of the number of bits in the binary representation of each integer from 0 to N-1, divided by N.

The binary representation of an integer has no leading zeroes in this context, with the exception of zero, which is represented as 0 in binary.

The output should be accurate to at least 7 significant figures.

Example

N = 6

```<code>0: 0   : 1 bit
1: 1   : 1 bit
2: 10  : 2 bits
3: 11  : 2 bits
4: 100 : 3 bits
5: 101 : 3 bits
</code>```

Mean number of bits = (1 + 1 + 2 + 2 + 3 + 3) / 6 = 2

Test cases

Input => output

```<code>1 => 1
2 => 1
3 => 1.3333333
4 => 1.5
5 => 1.8
6 => 2
7 => 2.1428571
</code>```

Leaderboard Snippet

(from here)

var QUESTION_ID=80586,OVERRIDE_USER=20283;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:400px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Note that the sum (before dividing to find the mean) is a sequence on OEIS.

Body:
J, 22 bytes

[:(+/%#)[:([:##:)"0 i.
Usage:

    bin =: [:(+/%#)[:([:##:)"0 i.
    bin 7
2.14286


问:
Will the beam hit?
A laser shoots a straight beam in one of the four orthogonal directions, indicated by <>^v. Determine whether it will hit the target O on a rectangular grid.

Each of these will hit (True):

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

>O.
...

v....
O....

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

These will miss (False):

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

......
.....>
O.....
......
......

.O.
...
.v.

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

Input: A rectangular grid of ., sized at least 2x2, with exactly one target O and one laser that's one of <>^v. The lines can be a list of strings, a 2D array or nested list of characters, or a single newline-separated string with an optional trailing newline.

Output: A consistent truthy value if the laser beam hits the target, and a consistent falsy value if it misses.

I'll consider submissions that don't use regular expressions (or built-in pattern-based string matching) as a separate category. If you put (no regex) after the language name, your answer will appear separately in the leaderboard.

var QUESTION_ID=80196,OVERRIDE_USER=20260;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/80196/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

```

答:
C (ANSI) (No regex), 237 bytes

```<code>#define l b[1][i]
main(i,b,c,d,x,y,z,p)char **b;{for(y=z=i=0,x=1;z<2&&(l==10?x=0,++y:1);i++,x++)if(l>46){if(l!=79)p=l;if(!z++)c=x,d=y;}i--;x--;z=(c==x)*((p=='v')*(l==79)+(p==94)*(l==p))+(d==y)*((p==60)*(l==p)+(p==62)*(l==79));return z;}
</code>```

Expanded:

```<code>#define l b[1][i]
main(i,b,c,d,x,y,z,p)char **b;{
    for(y=z=i=0,x=1;z<2&&(l==10?x=0,++y:1);i++,x++)
        if(l>46){if(l!=79)p=l;if(!z++)c=x,d=y;}
    i--;x--;
    z=(c==x)*((p=='v')*(l==79)+(p==94)*(l==p))+(d==y)*((p==60)*(l==p)+(p==62)*(l==79));
    printf("%i\n",z);
    return z;
}
</code>```

I think I took a decently different approach here compared to the Java or C# implementations. I got coordinates of the 'O' and arrow ((c,d) and (x,y)) and then compared them to see if the arrow was pointing in the correct direction.

Returns 0 if false and 1 if true

Title: Will the beam hit?

Body:
C (ANSI) (No regex), 237 bytes

#define l b[1][i]
main(i,b,c,d,x,y,z,p)char **b;{for(y=z=i=0,x=1;z<2&&(l==10?x=0,++y:1);i++,x++)if(l>46){if(l!=79)p=l;if(!z++)c=x,d=y;}i--;x--;z=(c==x)*((p=='v')*(l==79)+(p==94)*(l==p))+(d==y)*((p==60)*(l==p)+(p==62)*(l==79));return z;}

Expanded:

#define l b[1][i]
main(i,b,c,d,x,y,z,p)char **b;{
    for(y=z=i=0,x=1;z<2&&(l==10?x=0,++y:1);i++,x++)
        if(l>46){if(l!=79)p=l;if(!z++)c=x,d=y;}
    i--;x--;
    z=(c==x)*((p=='v')*(l==79)+(p==94)*(l==p))+(d==y)*((p==60)*(l==p)+(p==62)*(l==79));
    printf("%i\n",z);
    return z;
}

I think I took a decently different approach here compared to the Java or C# implementations. I got coordinates of the 'O' and arrow ((c,d) and (x,y)) and then compared them to see if the arrow was pointing in the correct direction.

Returns 0 if false and 1 if true


Title: Female and Male Sequences

Body:
Julia, 54 bytes

f(n,x=1,y=0)=n>1?f(n-.5,[y;-x[y[k=end]+1]+k],x):[x y]'

Try it online!


答:
Pyth, 15 bytes

```<code>+!-SQJeC{E*2{IJ
</code>```

The output is identified by:

```<code>nothing   : 0
surjective: 1
injective : 2
bijective : 3
</code>```

In pseudocode,

```<code>                  Q=input()                 # pre-initialized var, 'n'
+                 sum(                      # sur=1,in=2,thus bi=sur+in=3,no=0
 !                  not(                    # if 'filtrate'=[], true/surjective
  -SQ                 filter(range(1,Q),    # filter codomain by range
     JeC{E              J=transpose(deduplicate(input()))[-1]
                    ))  # find the "redundant" range, may corrspnd to diffrnt args
 *2{IJ              2*invariant(J,deduplicate)
                  ) # if J(redundnt range) invariant undr dduplicatn, true/injectiv
</code>```

Test suite

Currently, the test suite returns two False's, namely for case 2 and case -2 (second-to-last). This has to do with the definition of "injective", and will be discussed with the OP.

Title: Surjective, Injective, Bijective, or Nothing?

Body:
Given a mapping from the integers from 1 to N to the integers from 1 to N, determine if the mapping is surjective, injective, bijective, or nothing.

You may choose any character/digit for the four outputs.

Specs

Input format: n, arrays of pairs (n is the highest number in the domain and range)

For example, if the first number is 3, then both the domain and the co-domain are {1,2,3}.

For example, {i+1 | i from 1 to 9} (n=10) is represented by 10, [[1,2],[2,3],...,[9,10]].

The input may contain duplicate.

Testcases

```<code>2, [[1,2],[2,1]] => bijective
2, [[1,1],[1,2]] => surjective
3, [[1,1]] => injective
3, [[1,2],[2,3]] => injective
4, [[1,2],[2,2],[3,2],[4,2]] => nothing
2, [[1,2],[1,2]] => injective
3, [[1,1],[1,2],[1,3]] => surjective
2, [[1,1],[1,1],[2,2]] => bijective
</code>```

Body:
Pyth, 15 bytes

+!-SQJeC{E*2{IJ

The output is identified by:

nothing   : 0
surjective: 1
injective : 2
bijective : 3

In pseudocode,

                  Q=input()                 # pre-initialized var, 'n'
+                 sum(                      # sur=1,in=2,thus bi=sur+in=3,no=0
 !                  not(                    # if 'filtrate'=[], true/surjective
  -SQ                 filter(range(1,Q),    # filter codomain by range
     JeC{E              J=transpose(deduplicate(input()))[-1]
                    ))  # find the "redundant" range, may corrspnd to diffrnt args
 *2{IJ              2*invariant(J,deduplicate)
                  ) # if J(redundnt range) invariant undr dduplicatn, true/injectiv

<a href="http://pyth.herokuapp.com/?code=q%2B%21-SQJeC%7BE%2A2%7BIJE&test_suite=1&test_suite_input=2%0A%5B%5B1%2C2%5D%2C%5B2%2C1%5D%5D%0A3%0A2%0A%5B%5B1%2C1%5D%2C%5B1%2C2%5D%5D%0A1%0A3%0A%5B%5B1%2C1%5D%5D%0A2%0A3%0A%5B%5B1%2C2%5D%2C%5B2%2C3%5D%5D%0A2%0A4%0A%5B%5B1%2C2%5D%2C%5B2%2C2%5D%2C%5B3%2C2%5D%2C%5B4%2C2%5D%5D%0A0%0A2%0A%5B%5B1%2C2%5D%2C%5B1%2C2%5D%5D%0A2%0A3%0A%5B%5B1%2C1%5D%2C%5B1%2C2%5D%2C%5B1%2C3%5D%5D%0A1%0A2%0A%5B%5B1%2C1%5D%2C%5B1%2C1%5D%2C%5B2%2C2%5D%5D%0A3&debug=0&input_size=3" rel="nofollow">Test suite

Currently, the test suite returns two False's, namely for case 2 and case -2 (second-to-last). This has to do with the definition of "injective", and will be discussed with the OP.


问:
The Nine Pattern

Introduction

I stumbled across this (useless) pattern the other day while I was watching TV.
I named it "the 9 pattern" because the first number to use it was 9.
The gist of it is, you enter a number (let's say x), and then you get back:

x

x + (x / 3) [let's call this y]

two-thirds of y [let's call this z]

z + 1

So, if I put inside this pattern the number 9 as x, this is what would come out:

9 (9)

12 (9 + 9 / 3) [9 over 3 is 3, and 9 + 3 is 12]

8 (12 times two-thirds) [a third of 12 is 4, and 4 * 2 is 8]

9 (8 + 1 is 9)

Challenge

Write me a function (in any programming language) that takes in a number, and outputs an integer array using the pattern.

Somewhat like this psuedo-code:

```<code>function ninePattern(int myInt) returns IntegerArray {
    int iterationA = myInt + (myInt / 3);
    int iterationB = iterationA * (2 / 3);
    int iterationC = iterationB + 1;
    IntegerArray x = [myInt, iterationA, iterationB, iterationC];
    return x;
}
</code>```

Clarifications

Discussions have been arousing in comments regarding the specifications of the question. This section is meant to clarify some of those.

"better to count in bytes than characters"

I picked characters because (for me, at least) it would be easier to judge. Of course, I can't change that now. (lots of answers are already posted)

"rounding"

Rounding follows this rhyme:

If it's 5 or more, raise the score

  If it's 4 or less, let it rest

Simply, put, if it is something like 4.7 or 3.85, round them to 5 and 4 respectively.

Examples

```<code>Input => Result
9 => [9, 12, 8, 9]
8 => [8, 11, 7, 8]
6 => [6, 8, 5, 6]
23 => [23, 31, 21, 22]
159 => [159, 212, 141, 142]
</code>```

If, however, the numbers are something like 2.3 or 10.435446, round them to 2 and 10 respectively.

"language support"

You are free to not use functions and/or arrays IF AND ONLY IF the language of your choice does not support them.  If it does (even if it will increase your characters count), you must use them.

答:
Dyalog APL, 33 bytes

```<code>(⌽,{1+⊃⍵})∘{⍵,⍨3÷⍨2×⊃⍵}(3÷⍨4∘×),⊢
</code>```

Title: The Nine Pattern

Body:
Dyalog APL, 33 bytes

(⌽,{1+⊃⍵})∘{⍵,⍨3÷⍨2×⊃⍵}(3÷⍨4∘×),⊢


答:
PHP, <s>54</s> 48 bytes

Uses Windows-1252 encoding.

```<code>function(&$s,$l,$p=~ß){$s=str_pad($s,$l,$p,0);};
</code>```

Run like this (-d added for easthetics only):

```<code>php -r '$f = function(&$s,$l,$p=~ß){$s=str_pad($s,$l,$p,0);}; $s="foo";$f($s,5);echo"$s\n";' 2>/dev/null
</code>```

Old version (without the builtin):

```<code>function(&$s,$l,$p=~ß){for(;strlen($s)<$l;)$s=$p.$s;};
</code>```

Tweaks

Saved 6 bytes by using str_pad instead of a loop. Leaving the old one for reference, as builtins are frowned upon

Title: Javascript left-pad golf

Body:
Introduction

In the wake of the left-pad npm package fallout, let's have a code golf for implementing left-pad.

The left-pad function consists of 2 default arguments and 1 additional argument, in the form string, length, (padchar). If the padchar is not given, this is standardized to a space character. Let's take an example with two arguments:

```<code>left_pad("abc", 6)
</code>```

First, we observe the length of the string, which is 3. After this, we need to pad this string in the left until the length of the full string has reached the length given in the function. In this case 6. Since the padchar is not given, we need to pad this with spaces:

```<code>   abc
</code>```

This is a string with 3 spaces and the initial string, resulting into a string with length 6. Here is an example with the padchar given:

```<code>left_pad("abc", 6, "-")
</code>```

We just do the same as the example above, but replace the spaces with the padchar. In this case, the hyphen:

```<code>---abc
</code>```

The Task

Given the string, length, and maybe the additional argument padchar, output the left-padded string. You can assume that the length number is equal or greater than the length of the string. The padchar will always consist of 1 character.

Test cases

```<code>left_pad("string", length, ("padchar")) === "left-padded string"

left_pad("foo", 5) === "  foo"
left_pad("foobar", 6) === "foobar"
left_pad("1", 2, "0") === "01"
left_pad("1", 2, "-") === "-1"
</code>```

This is code-golf, so the submission with the smallest number of bytes wins!

Body:
PHP, <s>54</s> 48 bytes

Uses Windows-1252 encoding.

function(&$s,$l,$p=~ß){$s=str_pad($s,$l,$p,0);};

Run like this (-d added for easthetics only):

php -r '$f = function(&$s,$l,$p=~ß){$s=str_pad($s,$l,$p,0);}; $s="foo";$f($s,5);echo"$s\n";' 2>/dev/null

Old version (without the builtin):

function(&$s,$l,$p=~ß){for(;strlen($s)<$l;)$s=$p.$s;};

Tweaks

Saved 6 bytes by using str_pad instead of a loop. Leaving the old one for reference, as builtins are frowned upon


答:
Grime v0.1, 31 bytes

```<code>n`\>.*a|a.*\<|\v/./*/a|a/./*/\^
</code>```

Not a very interesting solution. Prints 1 for truthy instances, and 0 for falsy ones. Try it online!

Explanation

We simply search the input rectangle for a minimal-size (n×1 or 1×n) pattern that contains the laser and target in the correct order.
The n` flag makes the interpreter print the number of matches, of which there will always be at most one.
The rest of the line consists of four patterns separated by |-characters, which means a logical OR: a rectangle is matched if it matches one of the patterns.
The patterns work as follows:

```<code>\>.*a    Literal ">", horizontal row of any chars, one alphabetic char
a.*\<    One alphabetic char, horizontal row of any chars, literal "<"
\v/./*/a Literal "v", on top of vertical column of any chars, on top of one alphabetic char
a/./*/\^ One alphabetic char, on top of vertical column of any chars, on top of literal "^"
</code>```

Title: Will the beam hit?

Body:
A laser shoots a straight beam in one of the four orthogonal directions, indicated by <>^v. Determine whether it will hit the target O on a rectangular grid.

Each of these will hit (True):

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

>O.
...

v....
O....

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

These will miss (False):

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

......
.....>
O.....
......
......

.O.
...
.v.

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

Input: A rectangular grid of ., sized at least 2x2, with exactly one target O and one laser that's one of <>^v. The lines can be a list of strings, a 2D array or nested list of characters, or a single newline-separated string with an optional trailing newline.

Output: A consistent truthy value if the laser beam hits the target, and a consistent falsy value if it misses.

I'll consider submissions that don't use regular expressions (or built-in pattern-based string matching) as a separate category. If you put (no regex) after the language name, your answer will appear separately in the leaderboard.

var QUESTION_ID=80196,OVERRIDE_USER=20260;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/80196/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:
Grime v0.1, 31 bytes

n`\>.*a|a.*\<|\v/./*/a|a/./*/\^

Not a very interesting solution. Prints 1 for truthy instances, and 0 for falsy ones. Try it online!

Explanation

We simply search the input rectangle for a minimal-size (n×1 or 1×n) pattern that contains the laser and target in the correct order.
The n` flag makes the interpreter print the number of matches, of which there will always be at most one.
The rest of the line consists of four patterns separated by |-characters, which means a logical OR: a rectangle is matched if it matches one of the patterns.
The patterns work as follows:

\>.*a    Literal ">", horizontal row of any chars, one alphabetic char
a.*\<    One alphabetic char, horizontal row of any chars, literal "<"
\v/./*/a Literal "v", on top of vertical column of any chars, on top of one alphabetic char
a/./*/\^ One alphabetic char, on top of vertical column of any chars, on top of literal "^"


问:
Look and Say sequence in any base
We all already crossed the look and say sequence, and where asked to guess the next element. As its name tells it very well, you just have to say what you see :

```<code>1
1 1
2 1
1 2 1 1
1 1 1 2 2 1
3 1 2 2 1 1
...
</code>```

But, what if we had to use a different base to describe it? You could count it in base 3 as this OEIS squence do. You could even do it in whatever base you want! That will be your job in this challenge.

Goal

Your have to write a program or a function that will accept two integers as input, either by STDIN or as function arguments. The first one will be the base b you have to work in, the second one will be the number n of elements to output. As this sequence never changes for b>=4, you will assume 0<b<5.

The only restriction you have is to NOT use any base-converison built-in :).

The original sequence (in base 10) is the sequence A005150. It cannot be constructed simply by using a formula, so you can help yourself with the different implementations present on the sequence's page.

Sample output

Here are the first 10 elements for each b

```<code>for b=1:
1
11
111
1111
11111
111111
1111111
11111111
111111111
1111111111

for b=2:
1
11
101
111011
11110101
100110111011
111001011011110101
111100111010110100110111011
100110011110111010110111001011011110101
1110010110010011011110111010110111100111010110100110111011

for b=3:
1
11
21
1211
111221
1012211
1110112221
101102110211
111021101221101221
1011012211011222110112211

for b=4:
1
11
21
1211
111221
312211
13112211
1113212221
311312113211
132113111221131221
</code>```

You can use whatever formating you want as long it is readable (so you could output it in Python-like lists, separated by commas/newline...).

This is code-golf, so the shortest code in byte wins. Have fun !

答:
Pyth, 34 bytes

```<code>L?gbQ+y/bQ%bQ]bjms`Md.usyMsrN8tE]1
</code>```

Try it online!

Title: Look and Say sequence in any base

Body:
Pyth, 34 bytes

L?gbQ+y/bQ%bQ]bjms`Md.usyMsrN8tE]1

Try it online!


答:
Swift, 72 bytes

```<code>func f(n:Double)->Double{return n<1 ?1:f(n-1)+1+floor(log2(n))}
f(N-1)/N
</code>```

Title: Mean bits: an average challenge

Body:
Swift, 72 bytes

func f(n:Double)->Double{return n<1 ?1:f(n-1)+1+floor(log2(n))}
f(N-1)/N


问:
Proving you are the best StackExchange-User

Write one/two program(s)/function(s):

The first one should return a truthy value if given your Stack Exchange username.

~~Optional~~

An obfuscated one (as explained below) that does the same thing.

Rules for number 2:

May be no more than ten times the byte-count of number 1 or 100 bytes, whichever is higher.

Must be written in the same language as number 1.

Test cases

(for my case:)

```<code>input        output
-------------------
Seims        true
BestCoderXX  false
</code>```

Winning

This is code-golf, so shortest byte count for number one wins.

答:
Pyth

```<code>q1409257787840474805614C
</code>```

Test suite.

Encodes the input string in base-256, and then check if it is equal to 1409257787840474805614.

Body:
Pyth

q1409257787840474805614C

Test suite.

Encodes the input string in base-256, and then check if it is equal to 1409257787840474805614.


答:
Python 2 (Non-Competing)

This was posted before the rules were changed significantly.

```<code>False = True; True = False; True = True; print (`'Riker'.lower().upper()`=="Riker" and "Riker" == `raw_input()`) <> True and raw_input()=="Riker"
</code>```

Title: Proving you are the best StackExchange-User

Body:
Write one/two program(s)/function(s):

The first one should return a truthy value if given your Stack Exchange username.

~~Optional~~

An obfuscated one (as explained below) that does the same thing.

Rules for number 2:

May be no more than ten times the byte-count of number 1 or 100 bytes, whichever is higher.

Must be written in the same language as number 1.

Test cases

(for my case:)

```<code>input        output
-------------------
Seims        true
BestCoderXX  false
</code>```

Winning

This is code-golf, so shortest byte count for number one wins.

Body:
Python 2 (Non-Competing)

This was posted before the rules were changed significantly.

False = True; True = False; True = True; print (`'Riker'.lower().upper()`=="Riker" and "Riker" == `raw_input()`) <> True and raw_input()=="Riker"


问:
Reimplementing square root
Define a function, s, which takes a number and returns the square root.

No use of library functions, such as Java's Math.sqrt() or PHP's built in sqrt(), allowed.

答:
Python (13 chars)

f=.5.__rpow__

This is equivalent to f=lambda x:x**.5, but 3 bytes shorter.

ContentLicense: CC BY-SA 2.5

Title: Reimplementing square root


答:
Javascript

```<code>eval(function(B,á,l,i,n,t){if(n=function(B){return B},!"".replace(/^/,String)){for(;l--;)t[l]=i[l]||l;i=[function(B){return t[B]}],n=function(){return"\\w+"},l=1}for(;l--;)i[l]&&(B=B.replace(new RegExp("\\b"+n(l)+"\\b","g"),i[l]));return B}('3 4(0){2(!(0=="9á5")){{1 7}}6{{1 8}}}',10,10,"notMyName|return|if|function|HELLO_WORLD|lint|else|false|true|B".split("|"),0,{}));
</code>```

I first created a half-readable code, then I ran it trough RegPack, then an obfuscator, then a minifier, then RegPack again, and lastly a different minifier.

Note: RegPack is worse than an obfuscator

Made a slight modification on variable names after @LeakyNun pointed out something

Body:
Javascript

eval(function(B,á,l,i,n,t){if(n=function(B){return B},!"".replace(/^/,String)){for(;l--;)t[l]=i[l]||l;i=[function(B){return t[B]}],n=function(){return"\\w+"},l=1}for(;l--;)i[l]&&(B=B.replace(new RegExp("\\b"+n(l)+"\\b","g"),i[l]));return B}('3 4(0){2(!(0=="9á5")){{1 7}}6{{1 8}}}',10,10,"notMyName|return|if|function|HELLO_WORLD|lint|else|false|true|B".split("|"),0,{}));

I first created a half-readable code, then I ran it trough RegPack, then an obfuscator, then a minifier, then RegPack again, and lastly a different minifier.

Note: RegPack is worse than an obfuscator

Made a slight modification on variable names after @LeakyNun pointed out something


答:
Python 2 (Non-Competing)

This was posted before the rules were changed significantly.

```<code>print raw_input()=="Eᴀsᴛᴇʀʟʏ Iʀᴋ"
</code>```

Quite obfuscated to non-programmers or people who only code in brainfuck.

@Downvoters: Also serves to point out the definition of "obfuscated" needs to be fixed.

Body:
Python 2 (Non-Competing)

This was posted before the rules were changed significantly.

print raw_input()=="Eᴀsᴛᴇʀʟʏ Iʀᴋ"

Quite obfuscated to non-programmers or people who only code in brainfuck.

@Downvoters: Also serves to point out the definition of "obfuscated" needs to be fixed.


答:
05AB1E

```<code>žnžo‡"Vnrtmz"Q
</code>```

Uses the Atbash cipher.

Try it online

Body:
05AB1E

žnžo‡"Vnrtmz"Q

Uses the Atbash cipher.

Try it online


问:
ASCII's 95 Characters...95 Movie Quotes
Update: The winner has been decided, but the challenge is not over!

Finally, nearly 3 months after the question first started, someone has remained the last answerer for more than a week! Congratulations to jimmy23013 with his P1eq answer!

There are still however 8 characters left: 48KSaclw. If anyone is really ambitious they can keep on trying with those :D

Thanks a ton to everyone who participated, especially those of you who kept the contest going so long with multiple answers, notably KennyTM with a whopping 25 answers!!

Also, thanks to anyone who kept the answer list up to date, it was a great help :) (especially since I've been away from SE for a couple months :P).

Original Question:

In 2005 the American Film Institute produced AFI's 100 Years...100 Movie Quotes, a list of the best quotes in American cinema. Here they are listed exactly as they should be used in this challenge:

```<code>(answer  6) 1. "Frankly, my dear, I don't give a damn." - Rhett Butler
(answer  7) 2. "I'm gonna make him an offer he can't refuse." - Vito Corleone
(answer  5) 3. "You don't understand! I coulda had class. I coulda been a contender. I could've been somebody, instead of a bum, which is what I am." - Terry Malloy
(answer  3) 4. "Toto, I've a feeling we're not in Kansas anymore." - Dorothy Gale
5. "Here's looking at you, kid." - Rick Blaine
(answer  2) 6. "Go ahead, make my day." - Harry Callahan
(answer 11) 7. "All right, Mr. DeMille, I'm ready for my close-up." - Norma Desmond
(answer  8) 8. "May the Force be with you." - Han Solo
(answer 12) 9. "Fasten your seatbelts. It's going to be a bumpy night." - Margo Channing
(answer 13) 10. "You talking to me?" - Travis Bickle
(answer 16) 11. "What we've got here is failure to communicate." - Captain
(answer 15) 12. "I love the smell of napalm in the morning." - Lt. Col. Bill Kilgore
(answer  4) 13. "Love means never having to say you're sorry." - Jennifer Cavilleri Barrett
14. "The stuff that dreams are made of." - Sam Spade
(answer 18) 15. "E.T. phone home." - E.T.
(answer 20) 16. "They call me Mister Tibbs!" - Virgil Tibbs
17. "Rosebud." - Charles Foster Kane
(answer 10) 18. "Made it, Ma! Top of the world!" - Arthur "Cody" Jarrett
(answer 17) 19. "I'm as mad as hell, and I'm not going to take this anymore!" - Howard Beale
(answer 25) 20. "Louis, I think this is the beginning of a beautiful friendship." - Rick Blaine
(answer 26) 21. "A census taker once tried to test me. I ate his liver with some fava beans and a nice Chianti." - Hannibal Lecter
(answer  9) 22. "Bond. James Bond." - James Bond
(answer 22) 23. "There's no place like home." - Dorothy Gale
(answer 29) 24. "I am big! It's the pictures that got small." - Norma Desmond
25. "Show me the money!" - Rod Tidwell
(answer 31) 26. "Why don't you come up sometime and see me?" - Lady Lou
(answer 27) 27. "I'm walking here! I'm walking here!" - "Ratso" Rizzo
(answer 14) 28. "Play it, Sam. Play 'As Time Goes By.'" - Ilsa Lund
(answer 28) 29. "You can't handle the truth!" - Col. Nathan R. Jessup
(answer 23) 30. "I want to be alone." - Grusinskaya
(answer 30) 31. "After all, tomorrow is another day!" - Scarlett O'Hara
(answer  1) 32. "Round up the usual suspects." - Capt. Louis Renault
(answer 24) 33. "I'll have what she's having." - Customer
(answer 36) 34. "You know how to whistle, don't you, Steve? You just put your lips together and blow." - Marie "Slim" Browning
(answer 19) 35. "You're gonna need a bigger boat." - Martin Brody
(answer 39) 36. "Badges? We ain't got no badges! We don't need no badges! I don't have to show you any stinking badges!" - "Gold Hat"
(answer 40) 37. "I'll be back." - The Terminator
(answer 33) 38. "Today, I consider myself the luckiest man on the face of the earth." - Lou Gehrig
(answer 37) 39. "If you build it, he will come." - Shoeless Joe Jackson
(answer 43) 40. "My mama always said life was like a box of chocolates. You never know what you're gonna get." - Forrest Gump
(answer 34) 41. "We rob banks." - Clyde Barrow
(answer 38) 42. "Plastics." - Mr. Maguire
43. "We'll always have Paris." - Rick Blaine
(answer 49) 44. "I see dead people." - Cole Sear
(answer 21) 45. "Stella! Hey, Stella!" - Stanley Kowalski
(answer 32) 46. "Oh, Jerry, don't let's ask for the moon. We have the stars." - Charlotte Vale
(answer 35) 47. "Shane. Shane. Come back!" - Joey Starrett
(answer 42) 48. "Well, nobody's perfect." - Osgood Fielding III
(answer 51) 49. "It's alive! It's alive!" - Henry Frankenstein
(answer 41) 50. "Houston, we have a problem." - Jim Lovell
(answer 45) 51. "You've got to ask yourself one question: 'Do I feel lucky?' Well, do ya, punk?" - Harry Callahan
(answer 55) 52. "You had me at "hello."" - Dorothy Boyd
(answer 46) 53. "One morning I shot an elephant in my pajamas. How he got in my pajamas, I don't know." - Capt. Geoffrey T. Spaulding
(answer 44) 54. "There's no crying in baseball!" - Jimmy Dugan
(answer 59) 55. "La-dee-da, la-dee-da." - Annie Hall
(answer 60) 56. "A boy's best friend is his mother." - Norman Bates
(answer 47) 57. "Greed, for lack of a better word, is good." - Gordon Gekko
(answer 56) 58. "Keep your friends close, but your enemies closer." - Michael Corleone
(answer 48) 59. "As God is my witness, I'll never be hungry again." - Scarlett O'Hara
(answer 50) 60. "Well, here's another nice mess you've gotten me into!" - Oliver
(answer 65) 61. "Say "hello" to my little friend!" - Tony Montana
(answer 66) 62. "What a dump." - Rosa Moline
(answer 52) 63. "Mrs. Robinson, you're trying to seduce me. Aren't you?" - Benjamin Braddock
(answer 61) 64. "Gentlemen, you can't fight in here! This is the War Room!" - President Merkin Muffley
(answer 68) 65. "Elementary, my dear Watson." - Sherlock Holmes
(answer 64) 66. "Take your stinking paws off me, you damned dirty ape." - George Taylor
(answer 53) 67. "Of all the gin joints in all the towns in all the world, she walks into mine." - Rick Blaine
(answer 72) 68. "Here's Johnny!" - Jack Torrance
(answer 71) 69. "They're here!" - Carol Anne Freeling
(answer 73) 70. "Is it safe?" - Dr. Christian Szell
(answer 54) 71. "Wait a minute, wait a minute. You ain't heard nothin' yet!" - Jakie Rabinowitz/Jack Robin
(answer 77) 72. "No wire hangers, ever!" - Joan Crawford
(answer 67) 73. "Mother of mercy, is this the end of Rico?" - Cesare Enrico "Rico" Bandello
(answer 70) 74. "Forget it, Jake, it's Chinatown." - Lawrence Walsh
(answer 74) 75. "I have always depended on the kindness of strangers." - Blanche DuBois
(answer 78) 76. "Hasta la vista, baby." - The Terminator
(answer 75) 77. "Soylent Green is people!" - Det. Robert Thorn
(answer 76) 78. "Open the pod bay doors, HAL." - Dave Bowman
(answer 80) 79. Striker: "Surely you can't be serious." Rumack: "I am serious...and don't call me Shirley." - Ted Striker and Dr. Rumack
(answer 84) 80. "Yo, Adrian!" - Rocky Balboa
(answer 81) 81. "Hello, gorgeous." - Fanny Brice
(answer 83) 82. "Toga! Toga!" - John "Bluto" Blutarsky
(answer 63) 83. "Listen to them. Children of the night. What music they make." - Count Dracula
(answer 87) 84. "Oh, no, it wasn't the airplanes. It was Beauty killed the Beast." - Carl Denham
(answer 88) 85. "My precious." - Gollum
(answer 86) 86. "Attica! Attica!" - Sonny Wortzik
(answer 57) 87. "Sawyer, you're going out a youngster, but you've got to come back a star!" - Julian Marsh
(answer 82) 88. "Listen to me, mister. You're my knight in shining armor. Don't you forget it. You're going to get back on that horse, and I'm going to be right behind you, holding on tight, and away we're gonna go, go, go!" - Ethel Thayer
(answer 58) 89. "Tell 'em to go out there with all they got and win just one for the Gipper." - Knute Rockne
(answer 90) 90. "A martini. Shaken, not stirred." - James Bond
(answer 85) 91. "Who's on first." - Dexter
(answer 62) 92. "Cinderella story. Outta nowhere. A former greenskeeper, now, about to become the Masters champion. It looks like a mirac...It's in the hole! It's in the hole! It's in the hole!" - Carl Spackler
(answer 69) 93. "Life is a banquet, and most poor suckers are starving to death!" - Mame Dennis
(answer 89) 94. "I feel the need - the need for speed!" - Lt. Pete "Maverick" Mitchell and Lt. Nick "Goose" Bradshaw
(answer 79) 95. "Carpe diem. Seize the day, boys. Make your lives extraordinary." - John Keating
(answer 91) 96. "Snap out of it!" - Loretta Castorini
(answer 92) 97. "My mother thanks you. My father thanks you. My sister thanks you. And I thank you." - George M. Cohan
(answer 93) 98. "Nobody puts Baby in a corner." - Johnny Castle
(answer 94) 99. "I'll get you, my pretty, and your little dog, too!" - Wicked Witch of the West
(answer 95) 100. "I'm the king of the world!" - Jack Dawson
</code>```

(Feel free to mark quotes as used.)

There are 95 printable ASCII characters (hex codes 20 to 7E), that's pretty close to 100:

```<code> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
</code>```

In this challenge users will take turns writing programs that print one of the movie quotes using a new programming language and a smaller subset of printable ASCII each time.

How This Works

I've already submitted the first answer and I've labeled it 95 since I was allowed to use all 95 printable ASCII characters in my program. It is a Python program that prints the 100th quote, "I'm the king of the world!" - Jack Dawson, to stdout.

The second person to answer needs to choose a new quote, a new programming language, and one of the 95 printable ASCII characters to exclude from their code. They must write a program without using this character that prints their chosen quote to stdout. They should mark their answer as 94 since they had 94 printable ASCII characters to work with (think of it like a countdown).

The third person to answer must choose a quote and language that haven't been used in any previous answers (only 95 and 94 in this case), and a new character to forgo. They must not use this character or any previously forbidden characters in their code. They mark their answer as 93.

This answering process continues like this until all printable ASCII characters are forbidden and someone gives the "1" answer, or much more likely, no one can figure out how to answer again.

Rules (please read carefully)

It's important to understand that only one person can answer at a time and each answer depends on the one before it. There should never be two answers with the same number, quote, or programming language.

There's bound to be clashing answers submitted at the same time, and that's ok. If that happens the person who technically answered later should quickly (like 10 min or less) delete their post or edit it so it becomes the next answer. Otherwise, don't edit code unless truly necessary. Editing posts to only fix formatting is encouraged.

Specific Rules

A user who just answered must wait at least an hour before answering again.

A user may not answer twice in a row.

The quote number you choose must not be more than 5 below your answer number. For example, answer 90 can choose any unused quote from number 85 to 100. This leaves the better quotes for the harder answers. Other than this rule the quote numbering is irrelevant.

Programs may only contain tabs, newlines, and the printable ASCII character that are not forbidden so far. (Tabs and newlines are never forbidden.)

There is no program length limit, but there may not be more that 64 tabs or 64 newlines in your program.

Languages are considered distinct if they are commonly referred to by different names. Different versions of programming languages are not considered distinct. (Markup languages like HTML do count but full on programming languages are preferred.) Your language must have existed prior to the start of this contest.

If your language does not have stdout use some similar text output mechanism.

Your program should not take input or have unexpected side effects like creating files.

Please make sure your program is valid. It should be able to run as a full program as is, not just in a REPL environment.

Note that the "quote" you must output includes the quotation marks and the person who said it (but not the quote number). Your program should solely produce your quote exactly as it appears in the list above (a leading/trailing newline is fine).

Formatting

Please format your answers like this, {stuff in curly braces} needs to be replaced:

```<code>#{answer number}. {language}, uses no <code>{the forbidden character you just chose}</code>

    {program}

Output is quote {quote number}:

    {program output, should be identical to quote}

[Previously forbidden:]({url of previous answer (hit "share" just below it)}) <code>{the previous answerer's forbidden character followed by his previously forbidden list}</code>

{anything else you wish to say}
</code>```

The  tags can be replaced with backticks (`) as long as no backtick occurs within them.

Scoring

The communal goal of this challenge is to keep answers coming for as long as possible.

The official winner is the user who answers last, after a week of no additional answers. I will accept their last answer.

Answer List (newest first)

4 Progressive Unary

a Bueue

c Udage

S 1L_a105

w Binaryfuck

K Subskin

l 23

n P1eq

t Addleq

9 x86 Machine Code

r BSM

D ShaFuck 0.2

u Villmark

O PDP-11 machine code

f ProgFk

i NUMPAD

H Tri

2 ferNANDo

P Pointy

m Subleq

G FlogScript

? Nqubl

% Glypho

! 3var

q ETA

j BrainSpace 1.0

V Insomnia

` asdf

6 Lazy K

C !Py!Batch 1.5

T Fuckfuck

F PoGo

R Golunar

b 6502 machine code + Apple II System Monitor

Y Headsecks

I BRB

U Braincrash

Z Ecstatic

M Farm

A Enema

L ADJUST

$ Beatnik

N Rebmu

g Dupdog

B Gammaplex

J Fuck4

5 A0A0

W gs2

: l33t

h Tonoco

E Malbolge

k D1ffe7e45e

1 evil

Q CaneCode

d Grass

# URSL

| Burlesque

x Emmental

~ Applesoft BASIC

^ Forth

7 80386 machine code + DOS

_ Argh!

v Rexx

} AlphaBeta

o Super Stack!

e Pyth

z Plain TeX

> WASD

] POSIX shell

& Gibberish

/ GolfScript

* x86_64 assembly

0 AppleScript

X Deadfish~

, Spoon

- oOo CODE

= J

@ Mathematica

. Perl

+ DNA#

< Pi

) Postscript

[ ABC

s dc

{ HTML

( Unary

; Ook!

' CJam

  PHP

" Brainfuck

\ Marbelous

3 C++

y Ruby

p JavaScript

     Python

(Feel free to edit if incorrect or out of date)

This question works best when you sort by "oldest".

NOTE: Like my last question, this is a test of a new challenge type where each answer depends on the last and increases in difficulty. Come to chat or meta to discuss either question or the idea in general.

答:
5. Binaryfuck (uses no w)

(new lines for clarification only)

```<code>8
448448c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c4S
448448c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c4S
... many similar lines ...
448448c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c4S
</code>```

The whole program sans new lines is 39,790 bytes long. You may find the full program in http://pastebin.com/ybaWpcZG. The program after bzip2 + base64 is:

```<code>QlpoOTFBWSZTWaAjCX8AGnyLAARACAAIADABlBsthJ6qMJqSAqao3COyMkrqivNZbMtWykCFNoNEGsW2
zSwljFURtTKINbGxG2ixrMNtVFFtFrRtiNRW2xqmaE2k2jFY0WotSVpNBiNWU2xjVamyhpbGpTFFKZpN
m2220QW1SVbIC2AmZbUpC2pawTaqmy2kbahTNjKYVmbUJVmq2LUmLYqaCYpJZi1USvcFBTyUkp8XckU4
UJCgIwl/
</code>```

The SHA-1 sum after decompressing should be 9297a4c847aade08f93813dca66f79f8271bec45.

Output is quote 3:

```<code>"You don't understand! I coulda had class. I coulda been a contender. I could've been somebody, instead of a bum, which is what I am." - Terry Malloy
</code>```

Previously forbidden:

```<code>?!"#$%&'()*+,-./01235679:;<=>@[\]^_` AbBCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRstTuUvVWxXyYzZ{|}~
</code>```

Remaining characters:

4 8 S a c

Binaryfuck is a BrainFuck variant. The 8 instructions are encoded to 3 bits, and the whole bitstring is converted to a base-32 number (so it is similar to Unary).

The specification does not clarify the character set, but since the input is base-32 "number" I assume this means case-insensitive.

Every base-32 digit occupy 5 bits, so we analyze the commands produced every 3 digits (15 bits), where there are the following interesting instructions:

c48 = <+>-+ i.e. increase the value of the previous cell

c4S = <+><. i.e. move to the previous cell, increment and then output it

448 = -+>-+ i.e. move to the next cell

We also start the program with a 8 i.e. 1000₂, as the 1 in the most-significant-digit tells the Binaryfuck compiler where is the start of the code.

Generator:

```<code>quote = r'''"You don't understand! I coulda had class. I coulda been a contender. I could've been somebody, instead of a bum, which is what I am." - Terry Malloy'''

print('8')
#print('+')
for c in quote:
    print('448448' + 'c48' * (ord(c) - 1) + 'c4S')
    #print('-+>-+' + '-+>-+' + '<+>-+' * (ord(c) - 1) + '<+><.')
</code>```

Title: ASCII's 95 Characters...95 Movie Quotes

Body:
5. Binaryfuck (uses no w)

(new lines for clarification only)

8
448448c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c4S
448448c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c4S
... many similar lines ...
448448c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c48c4S

The whole program sans new lines is 39,790 bytes long. You may find the full program in http://pastebin.com/ybaWpcZG. The program after bzip2 + base64 is:

QlpoOTFBWSZTWaAjCX8AGnyLAARACAAIADABlBsthJ6qMJqSAqao3COyMkrqivNZbMtWykCFNoNEGsW2
zSwljFURtTKINbGxG2ixrMNtVFFtFrRtiNRW2xqmaE2k2jFY0WotSVpNBiNWU2xjVamyhpbGpTFFKZpN
m2220QW1SVbIC2AmZbUpC2pawTaqmy2kbahTNjKYVmbUJVmq2LUmLYqaCYpJZi1USvcFBTyUkp8XckU4
UJCgIwl/

The SHA-1 sum after decompressing should be 9297a4c847aade08f93813dca66f79f8271bec45.

Output is quote 3:

"You don't understand! I coulda had class. I coulda been a contender. I could've been somebody, instead of a bum, which is what I am." - Terry Malloy

Previously forbidden:

?!"#$%&'()*+,-./01235679:;<=>@[\]^_` AbBCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRstTuUvVWxXyYzZ{|}~

Remaining characters:

4 8 S a c

Binaryfuck is a BrainFuck variant. The 8 instructions are encoded to 3 bits, and the whole bitstring is converted to a base-32 number (so it is similar to Unary).

The specification does not clarify the character set, but since the input is base-32 "number" I assume this means case-insensitive.

Every base-32 digit occupy 5 bits, so we analyze the commands produced every 3 digits (15 bits), where there are the following interesting instructions:

c48 = <+>-+ i.e. increase the value of the previous cell

c4S = <+><. i.e. move to the previous cell, increment and then output it

448 = -+>-+ i.e. move to the next cell

We also start the program with a 8 i.e. 1000₂, as the 1 in the most-significant-digit tells the Binaryfuck compiler where is the start of the code.

Generator:

quote = r'''"You don't understand! I coulda had class. I coulda been a contender. I could've been somebody, instead of a bum, which is what I am." - Terry Malloy'''

print('8')
#print('+')
for c in quote:
    print('448448' + 'c48' * (ord(c) - 1) + 'c4S')
    #print('-+>-+' + '-+>-+' + '<+>-+' * (ord(c) - 1) + '<+><.')


问:
Golf a golf-scorer
As a kid, I used to play the card game "golf" a lot. Your challenge, should you choose to accept it, is to calculate the score of a golf hand. Since there are over 9000 variations on this card game1, we will go with the rules I remember playing.

Rules (of the game)

You end a round with 6 cards, and you want as few points as possible.

Jokers are not used.

Aces and 2s are worth -1, and -2 points respectively.

Jacks and Kings are both worth 0 points.

Cards from 3 to 10 are worth face value. However, these are cancelled when you pair them off. For example, a 5 is worth 5 points, but two 5s are worth zero. Three 5s are worth 5 points, (since the first 2 are paired off, but the 3rd is not.) and four 5s are worth 0 (since it makes 2 pairs).

Queens are worth 15 points. Queens cannot be cancelled, e.g. 2 queens are worth 30 points.

Rules (of the challenge)

Input will be an array of integers, or 6 individual integers. Whichever one you prefer. 1 represents an ace, 2-10 represents 2-10, and Jack, Queen, and King represents 11, 12, and 13. Output is the score of the hand according to the rules above. You can safely assume that all inputs are valid, e.g. no number appears more than 4 times, and all numbers are in the range [1, 13]. Input and output can be in any reasonable format.

Test IO:

```<code>[11, 10, 3, 1, 2, 2]    --> 8
[4, 5, 5, 3, 8, 7]      --> 22
[2, 2, 2, 2, 1, 1]      --> -10 (The lowest score possible)
[12, 12, 12, 12, 10, 9] --> 79 (The highest score possible)
[9, 9, 9, 9, 11, 1]     --> -1
[8, 8, 8, 8, 11, 13]    --> 0
[10, 9, 3, 7, 12, 2]    --> 42
[1, 2, 3, 4, 5, 6]      --> 15
[10, 9, 2, 3, 4, 1]     --> 23
[10, 3, 12, 3, 7, 12]   --> 47
</code>```

Shortest answer in bytes wins!

1not really, but there are a lot of variations.

答:
Pyth, <s>28</s> <s>27</s> 25 bytes

```<code>s+*L%/Qd2}3Tm?<d3_d*15q12
</code>```

Try it online. Test suite.

Explanation

Firstly, Pyth auto-appends some variables. The code is now s+*L%/Qd2}3Tm?<d3_d*15q12dQ.

}3T generates the list [3, 4, 5, 6, 7, 8, 9, 10].

Multiply each number in that list (*L) by the count of that number in the input (/Qd), modulo 2 (%…2). The result is 0 for paired numbers and the number itself for non-paired ones.

Map over the input numbers (m…Q):

If the number is less than 3 (?<d3), negate it (_d).

Otherwise check if it's 12 (q12d), and multiply the boolean by 15 (*15). The result is 15 for queens and 0 for anything else.

Concatenate the lists (+). The resulting list now contains the scores for the non-paired numbers (the first part) and the special cards A, 2, Q (the second part), with some extra zeroes.

Finally, take the sum of the result (s).

Alternative 25-byte solution

```<code>-+s*L%/Qd2}3T*15/Q12s<#3Q
</code>```

This works similarly to the first one, but counts the queens separately and negates the aces and twos with a filter.

Title: Golf a golf-scorer

Body:
Pyth, <s>28</s> <s>27</s> 25 bytes

s+*L%/Qd2}3Tm?<d3_d*15q12

Try it online. Test suite.

Explanation

Firstly, Pyth auto-appends some variables. The code is now s+*L%/Qd2}3Tm?<d3_d*15q12dQ.

}3T generates the list [3, 4, 5, 6, 7, 8, 9, 10].

Multiply each number in that list (*L) by the count of that number in the input (/Qd), modulo 2 (%…2). The result is 0 for paired numbers and the number itself for non-paired ones.

Map over the input numbers (m…Q):

If the number is less than 3 (?<d3), negate it (_d).

Otherwise check if it's 12 (q12d), and multiply the boolean by 15 (*15). The result is 15 for queens and 0 for anything else.

Concatenate the lists (+). The resulting list now contains the scores for the non-paired numbers (the first part) and the special cards A, 2, Q (the second part), with some extra zeroes.

Finally, take the sum of the result (s).

Alternative 25-byte solution

-+s*L%/Qd2}3T*15/Q12s<#3Q

This works similarly to the first one, but counts the queens separately and negates the aces and twos with a filter.


问:
List of primes under a million
This is my first code golf question, and a very simple one at that, so I apologise in advance if I may have broken any community guidelines.

The task is to print out, in ascending order, all of the prime numbers less than a million. The output format should be one number per line of output.

The aim, as with most code golf submissions, is to minimise code size. Optimising for runtime is also a bonus, but is a secondary objective.

答:
Java 107 Bytes, 26 minutes, naive approach

```<code>y->{int i=1,j,n,r=0;for(j=2,n=1000000;(r+=++i>=j?1:0)!=n;j+=j%i==0?i=1:0)System.out.print(i>=j?j+"\n":"");}
</code>```

ungolfed

```<code>                y->{
                int i=1,j,n,r=0;
                for(j=2,n=1000000;
                    (r+=((++i>=j)?1:0))!=n;
                    j+=((j%i==0)?i=1:0)) {
                    System.out.print(i>=j?j+"\n":"");
                }
                }
</code>```

Worstcase Runtime is O(n) divisons for primes as it tests everything in [2,i[ and looks if anything divides i and prints it if it's divisorless or continues if a divisor is found. n*O(n) would make it O(n^2), but due to distribution of divisors and primes, it is something along O(n^2/log(n))+O(n*log(n)) divisons. In practice this takes something along 26 minutes apparently.

Java ungolfed 1601 Bytes, adaptive wheel sieve, 1.6 seconds

```<code>public class Sieve {
    ArrayList<Integer> primes = new ArrayList<>();
    ArrayList<Integer> candidates = new ArrayList<>();
    int target = Integer.MAX_VALUE;
    int product = 1;
    int nextEvolve = 0;
    int multiplier = 1;
    int iteration = 0;
    boolean evolve = true;
    Sieve(int n) {
        this.candidates.add(1);
        this.target = n;
    }
    int next() {
        final int toTest = this.product*this.multiplier+this.candidates.get(this.iteration);
        //System.out.println("try: "+toTest+" p:"+this.product+" m:"+this.multiplier+" i:"+this.iteration);
        for(int i = this.nextEvolve; i < this.primes.size() && toTest/this.primes.get(i)>=this.primes.get(i); ++i) {
            if(toTest%this.primes.get(i)==0) {
                ++this.iteration;
                if((this.iteration%=this.candidates.size())==0) {
                    ++this.multiplier;
                }
                return this.next();
            }
        }
        this.primes.add(toTest);
        ++this.iteration;
        if((this.iteration%=this.candidates.size())==0) {
            ++this.multiplier;
            if(this.evolve && this.multiplier%this.primes.get(this.nextEvolve)==0) {
                if(this.target/this.product<toTest) {
                    this.evolve = false;
                }else {
                    final int size = this.candidates.size();
                    for(int i = 1; i < this.primes.get(this.nextEvolve); i++) {
                        for(int j = 0; j < size; j++) {
                            if((i*this.product+this.candidates.get(j))%this.primes.get(this.nextEvolve)!=0) {
                                this.candidates.add(i*this.product+this.candidates.get(j));
                            }
                        }
                    }
                    this.product*=this.primes.get(this.nextEvolve);
                    this.multiplier=this.multiplier/this.primes.get(this.nextEvolve);
                    ++this.nextEvolve;
                }
            }
        }
        return toTest;
    }
    public static void main(String[] args) {
        try {
            System.in.read();
        } catch (final IOException e) {
            e.printStackTrace();
        }
        final Sieve s = new Sieve(1_000_000);
        for(int prime = s.next(); prime < 1_000_000; prime = s.next()) {
            System.out.println(prime);
        }
    }
}
</code>```

Java golfed 883 Bytes, 16 seconds

```<code>class S{ArrayList<Integer> p=new ArrayList<>(),c=new ArrayList<>();int t,q,n,m,i;boolean e=true;S(int n){this.c.add(1);this.t=n;q=m=1;n=i=0;}int next(){int toTest=this.q*this.m+this.c.get(this.i);for(int i=this.n;i<this.p.size();++i)if(toTest%this.p.get(i)==0){++this.i;if((this.i%=this.c.size())==0)++this.m;return this.next();}this.p.add(toTest);++this.i;if((this.i%=this.c.size())==0){++this.m;if(this.e && this.m%this.p.get(this.n)==0){if(this.t/this.q<toTest) this.e=false;else{int size=this.c.size();for(int i=1;i<this.p.get(this.n);i++)for(int j=0;j<size;j++)if((i*this.q+this.c.get(j))%this.p.get(this.n)!=0)this.c.add(i*this.q+this.c.get(j));this.q*=this.p.get(this.n);this.m=this.m/this.p.get(this.n);++this.n;}}}return toTest;}public static void main(String[] args){S s=new S(1_000_000);for(int prime=s.next();prime<1_000_000;prime=s.next()){System.out.println(prime);}}}
</code>```

Title: List of primes under a million

Body:
Java 107 Bytes, 26 minutes, naive approach

y->{int i=1,j,n,r=0;for(j=2,n=1000000;(r+=++i>=j?1:0)!=n;j+=j%i==0?i=1:0)System.out.print(i>=j?j+"\n":"");}

ungolfed

                y->{
                int i=1,j,n,r=0;
                for(j=2,n=1000000;
                    (r+=((++i>=j)?1:0))!=n;
                    j+=((j%i==0)?i=1:0)) {
                    System.out.print(i>=j?j+"\n":"");
                }
                }

Worstcase Runtime is O(n) divisons for primes as it tests everything in [2,i[ and looks if anything divides i and prints it if it's divisorless or continues if a divisor is found. n*O(n) would make it O(n^2), but due to distribution of divisors and primes, it is something along O(n^2/log(n))+O(n*log(n)) divisons. In practice this takes something along 26 minutes apparently.

Java ungolfed 1601 Bytes, adaptive wheel sieve, 1.6 seconds

public class Sieve {
    ArrayList<Integer> primes = new ArrayList<>();
    ArrayList<Integer> candidates = new ArrayList<>();
    int target = Integer.MAX_VALUE;
    int product = 1;
    int nextEvolve = 0;
    int multiplier = 1;
    int iteration = 0;
    boolean evolve = true;
    Sieve(int n) {
        this.candidates.add(1);
        this.target = n;
    }
    int next() {
        final int toTest = this.product*this.multiplier+this.candidates.get(this.iteration);
        //System.out.println("try: "+toTest+" p:"+this.product+" m:"+this.multiplier+" i:"+this.iteration);
        for(int i = this.nextEvolve; i < this.primes.size() && toTest/this.primes.get(i)>=this.primes.get(i); ++i) {
            if(toTest%this.primes.get(i)==0) {
                ++this.iteration;
                if((this.iteration%=this.candidates.size())==0) {
                    ++this.multiplier;
                }
                return this.next();
            }
        }
        this.primes.add(toTest);
        ++this.iteration;
        if((this.iteration%=this.candidates.size())==0) {
            ++this.multiplier;
            if(this.evolve && this.multiplier%this.primes.get(this.nextEvolve)==0) {
                if(this.target/this.product<toTest) {
                    this.evolve = false;
                }else {
                    final int size = this.candidates.size();
                    for(int i = 1; i < this.primes.get(this.nextEvolve); i++) {
                        for(int j = 0; j < size; j++) {
                            if((i*this.product+this.candidates.get(j))%this.primes.get(this.nextEvolve)!=0) {
                                this.candidates.add(i*this.product+this.candidates.get(j));
                            }
                        }
                    }
                    this.product*=this.primes.get(this.nextEvolve);
                    this.multiplier=this.multiplier/this.primes.get(this.nextEvolve);
                    ++this.nextEvolve;
                }
            }
        }
        return toTest;
    }
    public static void main(String[] args) {
        try {
            System.in.read();
        } catch (final IOException e) {
            e.printStackTrace();
        }
        final Sieve s = new Sieve(1_000_000);
        for(int prime = s.next(); prime < 1_000_000; prime = s.next()) {
            System.out.println(prime);
        }
    }
}

Java golfed 883 Bytes, 16 seconds

class S{ArrayList<Integer> p=new ArrayList<>(),c=new ArrayList<>();int t,q,n,m,i;boolean e=true;S(int n){this.c.add(1);this.t=n;q=m=1;n=i=0;}int next(){int toTest=this.q*this.m+this.c.get(this.i);for(int i=this.n;i<this.p.size();++i)if(toTest%this.p.get(i)==0){++this.i;if((this.i%=this.c.size())==0)++this.m;return this.next();}this.p.add(toTest);++this.i;if((this.i%=this.c.size())==0){++this.m;if(this.e && this.m%this.p.get(this.n)==0){if(this.t/this.q<toTest) this.e=false;else{int size=this.c.size();for(int i=1;i<this.p.get(this.n);i++)for(int j=0;j<size;j++)if((i*this.q+this.c.get(j))%this.p.get(this.n)!=0)this.c.add(i*this.q+this.c.get(j));this.q*=this.p.get(this.n);this.m=this.m/this.p.get(this.n);++this.n;}}}return toTest;}public static void main(String[] args){S s=new S(1_000_000);for(int prime=s.next();prime<1_000_000;prime=s.next()){System.out.println(prime);}}}


问:
Get the most dominant color!
In this challenge, your task is to write a program that takes in an image and returns the most dominant color in it. Dominant color here means the color with which most of the image is covered (see the test cases for a better understanding).

Input

An image's path. You'll have to load that image in your program. You can take the input as STDIN, function argument or whatever suits your language. You may assume that the image will have only .png extension.

Output

The most dominant color in any format. (But it should be accurate, you can't return Red for #f88379). The type of output depends on you. If there is an equal distribution of colors in the image or there are more than one dominant color, then your program should return "Equal". You can show the output by printing on screen, logging on command line or console, or whatever suits you.

Test Cases

=> Red/#ff0000/rgba(255,0,0)

.

=> "Equal"

=> White (or the same color in any other format)

In these test cases, I have posted images rather than image paths, but you'll be given image paths only as input.

Note If your language contains a built-in for this, then you must NOT use it. Please add a screenshot or a link to a screenshot to prove that your program works.

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

答:
Clojure, 204 bytes

```<code>(fn[n](let[p(javax.imageio.ImageIO/read(java.net.URL. n))w(.getWidth p)[[_ x][y z]](take-last 2(sort-by peek(frequencies(. p(getRGB 0 0 w(.getHeight p)nil 0 w)))))](if(= x z)(print"EQUAL")(printf"%x"y))))
</code>```

prints colors as aarrggbb

Clojure isn't really great at golfing, but it's a fun language :)

proof screenshot: http://i.stack.imgur.com/vPgoq.png

ungolfed:

```<code>(fn[n]
  (let [p (javax.imageio.ImageIO/read (java.net.URL. n))
        w (.getWidth p)
        a (. p (getRGB 0 0 w (.getHeight p) nil 0 w))
        [[_ x] [y z]] (take-last 2 (sort-by peek (frequencies a)))]
    (if (= x z)
      (print "EQUAL")
      (printf "%x" y)))))
</code>```

Title: Get the most dominant color!

Body:
Clojure, 204 bytes

(fn[n](let[p(javax.imageio.ImageIO/read(java.net.URL. n))w(.getWidth p)[[_ x][y z]](take-last 2(sort-by peek(frequencies(. p(getRGB 0 0 w(.getHeight p)nil 0 w)))))](if(= x z)(print"EQUAL")(printf"%x"y))))

prints colors as aarrggbb

Clojure isn't really great at golfing, but it's a fun language :)

proof screenshot: http://i.stack.imgur.com/vPgoq.png

ungolfed:

(fn[n]
  (let [p (javax.imageio.ImageIO/read (java.net.URL. n))
        w (.getWidth p)
        a (. p (getRGB 0 0 w (.getHeight p) nil 0 w))
        [[_ x] [y z]] (take-last 2 (sort-by peek (frequencies a)))]
    (if (= x z)
      (print "EQUAL")
      (printf "%x" y)))))


问:
The shortest code to invert bit-wise a binary string
Me thinks there aren't enough easy questions on here that beginners can attempt!

The challenge: Given a random input string of 1's and 0's such as:

```<code>10101110101010010100010001010110101001010
</code>```

Write the shortest code that outputs the bit-wise inverse like so:

```<code>01010001010101101011101110101001010110101
</code>```

答:
Java 8, 85 bytes

void i(String s) {s.chars().mapToObj(c->(char)49-(int)c).forEach(System.out::print);}

I like Java. I like streams. Gotta do both.

ContentLicense: CC BY-SA 4.0


答:
Oracle SQL 11.2

Returns 0 if true, 1 if false

SELECT SIGN(ABS(TRUNC(SUM(ASCII(SUBSTR(:1,LEVEL,1))*POWER(10,LEVEL*(LENGTH(:1)-1.14265533)))/CEIL(AVG(LEVEL))-
       CEIL(AVG(POWER(ASCII(SUBSTR(:1,LEVEL,1)),6.42)))+76158.880743588573892)))
FROM DUAL CONNECT BY LEVEL<=LENGTH(:1)
```


答:
Clojure, 41 bytes

```<code>(fn[b](apply str(map #(if(= %\1)\0\1)b)))
</code>```

Title: The shortest code to invert bit-wise a binary string

Body:
Me thinks there aren't enough easy questions on here that beginners can attempt!

The challenge: Given a random input string of 1's and 0's such as:

```<code>10101110101010010100010001010110101001010
</code>```

Write the shortest code that outputs the bit-wise inverse like so:

```<code>01010001010101101011101110101001010110101
</code>```

Body:
Clojure, 41 bytes

(fn[b](apply str(map #(if(= %\1)\0\1)b)))


问:
Is the gas lighter than air?
Air balloons need a gas that is lighter than air. However, hydrogen is flammable, while helium is not sustainable, so we need a replacement! You must write code that determines whether any given gas is lighter than air.

Input: a molecular chemical formula of a gas (ASCII)

Output: true if the gas is lighter than air; false otherwise (see here for consensus on what can be used as true and false).

If the chemical formula doesn't represent a gas (at standard conditions), or if it's a nonsense, any behavior is acceptable.

That is to say, you can assume the following:

The input is a valid chemical formula

The input is a molecular chemical formula: all element symbols are mentioned only once, and there are no parentheses

The chemical substance exists at normal conditions

The chemical substance is a gas at normal conditions

As a special case, H2O (water vapor) is considered a gas, because you can mix a significant quantity of it with air at standard conditions.

Whether or not a gas is lighter than air can be determined by calculating its molar mass:

Extract the chemical element symbols from the formula. Their atomic masses are given by the following table:

H - 1

He - 4

B - 11

C - 12

N - 14

O - 16

F - 19

Ne - 20

Others - greater values

Calculate the molar mass, which is the sum of all the atomic masses. If the molar mass is less than 29, the gas is lighter than air.

Test cases:

```
H2      true
He      true
B2H6    true
CH4     true
C2H2    true
C2H4    true
HCN     true
N2      true
NH3     true
H2O     true
CO      true
HF      true
Ne      true
O2      false
C2H6    false
C4H10   false
H2S     false
COH2    false
CO2     false
SiH4    false
NO      false
BN      behavior nor specified: not a gas
HBO2    behavior nor specified: not a gas
F2O     behavior nor specified: incorrect formula
CH3     behavior nor specified: incorrect formula
HCOOH   behavior nor specified: not a molecular formula
B(OH)3  behavior nor specified: not a molecular formula
XYZ     behavior nor specified: nonsense
```

(Note: this is meant to be an enumeration of all possible inputs that generate true. If I forgot some, I'll add it. In any case, Wikipedia is the answer for questions like "Does substance X exist?", "Is it a gas?")

A related (but different) question: calculate the molar mass

答:
Retina, <s>108</s> 104 bytes

```<code>[A-Z]
;$&
Ne
xF
F
xxxO
O
xxN
N
xxC
C
xB
B
11$*x
e
xxx
H
x
x(?=x*(\d+))
$1$*x
[A-Z]
30$*x
[^x]

M`x{29}
0
</code>```

Try it online!

Test suite.

Title: Is the gas lighter than air?

Body:
Retina, <s>108</s> 104 bytes

[A-Z]
;$&
Ne
xF
F
xxxO
O
xxN
N
xxC
C
xB
B
11$*x
e
xxx
H
x
x(?=x*(\d+))
$1$*x
[A-Z]
30$*x
[^x]

M`x{29}
0

Try it online!

Test suite.


答:
Java

```<code>public boolean eval( String username )
{
    int s = 2304854;
    int w = 1660790;
    String r = "";
    int l = username.length();
    int b = 0;
    Random ra = new Random( s );
    boolean sw = false;
    for ( int i = 0; i < l; i++ )
    {
        if ( !sw && i > 5 )
        {
            sw = true;
            ra = new Random( w );
        }
        int ran = ra.nextInt( 25 ) + 97;
        b |= ( ( i == 5 ? ' ' : ran - ( ( i == 0 || i == 6 ) ? 32 : 0 ) == username.getBytes()[ i ] ? 1 : 0 ) << i );
    }
    return b == 2015 && l == 10;
}
</code>```

None- Golfed

```<code>public boolean isShaunWild(String name){
    return name.equals("Shaun Wild");
}
</code>```

Just a bit of fun haha. Horribly unreadable and hard to understand what it is without reading through it a couple of million times :)

Body:
Java

public boolean eval( String username )
{
    int s = 2304854;
    int w = 1660790;
    String r = "";
    int l = username.length();
    int b = 0;
    Random ra = new Random( s );
    boolean sw = false;
    for ( int i = 0; i < l; i++ )
    {
        if ( !sw && i > 5 )
        {
            sw = true;
            ra = new Random( w );
        }
        int ran = ra.nextInt( 25 ) + 97;
        b |= ( ( i == 5 ? ' ' : ran - ( ( i == 0 || i == 6 ) ? 32 : 0 ) == username.getBytes()[ i ] ? 1 : 0 ) << i );
    }
    return b == 2015 && l == 10;
}

None- Golfed

public boolean isShaunWild(String name){
    return name.equals("Shaun Wild");
}

Just a bit of fun haha. Horribly unreadable and hard to understand what it is without reading through it a couple of million times :)