问:
Generate Lucky Numbers
Story:

Lucy asked George what his Lucky Number was. After some contemplation, George replied that he had several Lucky Numbers. After some brief confusion, Lucy asked George what his first n Lucky Numbers are. George then asked you, his buddy, to write him a program to do the work for him.

The Challenge:

You will write a program/function that will receive from standard input/function argument a string or integer n. The program/function will then return/output the first n Lucky Numbers. Lucky numbers are defined via a sieve as follows.

Start with the positive integers:

```<code>1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, ...
</code>```

Now remove every second number:

```<code>1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, ...
</code>```

The second remaining number is 3, so remove every third number:

```<code>1, 3, 7, 9, 13, 15, 19, 21, 25, ...
</code>```

Now the next remaining number is 7, so remove every seventh number:

```<code>1, 3, 7, 9, 13, 15, 21, 25, ...
</code>```

Next, remove every ninth number and so on. The resulting sequence are the lucky numbers.

Winning:

As usual for codegolf, fewest bytes wins.

As usual, submissions using standard loopholes are disqualified.

答:
Racket 196 bytes

Produces lucky numbers upto n:

```<code>(λ(n)(let loop((l(filter odd?(range 1 n)))(i 1))(define x(list-ref l i))(set! l(for/list((j(length l))
#:unless(= 0(modulo(add1 j)x)))(list-ref l j)))(if(>= i(sub1(length l)))l(loop l(add1 i)))))
</code>```

Ungolfed version:

```<code>(define f
 (λ(n)
    (let loop ((l (filter odd? (range 1 n))) (i 1))
      (define x (list-ref l i))
      (set! l (for/list ((j (length l)) #:unless (= 0 (modulo (add1 j) x)))
                (list-ref l j)))
      (if (>= i (sub1 (length l)))
          l
          (loop l (add1 i)))))
  )
</code>```

Testing:

```<code>(f 100)
</code>```

Output:

```<code>'(1 3 7 9 13 15 21 25 31 33 37 43 49 51 63 67 69 73 75 79 87 93 99)
</code>```

Title: Generate Lucky Numbers

Body:
Racket 196 bytes

Produces lucky numbers upto n:

(λ(n)(let loop((l(filter odd?(range 1 n)))(i 1))(define x(list-ref l i))(set! l(for/list((j(length l))
#:unless(= 0(modulo(add1 j)x)))(list-ref l j)))(if(>= i(sub1(length l)))l(loop l(add1 i)))))

Ungolfed version:

(define f
 (λ(n)
    (let loop ((l (filter odd? (range 1 n))) (i 1))
      (define x (list-ref l i))
      (set! l (for/list ((j (length l)) #:unless (= 0 (modulo (add1 j) x)))
                (list-ref l j)))
      (if (>= i (sub1 (length l)))
          l
          (loop l (add1 i)))))
  )

Testing:

(f 100)

Output:

'(1 3 7 9 13 15 21 25 31 33 37 43 49 51 63 67 69 73 75 79 87 93 99)


问:
Iterated Dice Rolling
Given an input n where 3 <= n <= 25, perform the following steps, starting with a single n-sided die (faces in the range [1, n], inclusive):

Print the result of rolling the current n-sided dice in play, in the form kdn: X (where X is the result and k is the number of dice in play).

If X is greater than or equal to n/2 times the number of dice in play, add a die. Else, remove a die.

If the number of dice in play is equal to 0 or n, stop. Else, go to step 1.

Example runs (note that the output in parentheses is for explanation and is not required):

6-sided:

```<code>1d6: 4 (avg: 3.0, add)
2d6: 6 (avg: 6.0, add)
3d6: 9 (avg: 9.0, add)
4d6: 16 (avg: 12.0, add)
5d6: 13 (avg: 15.0, remove)
4d6: 9 (avg: 12.0, remove)
3d6: 5 (avg: 9.0, remove)
2d6: 7 (avg: 6.0, add)
3d6: 11 (avg: 9.0, add)
4d6: 14 (avg: 12.0, add)
5d6: 17 (avg: 15.0, add)
</code>```

9-sided:

```<code>1d9: 7 (avg: 4.5, add)
2d9: 14 (avg: 9.0, add)
3d9: 18 (avg: 13.5, add)
4d9: 18 (avg: 18.0, add)
5d9: 28 (avg: 22.5, add)
6d9: 26 (avg: 27.0, remove)
5d9: 28 (avg: 22.5, add)
6d9: 34 (avg: 27.0, add)
7d9: 33 (avg: 31.5, add)
8d9: 30 (avg: 36.0, remove)
7d9: 29 (avg: 31.5, remove)
6d9: 35 (avg: 27.0, add)
7d9: 32 (avg: 31.5, add)
8d9: 42 (avg: 36.0, add)
</code>```

Rules

Outputs must be exactly in the format kdn: X, with newlines separating each roll

You must actually simulate rolling multiple dice; simply returning a random integer in the range [1, n] (inclusive) multiplied by the number of dice currently in play is not allowed, as that does not accurately simulate rolling multiple dice.

Standard loopholes are forbidden

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

Leaderboard

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

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

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

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

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

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

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

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

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
PHP, 104 bytes

```<code>for($n=$argv[$k=1];$k&&$k<$n;print$k."d$n: $x\n",$k-=$x<$n*$k/2?:-1)for($x=$i=0;$i++<$k;)$x+=rand(1,$n);
</code>```

Run with php -r '' <N>

breakdown

```<code>for($n=$argv[$k=1];     // import input, init number of dice
    $k&&$k<$n;          // while 0<$k<$n
    print$k."d$n: $x\n",    // 2. print results
    $k-=$x<$n*$k/2?:-1      // 3. remove or add a die
)
    for($x=$i=0;$i++<$k;)   // 1. roll dice separately
        $x+=rand(1,$n);         // sum up results
</code>```

ContentLicense: CC BY-SA 3.0

Title: Iterated Dice Rolling

Body:
PHP, 104 bytes

for($n=$argv[$k=1];$k&&$k<$n;print$k."d$n: $x\n",$k-=$x<$n*$k/2?:-1)for($x=$i=0;$i++<$k;)$x+=rand(1,$n);

Run with php -r '<code>' <N>

breakdown

for($n=$argv[$k=1];     // import input, init number of dice
    $k&&$k<$n;          // while 0<$k<$n
    print$k."d$n: $x\n",    // 2. print results
    $k-=$x<$n*$k/2?:-1      // 3. remove or add a die
)
    for($x=$i=0;$i++<$k;)   // 1. roll dice separately
        $x+=rand(1,$n);         // sum up results


问:
Unlucky Numbers!

Things to know:

First, lucky numbers.

Lucky numbers are generated like so:

Take all the natural numbers:

```<code>1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20...
</code>```

Then, remove each second number.

```<code>1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39...
</code>```

Now, 3 is safe.

Remove every 3rd number:

```<code>1, 3, 7, 9, 13, 15, 19, 21, 25, 27, 31, 33, 37, 39, 43, 45, 49, 51, 55, 59...
</code>```

Now, 7 is safe.

Remove every 7th number.

Continue, and remove every nth number, where n is the first safe number after an elimination.

The final list of safe numbers is the lucky numbers.

The unlucky numbers is composed of separate lists of numbers, which are [U1, U2, U3... Un].

U1 is the first set of numbers removed from the lucky "candidates", so they are:

```<code>2, 4, 6, 8, 10, 12, 14, 16, 18, 20...
</code>```

U2 is the second set of numbers removed:

```<code>5, 11, 17, 23, 29, 35, 41, 47, 53, 59...
</code>```

And so on and so forth (U3 is the third list, U4 is the fourth, etc.)

Challenge:

Your task is, when given two inputs m and n, generate the mth number in the list Un.

Example inputs and outputs:

```<code>(5, 2) -> 29
(10, 1) -> 20
</code>```

Specs:

Your program must work for m up to 1e6, and n up to 100.

You are guaranteed that both m and n are positive integers.

If you're curious, U(1e6, 100) = 5,333,213,163. (Thank you @pacholik!)

Your program must compute that within 1 day on a reasonable modern computer.

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

PS: It would be nice if someone came up with a general formula for generating these. If you do have a formula, please put it in your answer!

答:
Racket 332 bytes

```<code>(λ(N m n)(let loop((l(filter odd?(range 1 N)))(i 1))(define x (list-ref l i))(if(= i (sub1 n))
(begin(set! l(for/list((j(length l))#:when(= 0(modulo(add1 j)x)))(list-ref l j)))(list-ref l(sub1 m)))
(begin(set! l(for/list((j(length l))#:unless(= 0(modulo(add1 j) x)))(list-ref l j)))(if(>= i(sub1 (length l)))l
(loop l(add1 i)))))))
</code>```

Ungolfed version:

```<code>(define f
  (λ(N m n)
    (let loop ((l (filter odd? (range 1 N))) (i 1))
      (define x (list-ref l i))
      (if (= i (sub1 n))
          (begin (set! l (for/list ((j (length l))
                                   #:when (= 0 (modulo (add1 j) x)))
                           (list-ref l j)))
                 (list-ref l (sub1 m)))
          (begin (set! l (for/list ((j (length l))
                                   #:unless (= 0 (modulo (add1 j) x)))
                           (list-ref l j)))
                 (if (>= i (sub1 (length l)))
                     l
                     (loop l (add1 i))))))))
</code>```

Testing:

```<code>(f 100 5 2)
</code>```

Output:

```<code>29
</code>```

Title: Unlucky Numbers!

Body:
Racket 332 bytes

(λ(N m n)(let loop((l(filter odd?(range 1 N)))(i 1))(define x (list-ref l i))(if(= i (sub1 n))
(begin(set! l(for/list((j(length l))#:when(= 0(modulo(add1 j)x)))(list-ref l j)))(list-ref l(sub1 m)))
(begin(set! l(for/list((j(length l))#:unless(= 0(modulo(add1 j) x)))(list-ref l j)))(if(>= i(sub1 (length l)))l
(loop l(add1 i)))))))

Ungolfed version:

(define f
  (λ(N m n)
    (let loop ((l (filter odd? (range 1 N))) (i 1))
      (define x (list-ref l i))
      (if (= i (sub1 n))
          (begin (set! l (for/list ((j (length l))
                                   #:when (= 0 (modulo (add1 j) x)))
                           (list-ref l j)))
                 (list-ref l (sub1 m)))
          (begin (set! l (for/list ((j (length l))
                                   #:unless (= 0 (modulo (add1 j) x)))
                           (list-ref l j)))
                 (if (>= i (sub1 (length l)))
                     l
                     (loop l (add1 i))))))))

Testing:

(f 100 5 2)

Output:

29


问:
Output the alphabet, the ALPHABET, or just a character
The challenge is simple:

Write a function or program that takes an input x, and outputs the lower case alphabet if x is part of the lower case alphabet, outputs the upper case alphabet if x is part of the upper case alphabet and outputs just x if it's not part of either.

Rules:

The input can be function argument or from STDIN

The input will be any of the printable ASCII characters from 32 to 126 (space to tilde).

The input may be inside quotation marks,'x' or "x", but remember that ' and " are valid input and should be supported.

The input can be any of the letters in the alphabet, i.e. you can't assume it will be a or A.

The output should be only one of the alphabets or the single symbol, but trailing newlines are OK.

The letters in the alphabet should not be separated by spaces, commas or anything else.

Some examples:

```<code>F
ABCDEFGHIJKLMNOPQRSTUVWXYZ

z
abcdefghijklmnopqrstuvwxyz

"
"

    <- Input:  Space
    <- Output: Space
</code>```

Shortest code in bytes win.

Optional but appreciated: If your language has an online interpreter, please also post a link so that it can be easily tested by others.

Leaderboard

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

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

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

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

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

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

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

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

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

var QUESTION_ID=67357,OVERRIDE_USER=44713;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

```

答:
Java 7, 99 bytes

```<code>void f(char c){for(int a=c|32,i=97;i<123;i++)System.out.print(a<123&a>96?(char)(i-a+c):i<98?c:"");}
</code>```

Slightly more readable, with no scrollbars:

```<code>void f(char c){
    for(int a=c|32,i=97;i<123;i++)  // a is lowercased input, i loops alphabet
        System.out.print(
            a<123&a>96?             // if a is a letter
                (char)(i-a+c):      //   subtract diff between lower and input
                    i<98?c:"");     // else print input if first iteration
}
</code>```

The logic here is pretty straightforward, but a different method than the other Java answer.

Body:
Java 7, 99 bytes

void f(char c){for(int a=c|32,i=97;i<123;i++)System.out.print(a<123&a>96?(char)(i-a+c):i<98?c:"");}

Slightly more readable, with no scrollbars:

void f(char c){
    for(int a=c|32,i=97;i<123;i++)  // a is lowercased input, i loops alphabet
        System.out.print(
            a<123&a>96?             // if a is a letter
                (char)(i-a+c):      //   subtract diff between lower and input
                    i<98?c:"");     // else print input if first iteration
}

The logic here is pretty straightforward, but a different method than the other Java answer.


问:
Alphabet Spiral
You are to write a program or function that outputs this exact text:

```<code>OPQRSTU
NQPONMV
MREDCLW
LSFABKX
KTGHIJY
JUVWXYZA
IHGFEDCB
</code>```

May also be lowercase and trailing spaces and newlines are allowed.

Standard loopholes are disallowed

This is code-golf, so smallest byte count wins.

答:
PHP, 130 bytes

```<code>for($p=30,$s=1,$r=_;$i<51;$r[$p]=chr(90-abs(25-$i++)),$p+=$s*(9-$d))if(!$n||!$c=++$c%$n)($d=8-$d)?$n++:$s=-$s;echo wordwrap($r,8);
</code>```

literally draws the spiral. Run with -r

breakdown

```<code>for($p=30,$s=1,$r=_;    // initialize position to 3*9+3, $s(ign) to +1, $r(esult) to string
                        // implicit $c(ount)=$d(irection)=$i(ndex)=le($n)gth=0
    $i<51;              // loop $i from 0 to 50
    $r[$p]=chr(90-abs(25-$i++)),// 2. set current position in string to correct character
    $p+=$s*(9-$d))              // 3. move cursor
    if(!$n||!$c=++$c%$n)        // 1. if 1st iteration ($n==0) or ++$c has rotated around $n
        ($d=8-$d)                   // negate $direction (0=horizontal, 8=vertical)
            ?$n++                   // if vertical: increase length
            :$s=-$s                 // else invert sign
        ;
                        // output: wrap to lines of 8 characters
echo wordwrap($r,8);    // having left spaces avoids need to provide 3rd and 4th parameter
</code>```

Easy to extend: For more alphabet,
append %50 after $i++,
replace 51 with the wanted number,
modify 8-$d, 9-$d, $p=30 and the wordwrap width to the new dimensions.

Title: Alphabet Spiral

Body:
PHP, 130 bytes

for($p=30,$s=1,$r=_;$i<51;$r[$p]=chr(90-abs(25-$i++)),$p+=$s*(9-$d))if(!$n||!$c=++$c%$n)($d=8-$d)?$n++:$s=-$s;echo wordwrap($r,8);

literally draws the spiral. Run with -r

breakdown

for($p=30,$s=1,$r=_;    // initialize position to 3*9+3, $s(ign) to +1, $r(esult) to string
                        // implicit $c(ount)=$d(irection)=$i(ndex)=le($n)gth=0
    $i<51;              // loop $i from 0 to 50
    $r[$p]=chr(90-abs(25-$i++)),// 2. set current position in string to correct character
    $p+=$s*(9-$d))              // 3. move cursor
    if(!$n||!$c=++$c%$n)        // 1. if 1st iteration ($n==0) or ++$c has rotated around $n
        ($d=8-$d)                   // negate $direction (0=horizontal, 8=vertical)
            ?$n++                   // if vertical: increase length
            :$s=-$s                 // else invert sign
        ;
                        // output: wrap to lines of 8 characters
echo wordwrap($r,8);    // having left spaces avoids need to provide 3rd and 4th parameter

Easy to extend: For more alphabet,
append %50 after $i++,
replace 51 with the wanted number,
modify 8-$d, 9-$d, $p=30 and the wordwrap width to the new dimensions.


问:
Draw an ASCII Rectangle
Given two integers as input in an array, draw a rectangle, using the first integer as width and second as height.

Or, if your language supports it, the two integers can be given as separate inputs.

Assume the width and height will never be less than 3, and they will always be given.

Example Outputs:

[3, 3]

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

[5, 8]

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

[10, 3]

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

This is code-golf, so the answer with the lowest amount of bytes wins.

Title: Draw an ASCII Rectangle

Body:
Python 3, 68 bytes

def f(a,b):
 c='|'+'-'*(a-2)+'|\n';print(c+c.replace(*'- ')*(b-2)+c)


问:
Can you outgolf me? (Cops section)

Cops section

The robbers section can be found here.

Thanks to FryAmTheEggman, Peter Taylor, Nathan Merrill, xnor, Dennis, Laikoni and Mego for their contributions.

Challenge

Your task is to write 2 different programs (full programs/functions/etc.) in the same language and the same version (e.g. Python 3.5 ≠ Python 3.4, so that is not allowed), and when given n (using STDIN/function arguments/etc.), compute a(n) where a is an OEIS sequence of your choice. One of those programs is shorter than the other. You only need to submit the longer program of the two. The other one needs to be saved in case of not being cracked after 7 days. Your submission is cracked when your program has been outgolfed (whether it is by 1 byte or more).

For example, if the task you chose was to perform 2 × n, this could be a valid submission (in Python 2):

Python 2, 16 bytes, score = 15 / 16 = 0.9375

```<code>print(2*input())
</code>```

Computes A005843, (offset = 0).

If your submission has been cracked, then you need to state that in your header like so:

Python 2, 16 bytes, score = 15 / 16 = 0.9375, [cracked] + link

```<code>print(2*input())
</code>```

Computes A005843, (offset = 0).

Offset

This can be found on every OEIS page. For example, for A005843, the offset is 0,2. We only need to use the first one, which is 0. This means that the function is defined for all numbers ≥ 0.

In other words, the function OEIS(n) starts with n = 0. Your program needs to work for all cases given by OEIS.

More information can be found here.

Scoring

The score you get for your submission is equal to the following formula:

Score = Length (in bytes) of secret code ÷ Length (in bytes) of public code

The example above has the score 15 ÷ 16 = 0.9375.

The submission with the lowest score wins. Only submissions that have posted their solution will be eligible for winning.

Rules

The task you need to do is an OEIS sequence of your choice.

Given n, output OEIS(n). Deviation is not allowed, so you need to produce the exact same sequence (when given n, you need to output OEIS(n)).

Submissions that are not cracked within a period of 7 days are considered safe after the solution has been posted (submissions older than 7 days that do not have their solution posted are still vulnerable in being cracked).

In your submission, you need to post the following things: language name, byte count, full code, so no pastebin links etc. (to prevent answers like Unary), OEIS sequence, score with lengths of both programs and additionally, the encoding that is used.

Note: the same sequence cannot be posted twice in the same language. (For example, if the sequence A005843 has been done in Pyth, you cannot use Pyth again for that same sequence.)

Input and output are both in decimal (base 10)

Leaderboard

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

Uncracked submissions

 Language	 Score	 User

Sort by: score creation

Safe submissions

 Language	 Score	 User

```

Note

This challenge is finished. The final winner is feersum with his Seed answer. Congratulations! :).

You can still submit new cops, but be aware that they are no longer competing.

Title: Can you outgolf me? (Cops section)

Body:
J, 18 bytes, score = 0.7222 (13/18) (cracked)

0{]1&(}.],+/)2 1"_

Computes the Lucas numbers, A000032.


问:
Is it a balanced number?
A number is balanced if the sum of the digits on each half of the number is equal, so: 1423 is balanced because 1+4 = 2+3, so is: 42615 because 4+2=1+5. Note that the middle digit is not included on either side (or it's included on both sides) if there's an odd number of digits.

Challenge:

Take a positive integer as input, and output a truthy value if it's balanced and a falsy value if it's unbalanced.

Test cases (true)

```<code>1
6
11
141
1221
23281453796004414
523428121656666655655556655656502809745249552466339089702361716477983610754966885128041975406005088
</code>```

Test cases (false)

```<code>10
12
110
15421
5234095123508321
6240911314399072459493765661191058613491863144152352262897351988250431140546660035648795316740212454
</code>```

There will not be numbers starting with zero, for instance 00032 instead of 32. You must support numbers up to at least 100 digits (so larger than 2^64-1). As always, optional input format, so you may surround the number with apostrophes if desired.

ContentLicense: CC BY-SA 4.0

Title: Is it a balanced number?

Body:
JavaScript (ES5), <s>70</s> 66 bytes

function g(n){for(a=b=0;(l=n.length)>b*2;)a+=n[b]-n[l-++b];return!a}

// tests:
var falses = ['10', '12', '110', '15421', '5234095123508321', '6240911314399072459493765661191058613491863144152352262897351988250431140546660035648795316740212454']
var i=falses.length;
while(i--) console.info(!g(falses[i]) ? 'ok' : 'not false: ' + falses[i])

var trues = ['1', '6', '11', '141', '1221', '23281453796004414', '523428121656666655655556655656502809745249552466339089702361716477983610754966885128041975406005088'];
i = trues.length;
while(i--) console.info(g(trues[i]) ? 'ok' : 'not true: ' + trues[i])


问:
Enlarge ASCII art
In this challenge, you must take multiline ASCII art as input, such as:

```<code> OOOOOO  OOOOOO  OOOOOO  OOOOOOO      OOOOOO   OOOOOO  OO      OOOOOOO
OO      OO    OO OO   OO OO          OO       OO    OO OO      OO
OO      OO    OO OO   OO OOOOO       OO   OOO OO    OO OO      OOOOO
OO      OO    OO OO   OO OO          OO    OO OO    OO OO      OO
 OOOOOO  OOOOOO  OOOOOO  OOOOOOO      OOOOOO   OOOOOO  OOOOOOO OO
</code>```

And you will also take an integer as input. You must output the ASCII art enlarged by the amount specified with the integer. For example, if you used a second argument of 3, the output would be

```<code>   OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOOOOO                  OOOOOOOOOOOOOOOOOO         OOOOOOOOOOOOOOOOOO      OOOOOO                  OOOOOOOOOOOOOOOOOOOOO
   OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOOOOO                  OOOOOOOOOOOOOOOOOO         OOOOOOOOOOOOOOOOOO      OOOOOO                  OOOOOOOOOOOOOOOOOOOOO
   OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOOOOO                  OOOOOOOOOOOOOOOOOO         OOOOOOOOOOOOOOOOOO      OOOOOO                  OOOOOOOOOOOOOOOOOOOOO
OOOOOO                  OOOOOO            OOOOOO   OOOOOO         OOOOOO   OOOOOO                              OOOOOO                     OOOOOO            OOOOOO   OOOOOO                  OOOOOO
OOOOOO                  OOOOOO            OOOOOO   OOOOOO         OOOOOO   OOOOOO                              OOOOOO                     OOOOOO            OOOOOO   OOOOOO                  OOOOOO
OOOOOO                  OOOOOO            OOOOOO   OOOOOO         OOOOOO   OOOOOO                              OOOOOO                     OOOOOO            OOOOOO   OOOOOO                  OOOOOO
OOOOOO                  OOOOOO            OOOOOO   OOOOOO         OOOOOO   OOOOOOOOOOOOOOO                     OOOOOO         OOOOOOOOO   OOOOOO            OOOOOO   OOOOOO                  OOOOOOOOOOOOOOO
OOOOOO                  OOOOOO            OOOOOO   OOOOOO         OOOOOO   OOOOOOOOOOOOOOO                     OOOOOO         OOOOOOOOO   OOOOOO            OOOOOO   OOOOOO                  OOOOOOOOOOOOOOO
OOOOOO                  OOOOOO            OOOOOO   OOOOOO         OOOOOO   OOOOOOOOOOOOOOO                     OOOOOO         OOOOOOOOO   OOOOOO            OOOOOO   OOOOOO                  OOOOOOOOOOOOOOO
OOOOOO                  OOOOOO            OOOOOO   OOOOOO         OOOOOO   OOOOOO                              OOOOOO            OOOOOO   OOOOOO            OOOOOO   OOOOOO                  OOOOOO
OOOOOO                  OOOOOO            OOOOOO   OOOOOO         OOOOOO   OOOOOO                              OOOOOO            OOOOOO   OOOOOO            OOOOOO   OOOOOO                  OOOOOO
OOOOOO                  OOOOOO            OOOOOO   OOOOOO         OOOOOO   OOOOOO                              OOOOOO            OOOOOO   OOOOOO            OOOOOO   OOOOOO                  OOOOOO
   OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOOOOO                  OOOOOOOOOOOOOOOOOO         OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOOOOO   OOOOOO
   OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOOOOO                  OOOOOOOOOOOOOOOOOO         OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOOOOO   OOOOOO
   OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOOOOO                  OOOOOOOOOOOOOOOOOO         OOOOOOOOOOOOOOOOOO      OOOOOOOOOOOOOOOOOOOOO   OOOOOO
</code>```

Specifically, each character must turn into an n by n box of that character, where n is the integer argument. For example, an input of

```<code>ab
cd
</code>```

and 3 will result in

```<code>aaabbb
aaabbb
aaabbb
cccddd
cccddd
cccddd
</code>```

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

答:
Vim, 39 keystrokes (excluding input, not competing)

the gotcha and the reason this is not competing is because the input has to be entered twice. Replace both 2 with your own input.

```<code>qayl2phxl@aquu:%norm @a<cr>gg0qbyy2P2jkddj@bq@b
</code>```

Explanation

qayl2phxl@aquu records a macro that yanks a character, paste it and move to the next one, then replays itself. Then it undoes the changes. Because we want the loop not to be infinite, we don't delete the character, which means we have to delete the extraneous one but still finish with a movement that fails on the last char.

:%norm @a<cr> runs the macro on every line

gg0 returns to the very beginning

qbyy2P2jkddj@bq@b uses the same technique as @a to copy every line, but with a recursive macro.

I know this can be golfed more, e.g. by traversing backwards for line duplication but because of the multiple input entry requirement, I will stop there and mark this answer as non competing.

Previous answer (32 keystrokes,  only doubles)

```<code>qaylpl@aqu:%norm @a<cr>:%s/.*/&\r&<cr>
</code>```

Explanation

qaylpl@aqu records a macro that yanks a character, paste it and move to the next one, then replays itself. Undo the change.

:%norm @a<cr> runs the macro on every line

:%s/.*/&\r&<cr> doubles every line

I wanted to do a nested macro, but the inner one (characters) stops the outer one (lines)... So I have to run two commands, adding quite a few keystrokes to an otherwise simple solution.

Title: Enlarge ASCII art

Body:
Vim, 39 keystrokes (excluding input, not competing)

the gotcha and the reason this is not competing is because the input has to be entered twice. Replace both 2 with your own input.

qayl2phxl@aquu:%norm @a<cr>gg0qbyy2P2jkddj@bq@b

Explanation

qayl2phxl@aquu records a macro that yanks a character, paste it and move to the next one, then replays itself. Then it undoes the changes. Because we want the loop not to be infinite, we don't delete the character, which means we have to delete the extraneous one but still finish with a movement that fails on the last char.

:%norm @a<cr> runs the macro on every line

gg0 returns to the very beginning

qbyy2P2jkddj@bq@b uses the same technique as @a to copy every line, but with a recursive macro.

I know this can be golfed more, e.g. by traversing backwards for line duplication but because of the multiple input entry requirement, I will stop there and mark this answer as non competing.

Previous answer (32 keystrokes,  only doubles)

qaylpl@aqu:%norm @a<cr>:%s/.*/&\r&<cr>

Explanation

qaylpl@aqu records a macro that yanks a character, paste it and move to the next one, then replays itself. Undo the change.

:%norm @a<cr> runs the macro on every line

:%s/.*/&\r&<cr> doubles every line

I wanted to do a nested macro, but the inner one (characters) stops the outer one (lines)... So I have to run two commands, adding quite a few keystrokes to an otherwise simple solution.


问:
DISARM THE B.O.M.B.!
You have been hired for your tech knowledge as a Secret Agent's sidekick to ensure that the good guy can get his job done and the world can be saved.

This is your last mission before retiring with a high paycheck and the gratitude of the whole world. But before you have to disarm the Evil Genius' Big Overly Massive BOMB (seems that the evil genius is a smart ass who likes recursive acronyms). Anyways you and your buddy are in the very core of the Evil Genius secret base, ready to disarm the BOMB that could wipe the continent out. In your previous mission you managed to get the disarm code that to your astonishment is just "PASSWORD_01". You connect your keyboard to the BOMB but when you are ready to go, the Evil Genius' henchmen enter in with a barrage of bullets. Unfortunately one of these bullets impacts on your keyboard. "Finish the job while I distract those d*ckheads!" says your buddy and then begins to fire his gun. But how could you finish the job with only half a keyboard?

SPECS

Write a program that outputs in any way you want the string PASSWORD_01 (uppercase).

Since your keyboard has been hit by a bullet, you can only use these keys:

1 2 3 4 5

Q W E R T

A S D F G

< > Z X C

Ctrl Shift Tab Space

Using the Shift key, your keyboard allows you to use these characters:

! " · $ %

You don't have any other hardware than the keyboard and the screen (a mouse for example), nor a file with the password written in your computer.

You don't have an Internet connection.

You can assume you have the interpreter shell / source editor opened before the bullets came in. Sadly you have not written anything in it before the keyboard was hit.

You don't have a virtual keyboard. In fact the BOMB has a TOO_FUNNY detector that will make it explode if you try to use the Standard loopholes.

Since your buddy is waiting for you to finish soon to escape off the Secret Base, you will have to write the smallest code possible (so it's restricted-source and code-golf!).

Good luck because the count down has begun!

HELP MODE: Also a KEY (only one Key you want from the keyboard, but not the Shift + Key or any other combination) has miraculously survived too. E.g.: You can use =, or 0 or /… This extra key cannot be any of the letters in PASSWORD_01 (so you cannot add P or O). Name that key in your answer. You have a penalization of 10 characters for use of this key regardless of how many times you use the key.

答:
JS-Forth, 103 bytes

The string will be returned on the stack as an array of characters.

```<code>12544 1 3 << >> 24 1 << 1521 4 >> 34 1 << 41 1 << 2531 5 >> 351 2 >> 332 2 >> 32 2 >> 131 1 >> 321 2 >>
</code>```

Try it online - Commented version

Explanation:

I first found the list of allowed words. Essentially, the only things I could use that would be useful are:

12345 Numeric constants

<< Shift left

>> Shift right

s>f Push single to float stack

f>d Pop double from float stack

fsqrt Square root on float stack

So I could use numeric constants, bit-shift, and compute a square root using the following (>> replaces drop, shifting by 0 to remove the 0):

```<code>s>f fsqrt f>d >>
</code>```

Fortunately, I found possible bit-shifts for every constant I needed to create that were shorter than using square roots. For the most part, I searched by simply printing each number squared, or a larger power of two if any of them contained a digit 6-0. Then, I realized I could use loss of precision from f>d to find more possibilities. (I could add to the number, but still get the same integer square root.) A bit later, I started using bit-shifting to find some, and then all, of the constants. The greater the >> bit-shift, the more I could add to the "magic number" and still get the same result. So I found the smallest bit-shifts I could use to get the necessary results. Even numbers could sometimes use <<, odds had to use >>.

Commented code (\ starts a comment):

```<code>\ 49
12544 1 3 << >>

\ 48
24 1 <<

\ 95
1521 4 >>

\ 68
34 1 <<

\ 82
41 1 <<

\ 79
2531 5 >>

\ 87
351 2 >>

\ 83 (x2)
332 2 >> 332 2 >>

\ 65
131 1 >>

\ 80
321 2 >>
</code>```

gForth does not have the words << or >>. Instead it has lshift and rshift, which I could not use.

Title: DISARM THE B.O.M.B.!

Body:
JS-Forth, 103 bytes

The string will be returned on the stack as an array of characters.

12544 1 3 << >> 24 1 << 1521 4 >> 34 1 << 41 1 << 2531 5 >> 351 2 >> 332 2 >> 32 2 >> 131 1 >> 321 2 >>

Try it online - Commented version

Explanation:

I first found the list of allowed words. Essentially, the only things I could use that would be useful are:

12345 Numeric constants

<< Shift left

>> Shift right

s>f Push single to float stack

f>d Pop double from float stack

fsqrt Square root on float stack

So I could use numeric constants, bit-shift, and compute a square root using the following (>> replaces drop, shifting by 0 to remove the 0):

s>f fsqrt f>d >>

Fortunately, I found possible bit-shifts for every constant I needed to create that were shorter than using square roots. For the most part, I searched by simply printing each number squared, or a larger power of two if any of them contained a digit 6-0. Then, I realized I could use loss of precision from f>d to find more possibilities. (I could add to the number, but still get the same integer square root.) A bit later, I started using bit-shifting to find some, and then all, of the constants. The greater the >> bit-shift, the more I could add to the "magic number" and still get the same result. So I found the smallest bit-shifts I could use to get the necessary results. Even numbers could sometimes use <<, odds had to use >>.

Commented code (\ starts a comment):

\ 49
12544 1 3 << >>

\ 48
24 1 <<

\ 95
1521 4 >>

\ 68
34 1 <<

\ 82
41 1 <<

\ 79
2531 5 >>

\ 87
351 2 >>

\ 83 (x2)
332 2 >> 332 2 >>

\ 65
131 1 >>

\ 80
321 2 >>

gForth does not have the words << or >>. Instead it has lshift and rshift, which I could not use.


问:
How many switches are ON
A class has N student and the class room has N switches (all turned OFF and numbered 1 to N). Each student has an enrollment number assigned from 1 to N. Each student serially (by number) toggles the switches that has a number which is divisible by his/her enrollment number.

Example: Student 1 will turn all the switches ON. Student 2 will turn all even switches OFF. Student N just toggles the Nth switch.

Write a function that takes N as input as returns number of ON switches.
sample I/O

```<code>Input: 10
Output:3
</code>```

No upper bound for N is given, but greater the scope, better the code. Shortest and innovative function wins

答:
J, 9 chars

(Just for a simple example on J)

```<code>f=:[:<.%:
</code>```

floor (<.) of square root (%:)

ContentLicense: CC BY-SA 2.5

Title: How many switches are ON

Body:
J, 9 chars

(Just for a simple example on J)

f=:[:<.%:

floor (<.) of square root (%:)


问:
Find the odd one out in a sequence
The Challenge:

Consider the function F(N) = 2^N + 1 where N is a positive integer less than 31. The sequence defined by this function is:

```<code>3, 5, 9, 17, 33, 65, 129, 257, 513, 1025, 2049, 4097, 8193, 16385, 32769, 65537, 131073, 262145, 524289, 1048577, 2097153, 4194305, 8388609, 16777217, 33554433, 67108865, 134217729, 268435457, 536870913, 1073741825
</code>```

An input will be generated as follows:

Take 5 contiguous integers from the above sequence.

Replace one of them with a different, positive integer (which may or may not be part of the above sequence).

Optionally reorder the the 5 resulting numbers.

Given such a list of 5 integers, find the one that was swapped in and is therefore not part of the original 5 contiguous integers.

Example:

Original sublist: 5, 9, 17, 33, 65.

Replace one: 5, 7, 17, 33, 65.

Reorder: 33, 17, 5, 7, 65.

The expected output would be 7.

The 5 values in the input will always be distinct and there will always be a unique solution. (For instance, you won't have to deal with inputs like 3, 9, 17, 33, 129 where either 3 or 129 might have been swapped in.)

Test Cases:

```<code>5,9,17,33,829
o/p: 829

9,5,17,829,33
o/p: 829

33, 17, 5, 7, 65
o/p: 7

5,9,177,33,65
o/p: 177

65,129,259,513,1025
o/p: 259

129,259,513,1025,65
o/p: 259

63,129,257,513,1025
o/p: 63

65,129,257,513,4097
o/p: 4097

5, 9, 2, 17, 33
o/p: 2

536870913, 67108865, 1073741825, 1, 268435457
o/p: 1
</code>```

Title: Find the odd one out in a sequence

Body:
C#, 69 bytes

int M(int[]a)=>a.Except(new int[30].Select((_,i)=>(1<<i+1)+1)).Sum();


问:
Build a nest
The challenge is simple: write a program or function that, when given a finite non-negative integer, outputs a nested array.

The rules

Your code must produce a unique valid nested array for every integer 0 ≤ n < 231.

Every possible nested array with up to 16 open brackets must be outputted within this range. (This does not mean that your code can never output a nested array with more than 16 open brackets.)

Your code may output a string representation of the nested array instead of an actual array (with or without commas).

One possible mapping:

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

Scoring

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

答:
MATL, 31 bytes

```<code>O`@BEqXJYs0&)0>w~hA+tG>~]x92J-c
</code>```

Try it online! Or verify the first few test cases (takes a few seconds).

The produced mapping is:

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

Explanation

The code keeps testing increasing binary numbers, with digit 0 replaced by -1; that is, using 1 and -1 as digits. Digit 1 will represent '[' and -1 will represent ']'.

The program counts until n+1 valid numbers have been obtained. A number is valid if the following two conditions hold:

The sum of digits is zero (that is, there is an equal number of 1 and -1)

The cumulative sum of digits is always positive (that is, the accumulated number of 1 digits always exceeds that of -1) except at the end (where it is zero by condition 1).

Once n+1 valid numbers have been obtained, the last one is transliterated by changing 1 into [ and -1 into ], and then it is displayed.

Code:

```<code>O          % Push 0: initial count of valid numbers
`          % Do...while
  @        %   Push iteretation index k, starting at 1
  B        %   Convert to binary. For example, k=6 gives [1 1 0 0]
  Eq       %   Multiply by 2, subtract 1: transforms [1 1 0 0] into [1 1 -1 -1]
  XJ       %   Copy that to clipboard J, without popping it
  Ys       %   Cumulative sum: gives [1 2 1 0]
  0&)      %   Split array into its final element and the rest. Gives 0, [1 2 1]
  0>       %   Yields 1 for positive entries (condition 2). So in this case it
           %   gives [1 1 1]
  w        %   Swap: moves second-top element in the stack (0 in this case) to top
  ~        %   Negate: yields 1 if input is 0 (condition 1). Gives 1 in this case
  h        %   Concatenate horizontally. Gives [1 1 1 1]
  A        %   All: gives 1 if all elements are 1. Gives 1 in this case, meaning
           %   that this k is valid
  +        %   Add the result (0 or 1) to the count of valid numbers
  t        %   Duplicate
  G        %   Push input n
  >~       %   Loop condition: false (exit loop) if count exceeds input n
]          % End loop. At this point the result is in clipboard J, in 1/-1 format
x          % Delete count
92         % Push 92. Will be used to convert 1, -1 to '[', ']' (ASCII 91, 93)
J          % Push result in 1/-1 format
-          % Subtract: converts 1 to 91, -1 to 93
c          % Convert to char. Implicitly display
</code>```

Title: Build a nest

Body:
MATL, 31 bytes

O`@BEqXJYs0&)0>w~hA+tG>~]x92J-c

Try it online! Or verify the first few test cases (takes a few seconds).

The produced mapping is:

0 -> []
1 -> [[]]
2 -> [[][]]
3 -> [[[]]]
4 -> [[][][]]
5 -> [[][[]]]
6 -> [[[]][]]
7 -> [[[][]]]
...

Explanation

The code keeps testing increasing binary numbers, with digit 0 replaced by -1; that is, using 1 and -1 as digits. Digit 1 will represent '[' and -1 will represent ']'.

The program counts until n+1 valid numbers have been obtained. A number is valid if the following two conditions hold:

The sum of digits is zero (that is, there is an equal number of 1 and -1)

The cumulative sum of digits is always positive (that is, the accumulated number of 1 digits always exceeds that of -1) except at the end (where it is zero by condition 1).

Once n+1 valid numbers have been obtained, the last one is transliterated by changing 1 into [ and -1 into ], and then it is displayed.

Code:

O          % Push 0: initial count of valid numbers
`          % Do...while
  @        %   Push iteretation index k, starting at 1
  B        %   Convert to binary. For example, k=6 gives [1 1 0 0]
  Eq       %   Multiply by 2, subtract 1: transforms [1 1 0 0] into [1 1 -1 -1]
  XJ       %   Copy that to clipboard J, without popping it
  Ys       %   Cumulative sum: gives [1 2 1 0]
  0&)      %   Split array into its final element and the rest. Gives 0, [1 2 1]
  0>       %   Yields 1 for positive entries (condition 2). So in this case it
           %   gives [1 1 1]
  w        %   Swap: moves second-top element in the stack (0 in this case) to top
  ~        %   Negate: yields 1 if input is 0 (condition 1). Gives 1 in this case
  h        %   Concatenate horizontally. Gives [1 1 1 1]
  A        %   All: gives 1 if all elements are 1. Gives 1 in this case, meaning
           %   that this k is valid
  +        %   Add the result (0 or 1) to the count of valid numbers
  t        %   Duplicate
  G        %   Push input n
  >~       %   Loop condition: false (exit loop) if count exceeds input n
]          % End loop. At this point the result is in clipboard J, in 1/-1 format
x          % Delete count
92         % Push 92. Will be used to convert 1, -1 to '[', ']' (ASCII 91, 93)
J          % Push result in 1/-1 format
-          % Subtract: converts 1 to 91, -1 to 93
c          % Convert to char. Implicitly display


Title: DISARM THE B.O.M.B.!

Body:
You have been hired for your tech knowledge as a Secret Agent's sidekick to ensure that the good guy can get his job done and the world can be saved.

This is your last mission before retiring with a high paycheck and the gratitude of the whole world. But before you have to disarm the Evil Genius' Big Overly Massive BOMB (seems that the evil genius is a smart ass who likes recursive acronyms). Anyways you and your buddy are in the very core of the Evil Genius secret base, ready to disarm the BOMB that could wipe the continent out. In your previous mission you managed to get the disarm code that to your astonishment is just "PASSWORD_01". You connect your keyboard to the BOMB but when you are ready to go, the Evil Genius' henchmen enter in with a barrage of bullets. Unfortunately one of these bullets impacts on your keyboard. "Finish the job while I distract those d*ckheads!" says your buddy and then begins to fire his gun. But how could you finish the job with only half a keyboard?

SPECS

Write a program that outputs in any way you want the string PASSWORD_01 (uppercase).

Since your keyboard has been hit by a bullet, you can only use these keys:

1 2 3 4 5

Q W E R T

A S D F G

< > Z X C

Ctrl Shift Tab Space

Using the Shift key, your keyboard allows you to use these characters:

! " · $ %

You don't have any other hardware than the keyboard and the screen (a mouse for example), nor a file with the password written in your computer.

You don't have an Internet connection.

You can assume you have the interpreter shell / source editor opened before the bullets came in. Sadly you have not written anything in it before the keyboard was hit.

You don't have a virtual keyboard. In fact the BOMB has a TOO_FUNNY detector that will make it explode if you try to use the Standard loopholes.

Since your buddy is waiting for you to finish soon to escape off the Secret Base, you will have to write the smallest code possible (so it's restricted-source and code-golf!).

Good luck because the count down has begun!

HELP MODE: Also a KEY (only one Key you want from the keyboard, but not the Shift + Key or any other combination) has miraculously survived too. E.g.: You can use =, or 0 or /… This extra key cannot be any of the letters in PASSWORD_01 (so you cannot add P or O). Name that key in your answer. You have a penalization of 10 characters for use of this key regardless of how many times you use the key.

Body:
ferNANDo, 179 + 10 = 189 bytes

2 1
1 2 1 2 1 1 1 1
1 2 1 1 1 1 1 2
1 2 1 2 1 1 2 2
1 2 1 2 1 1 2 2
1 2 1 2 1 2 2 2
1 2 1 1 2 2 2 2
1 2 1 2 1 1 2 1
1 2 1 1 1 2 1 1
1 2 1 2 2 2 2 2
1 1 2 2 1 1 1 1
1 1 2 2 1 1 1 2

Try it online!

Enter used. I'd use 0 and 1 to make the code more readable but I can't use 0.


问:
Praming Puzles & Colf: Condense a String
Having spend some time on this site I have come to enjoy things being as short as possible. That may be the reason why I'm recently kind of offended by strings containing the same characters more than once. Your job is to write a function or program which condenses a given string according to the following rules:

Start with a 0-condensation, that is look for the first (leftmost) pair of the same characters with 0 other characters between them. If such a pair is found, remove one of the two characters and restart the algorithm by performing another 0-condensation. If no such pair is found, proceed with the next step. Examples:

  programming -C0-> programing

  aabbcc -C0-> abbcc

  test -C0-> test

Then perform a 1-condensation, that is look for the first pair of same characters with 1 other character between them. If such a pair is found remove one of them and all characters between them and restart with a 0-condensation. If no such pair is found, proceed with the next step. Examples:

abacac -C1-> acac

java -C1-> ja

Continue with a 2-condensation and so on up to a n-condensation with n being the length of the original string, each time restarting after a condensation removed some letters. Examples:

programing -C2-> praming

abcdafg -C3-> afg

The resulting string is called condensed and contains each character at most once.

Input:

A lower case string of printable ascii-characters.

Output:

The condensed string according to the rules above.

Examples:

```<code>examples     -> es
programming  -> praming
puzzles      -> puzles
codegolf     -> colf
andromeda    -> a
abcbaccbabcb -> acb
if(x==1):x++ -> if(x+
fnabnfun     -> fun
abcdefae     -> abcde
</code>```

Detailed examples to clarify how the algorithm works:

```<code>fnabnfun -C0-> fnabnfun -C1-> fnabnfun -C2-> fnfun -C0-> fnfun -C1-> fun -C0-> fun
 -C1-> fun -C2-> ... -C8-> fun

abcbaccbabcb -C0-> abcbacbabcb -C0-> abcbacbabcb -C1-> abacbabcb -C0-> abacbabcb
 -C1-> acbabcb -C0-> acbabcb -C1-> acbcb -C0-> acbcb -C1-> acb -C0-> acb
 -C1-> ... -C12-> acb
</code>```

Your approach doesn't have to implement the algorithm from above as long as your solution and the algorithm return the same output for all allowed inputs.
This is a code-golf challenge.

Thanks to @Linus for helpful sandbox comments!

答:
Haskell, <s>97</s> 88 bytes

(0?)
(a:s)!(b:t)|a==b=a:t|1<3=a:s!t
s!_=s
m?s|length s<m=s|a<-s!drop m s=sum[m+1|a==s]?a
```
<p>Try it online!</p>
<hr />
<h3>Old 97 byte bersion:</h3>

<pre class="lang-haskell prettyprint-override"><code>(a:s)!(b:t)|a==b=a:t|1<3=a:s!t
s!_=s
m?s|length s==m=s|a<-s!drop m s=(last$0:[m+1|a==s])?a
c=(0?)
</code>```

Try it on ideone.

Explanation:

(a:s)!(b:t)|a==b = a:t         --perform condensation
           |1<3  = a:s!t       --recursively compare further
 s   ! _         = s           --no condensation performed
```
<p>The <code>(!)</code> function performs one n-condensation when given a string once whole and once with the first n characters removed, e.g. <code>abcdbe</code> and <code>cdbe</code> for a 2-condensation, by recursively comparing the two leading characters.</p>
<pre class="lang-haskell prettyprint-override"><code>m?s|length s==m   = s         --stop before performing length-s-condensation
   |a <- s!drop m s           --a is the m-condensation of s
    = (last$0:[m+1|a==s])?a   --disguised conditional:
                              -- if a==s       if the m-condensation did not change s
                              -- then (m+1)?a  then perform m+1-condensation
                              -- else 0?a      else restart with a 0-condensation

c=(0?)                        -- main function, initialise m with 0
</code>```

Body:
Haskell, <s>97</s> 88 bytes

(0?)
(a:s)!(b:t)|a==b=a:t|1<3=a:s!t
s!_=s
m?s|length s<m=s|a<-s!drop m s=sum[m+1|a==s]?a

Try it online!

Old 97 byte bersion:

(a:s)!(b:t)|a==b=a:t|1<3=a:s!t
s!_=s
m?s|length s==m=s|a<-s!drop m s=(last$0:[m+1|a==s])?a
c=(0?)

Try it on ideone.

Explanation:

(a:s)!(b:t)|a==b = a:t         --perform condensation
           |1<3  = a:s!t       --recursively compare further
 s   ! _         = s           --no condensation performed

The (!) function performs one n-condensation when given a string once whole and once with the first n characters removed, e.g. abcdbe and cdbe for a 2-condensation, by recursively comparing the two leading characters.

m?s|length s==m   = s         --stop before performing length-s-condensation
   |a <- s!drop m s           --a is the m-condensation of s
    = (last$0:[m+1|a==s])?a   --disguised conditional:
                              -- if a==s       if the m-condensation did not change s
                              -- then (m+1)?a  then perform m+1-condensation
                              -- else 0?a      else restart with a 0-condensation

c=(0?)                        -- main function, initialise m with 0


问:
Number Triangles

Credit

My thanks to Rand Al'Thor's letter-based question for the inspiration for this code-golf challenge.

Background

The nature of this challenge is based off the algorithm mentioned by Rand in his "A Triangle Formed of Three Letters":

Start with a sequence of 10 letters each of which is X, Y, or Z.

Under each row, construct the next row as follows. If two adjacent letters are the same, write the same letter beneath them; if they're different, write the third letter beneath them.

You would then repeat the previous step until you have one letter in your tenth row.

Challenge

We're going to put a mathematical spin on the above algorithm:

Let's start with a sequences of 10 digits, each separated by a space, and each of which is either 1, 2 or 3.

Under each row, construct the next row as follows. If two adjacent digits are the same, write the same digit beneath them; if they're different, write the third digit beneath them.

Repeat the previous step until you have one final number.

So, following this algorithm, if starting with the row 1 2 3 3 1 3 1 3 1 2, for example, the following triangle is generated:

```<code>Input: 1 2 3 3 1 3 1 3 1 2

Output:

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

I'm also curious to know the sum of all the digits in the number triangle, so add all these digits, and put this total in an eleventh row, right-justified to the last digit in the first row. So, our number triangle will look something like the following (spaces in my example are represented below by the . character to show formatting.)

```<code>Input: 1 2 3 3 1 3 1 3 1 2

Output:

1.2.3.3.1.3.1.3.1.2
.3.1.3.2.2.2.2.2.3.
..2.2.1.2.2.2.2.1..
...2.3.3.2.2.2.3...
....1.3.1.2.2.1....
.....2.2.3.2.3.....
......2.1.1.1......
.......3.1.1.......
........2.1........
.........3.........
................109
</code>```

Your challenge is to write code that can start with an inputted string/array/etc. of ten digits, as per my example, and then apply the algorithm to generate the ten rows that would create the number triangle, followed by an 11th row that would display the total of all digits with right-justification.

Testing

Testing of this string can be performed with a randomly generated string of ten digits of your choosing, or one generated from the snippet below...

c1=()=>('1331123221'+(Math.random()*(1<<24)|0).toString(4)).replace(/0/g, "").slice(-10).split("").join(" ");

$("#btn").click(function(){
  $("#str").val(c1());
});```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="str"><button id="btn">Get numbers</button>
<br>
Please use this snippet to generate a starting row for testing your code. Alternatively, you can also use a string of your choice, so long as it's ten digits (ranging from 1 to 3), separated by single spaces.</code>```

Rules

Code-golf rules apply, so lowest number of bytes wins the challenge. In the event that there are two entries with the same low score, the winner will be awarded based on the number of up-votes.

What we're basically after is 11 rows, 19 characters long... How you render your final output is entirely up to you: array, console, file output, STDOUT, etc., so please use whatever output method you like that will work to your advantage. The only rule in the output is that we have 11 rows with 19 characters in each row in a similar format to above...

If it helps your code, use whatever separator for the digits... Just remember that legibility may be a contributing factor.

No silly loopholes.

Hard-coding of the input is not allowed. The purposes of this code is such that it can be used to produce different results each time with varying input. Hard-coding of 1 1 1 1 1 1 1 1 1 1 for example, completely negates the whole point of the algorithm.

Look forward to seeing what you all can come up with!

Title: Number Triangles

Body:
PHP, 143 Bytes

<?for($t=$_GET[t];$i<181;$s+=$v,$i+=2)$t[$i+20]=($v=$t[$i])*($z=$t[$i+2])>0&$i!=18?($v+$z)%3^3:" ";echo chunk_split($t.str_pad($s,8," ",0),19);


答:
Kotlin, 55 bytes

fun f(a:IntArray)=a.find{it-1 !in(1..30).map{1 shl it}}

Title: Find the odd one out in a sequence

Body:
The Challenge:

Consider the function F(N) = 2^N + 1 where N is a positive integer less than 31. The sequence defined by this function is:

```<code>3, 5, 9, 17, 33, 65, 129, 257, 513, 1025, 2049, 4097, 8193, 16385, 32769, 65537, 131073, 262145, 524289, 1048577, 2097153, 4194305, 8388609, 16777217, 33554433, 67108865, 134217729, 268435457, 536870913, 1073741825
</code>```

An input will be generated as follows:

Take 5 contiguous integers from the above sequence.

Replace one of them with a different, positive integer (which may or may not be part of the above sequence).

Optionally reorder the the 5 resulting numbers.

Given such a list of 5 integers, find the one that was swapped in and is therefore not part of the original 5 contiguous integers.

Example:

Original sublist: 5, 9, 17, 33, 65.

Replace one: 5, 7, 17, 33, 65.

Reorder: 33, 17, 5, 7, 65.

The expected output would be 7.

The 5 values in the input will always be distinct and there will always be a unique solution. (For instance, you won't have to deal with inputs like 3, 9, 17, 33, 129 where either 3 or 129 might have been swapped in.)

Test Cases:

```<code>5,9,17,33,829
o/p: 829

9,5,17,829,33
o/p: 829

33, 17, 5, 7, 65
o/p: 7

5,9,177,33,65
o/p: 177

65,129,259,513,1025
o/p: 259

129,259,513,1025,65
o/p: 259

63,129,257,513,1025
o/p: 63

65,129,257,513,4097
o/p: 4097

5, 9, 2, 17, 33
o/p: 2

536870913, 67108865, 1073741825, 1, 268435457
o/p: 1
</code>```


问:
Tips for golfing in C
What general tips do you have for golfing in C? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to C (e.g. "remove comments" is not an answer). Please post one tip per answer. Also, please include if your tip applies to C89 and/or C99 and if it only works on certain compilers.</p>

答:
Reverse Loops

If you can, try to replace

```<code>for(int i=0;i<n;i++){...}
</code>```

with

```<code>for(int i=n;i--;){...}
</code>```

Title: Tips for golfing in C

Body:
Reverse Loops

If you can, try to replace

for(int i=0;i<n;i++){...}

with

for(int i=n;i--;){...}


问:
Can you outgolf me? (Robbers section)

Robbers section

The cops section can be found here.

Challenge

Your task is to outgolf the submissions of the cops in the same language and the same version (for example, Python 3.5 ≠ Python 3.4, so that is not allowed). A submission is outgolfed when the length in bytes is shorter than the original submission. You only need to golf off at least 1 byte in order to crack a submission. E.g. if the task was to perform 2 × n, and the submission was the following:

```<code>print(2*input())
</code>```

You could outgolf the cop by doing the following:

```<code>print 2*input()
</code>```

Or even this (since lambda's are allowed):

```<code>lambda x:2*x
</code>```

Post this with the following header:

```<code>##{language name}, <s>{prev byte count}</s> {byte count}, {cop's submission + link}
</code>```

For example:

Python 2, <s>16</s> 12 bytes, Adnan (+ link to submission)

```<code>lambda x:2*x
</code>```

Computes A005843, (offset = 0).

In that case, you have cracked the submission.

Scoring

The person with who cracked the most submissions is the winner.

Rules

The crack submission must be in the same language as the cop submission.

The same input should result into the same output (so a(2) = 4 should remain 4).

For languages such as Python, you can import libraries that are standard included within the language. (So, no numpy/sympy etc.)

Input and output are both in decimal (base 10).

Note

This challenge is finished. The winner of the Robbers section is feersum. The final scores for the CnR are shown below:

feersum: 16 cracks

Dennis: 12 cracks

Leaky Nun: 6 cracks

Lynn: 4 cracks

miles: 3 cracks

Martin Ender: 2 cracks

Emigna: 2 cracks

jimmy23013: 1 crack

Sp3000: 1 crack

randomra: 1 crack

alephalpha: 1 crack

nimi: 1 crack

Destructible Watermelon: 1 crack

Dom Hastings: 1 crack

答:
J, <s>18</s> 13 bytes, miles

```<code>(2&-%-.-*:)t.
</code>```

I checked the <s>shortest</s> most popular J answer for Fibonacci numbers: a generating function. Unsurprisingly, the same approach is also good for Lucas numbers.

Title: Can you outgolf me? (Robbers section)

Body:
J, <s>18</s> 13 bytes, miles

(2&-%-.-*:)t.

I checked the <s>shortest</s> most popular J answer for Fibonacci numbers: a generating function. Unsurprisingly, the same approach is also good for Lucas numbers.


答:
Haskell

Not able to compute for n=1: <s>175</s> 160 bytes

When compiled, it took my computer 2h 35m to compute for an input of (1000000,100) using this:

```<code>n#s=y:(n#p)where y:p=drop(n-1)s
n%s=f n s$[]where f n s=(take(n-1)s++).f n(drop n s)
l 2=[1,3..]
l m=((l$m-1)!!(m-2))%(l$m-1)
m?n=(((l n)!!(n-1))#(l$n))!!(m-1)
</code>```

I tried ridding the where modules, but they seem to affect the speed and I'm not sure why... But I think there is more pruning to be done here.

The method to use is m?n for querying the answer given an m and n.

Ungolfed

```<code>everynth n xs = y:(everynth n ys) -- Takes every nth element from a list 'xs'
  where y:ys = drop (n-1) xs

skipeverynth n xs = f' n xs $ []  -- Removes every nth element from a list 'xs'
  where f' n xs = (take (n-1) xs ++) . f' n (drop n xs)

l 2 = [1,3..] -- The base case of the list of lucky numbers for 'n=2'
l m = skipeverynth ((l$m-1)!!(m-2)) (l$m-1) -- Recursively defining next case as being the last one with every 'ath' element skipped. Here, 'a' is the (m-1)th elemnent of the (l (m-1)) list.
ul m = everynth ((l m)!!(m-1)) (l$m) -- This is not used other than to compute the final, required unlucky number list. It picks out every 'ath' element.

ans m n = (ul n)!!(m-1) -- The function giving the answer.
</code>```

I reckon it may be possible to combine the 'skipeverynth' and 'everynth' functions into a single function which returns a pair.

I used this kind person's code for skipping every nth element. I did it myself a few times, but it was always much more inefficient and I couldn't figure out why.

Able to compute for all n: 170 bytes

This is basically the same, but a couple of max functions had to be thrown in to handle the special case of n=1.

```<code>n#s=y:(n#p)where y:p=drop(n-1)s
n%s=f n s$[]where f n s=(take(n-1)s++).f n(drop n s)
l 1=[1..]
l m=((l$m-1)!!(max 1$m-2))%(l$m-1)
m?n=(((l n)!!(max 1$n-1))#(l$n))!!(m-1)
</code>```

Title: Unlucky Numbers!

Body:
Things to know:

First, lucky numbers.

Lucky numbers are generated like so:

Take all the natural numbers:

```<code>1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20...
</code>```

Then, remove each second number.

```<code>1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39...
</code>```

Now, 3 is safe.

Remove every 3rd number:

```<code>1, 3, 7, 9, 13, 15, 19, 21, 25, 27, 31, 33, 37, 39, 43, 45, 49, 51, 55, 59...
</code>```

Now, 7 is safe.

Remove every 7th number.

Continue, and remove every nth number, where n is the first safe number after an elimination.

The final list of safe numbers is the lucky numbers.

The unlucky numbers is composed of separate lists of numbers, which are [U1, U2, U3... Un].

U1 is the first set of numbers removed from the lucky "candidates", so they are:

```<code>2, 4, 6, 8, 10, 12, 14, 16, 18, 20...
</code>```

U2 is the second set of numbers removed:

```<code>5, 11, 17, 23, 29, 35, 41, 47, 53, 59...
</code>```

And so on and so forth (U3 is the third list, U4 is the fourth, etc.)

Challenge:

Your task is, when given two inputs m and n, generate the mth number in the list Un.

Example inputs and outputs:

```<code>(5, 2) -> 29
(10, 1) -> 20
</code>```

Specs:

Your program must work for m up to 1e6, and n up to 100.

You are guaranteed that both m and n are positive integers.

If you're curious, U(1e6, 100) = 5,333,213,163. (Thank you @pacholik!)

Your program must compute that within 1 day on a reasonable modern computer.

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

PS: It would be nice if someone came up with a general formula for generating these. If you do have a formula, please put it in your answer!

Body:
Haskell

Not able to compute for n=1: <s>175</s> 160 bytes

When compiled, it took my computer 2h 35m to compute for an input of (1000000,100) using this:

n#s=y:(n#p)where y:p=drop(n-1)s
n%s=f n s$[]where f n s=(take(n-1)s++).f n(drop n s)
l 2=[1,3..]
l m=((l$m-1)!!(m-2))%(l$m-1)
m?n=(((l n)!!(n-1))#(l$n))!!(m-1)

I tried ridding the where modules, but they seem to affect the speed and I'm not sure why... But I think there is more pruning to be done here.

The method to use is m?n for querying the answer given an m and n.

Ungolfed

everynth n xs = y:(everynth n ys) -- Takes every nth element from a list 'xs'
  where y:ys = drop (n-1) xs

skipeverynth n xs = f' n xs $ []  -- Removes every nth element from a list 'xs'
  where f' n xs = (take (n-1) xs ++) . f' n (drop n xs)

l 2 = [1,3..] -- The base case of the list of lucky numbers for 'n=2'
l m = skipeverynth ((l$m-1)!!(m-2)) (l$m-1) -- Recursively defining next case as being the last one with every 'ath' element skipped. Here, 'a' is the (m-1)th elemnent of the (l (m-1)) list.
ul m = everynth ((l m)!!(m-1)) (l$m) -- This is not used other than to compute the final, required unlucky number list. It picks out every 'ath' element.

ans m n = (ul n)!!(m-1) -- The function giving the answer.

I reckon it may be possible to combine the 'skipeverynth' and 'everynth' functions into a single function which returns a pair.

I used this kind person's code for skipping every nth element. I did it myself a few times, but it was always much more inefficient and I couldn't figure out why.

Able to compute for all n: 170 bytes

This is basically the same, but a couple of max functions had to be thrown in to handle the special case of n=1.

n#s=y:(n#p)where y:p=drop(n-1)s
n%s=f n s$[]where f n s=(take(n-1)s++).f n(drop n s)
l 1=[1..]
l m=((l$m-1)!!(max 1$m-2))%(l$m-1)
m?n=(((l n)!!(max 1$n-1))#(l$n))!!(m-1)


问:
Compute the Carmichael function

Task description

In number theory, the Carmichael function λ takes a positive integer n and returns the least positive integer k so that the k-th power of each integer coprime to n equals 1 modulo n.

Given a positive integer n, your solution must compute λ(n). The shortest code in bytes wins.

Your program should theoretically work for arbitrarily large inputs, but doesn’t need to be efficient.

Tips

The sequence of all λ(n) is OEIS A002322.

An ungolfed Python implementation would look like

```<code>from fractions import gcd

def carmichael(n):
    coprimes = [x for x in range(1, n) if gcd(x, n) == 1]
    k = 1
    while not all(pow(x, k, n) == 1 for x in coprimes):
        k += 1
    return k
</code>```

(In Python, pow(A, B, C) efficiently computes pow(A, B) % C.)

Test cases

```<code>Input    Output
1        1
2        1
3        2
10       4
35       12
101      100
530      52
3010     84
6511     3056
10000    500
</code>```

答:
Racket 218 bytes

```<code>(λ(n)(let((fl #f)(cl(for/list((i n) #:when(coprime? n i))i)))(for/sum((k(range 1 n))#:break fl)(set! fl #t)
(for((i(length cl))#:break(not fl))(when(not(= 1(modulo(expt(list-ref cl i)k)n)))(set! fl #f)))(if fl k 0))))
</code>```

Ungolfed version:

```<code>(require math)
(define f
  (λ(n)
    (let ((fl #f)
          (cl (for/list ((i n) #:when (coprime? n i))
                i)))
             (for/sum ((k (range 1 n)) #:break fl)
               (set! fl #t)
               (for ((i (length cl)) #:break (not fl))
                 (when (not (= 1 (modulo (expt (list-ref cl i) k) n)))
                   (set! fl #f)))
               (if fl k 0)))))
</code>```

Testing:

```<code>(f 2)
(f 3)
(f 10)
(f 35)
(f 101)
(f 530)
(f 3010)
(f 6511)
(f 10000)
</code>```

Output:

```<code>1
2
4
12
100
52
84
3056
500
</code>```

Title: Compute the Carmichael function

Body:
Racket 218 bytes

(λ(n)(let((fl #f)(cl(for/list((i n) #:when(coprime? n i))i)))(for/sum((k(range 1 n))#:break fl)(set! fl #t)
(for((i(length cl))#:break(not fl))(when(not(= 1(modulo(expt(list-ref cl i)k)n)))(set! fl #f)))(if fl k 0))))

Ungolfed version:

(require math)
(define f
  (λ(n)
    (let ((fl #f)
          (cl (for/list ((i n) #:when (coprime? n i))
                i)))
             (for/sum ((k (range 1 n)) #:break fl)
               (set! fl #t)
               (for ((i (length cl)) #:break (not fl))
                 (when (not (= 1 (modulo (expt (list-ref cl i) k) n)))
                   (set! fl #f)))
               (if fl k 0)))))

Testing:

(f 2)
(f 3)
(f 10)
(f 35)
(f 101)
(f 530)
(f 3010)
(f 6511)
(f 10000)

Output:

1
2
4
12
100
52
84
3056
500


问:
When was this language released?
Your challenge is simple. You need to write a program that prints to either STDOUT or a file the year the language it is written in was released. Because this is such a simple task, the twist is that it must be written in as many different languages as possible.

Your score is the total number of different years that are correctly printed.

For each language you use, you must

Specify which version of the language you are using. (If there are multiple versions)

Specify what year that version was first released, and

Provide a link to a page proving the date of your version/language.

Any one of these counts as release date proof, as long as it specifies the version number (if applicable) and a release date.

A wikipedia page.

An esolangs page.

The language's official website. A github page or similar counts, as long as it has a release date. (Latest commit does not count, unless there is a version number somewhere in the code)

If there are not multiple versions or releases of a language, just use the initial release date of the language.

Minor versions of the same language do count as different languages, as long as they come from different years and still produce the correct output. You may not use any builtins that give you information (including release date) about the current version of the language you are using. For example, this is an invalid python submission:

```<code>import platform
i = platform.python_version()
if i == '3.5':
    print(2015)
if i == '3.4':
    print(2014)
if i == '3.3':
    print(2012)
...
</code>```

Whichever submission correctly prints the most distinct years wins!

Rules

Each program must print out the language year and nothing more. A trailing newline (windows style or *nix style) is allowed.

No programs may take any input.

In case of a tie, the shortest code scored in bytes wins. You may use whatever encoding you like for this, but all programs must use the same encoding.

Any of the programs may print to STDERR, or throw runtime/compile time errors and warnings as long as the correct output is still printed to STDOUT or a file.

Different languages may use different IO methods, but they most all be full programs, (functions not allowed for this challenge) and follow one of our default IO methods allowed.

Happy <s>golfing</s> polyglotting!

答:
2 languages, Python 2.7 and Python 3.5

Python 2.7 was released in 2010.

Python 3.5 was released in 2015.

```<code>print('2010'if 3/2==1else'2015')
</code>```

This relies on PEP 238 where the operator / was changed from integer division in Python 2 to floating-point division in Python 3.

Title: When was this language released?

Body:
2 languages, Python 2.7 and Python 3.5

Python 2.7 was released in 2010.

Python 3.5 was released in 2015.

print('2010'if 3/2==1else'2015')

This relies on PEP 238 where the operator / was changed from integer division in Python 2 to floating-point division in Python 3.


答:
5 years

```<code>#define q/*-[>+<-----]>--.++++++++..------.[-][
print('2010'if len(bin.__doc__)==86else'2015')
"""*/
main(c){c=-4.5//**/
-4.5;printf("19%d",90-c);}
#define w/*]
*/"""
</code>```

1989: C89[1], and 1999: C99

The single line comment // was added in C99, so a C89 compiler would read that code as c=-4.5 / /*comment*/ -4.5, which is the same as c=-4.5 / -4.5, whereas a C99 compiler would read as c=-4.5 //comment/**/

- 4.5, which is the same as c=-4.5 - 4.5.

The Python part is a comment in the C program.

2010: Python 2.7, and 2015: Python 3.5

The docs vary between Python 3 and 2, this program uses the length of the docs to detect the Python version.

The C part is in a string in the Python program.

1993[2]: Brainfuck

It basically ignores everything that aren't .,[]+-<>. Since C program has a , in it, I had to make Brainfuck to dismiss that part by setting the current byte to 0.

The C89 spec was released in 1990. More info.

I couldn't find an official release date, so I'll believe Esolangs and Wikipedia.

Title: When was this language released?

Body:
Your challenge is simple. You need to write a program that prints to either STDOUT or a file the year the language it is written in was released. Because this is such a simple task, the twist is that it must be written in as many different languages as possible.

Your score is the total number of different years that are correctly printed.

For each language you use, you must

Specify which version of the language you are using. (If there are multiple versions)

Specify what year that version was first released, and

Provide a link to a page proving the date of your version/language.

Any one of these counts as release date proof, as long as it specifies the version number (if applicable) and a release date.

A wikipedia page.

An esolangs page.

The language's official website. A github page or similar counts, as long as it has a release date. (Latest commit does not count, unless there is a version number somewhere in the code)

If there are not multiple versions or releases of a language, just use the initial release date of the language.

Minor versions of the same language do count as different languages, as long as they come from different years and still produce the correct output. You may not use any builtins that give you information (including release date) about the current version of the language you are using. For example, this is an invalid python submission:

```<code>import platform
i = platform.python_version()
if i == '3.5':
    print(2015)
if i == '3.4':
    print(2014)
if i == '3.3':
    print(2012)
...
</code>```

Whichever submission correctly prints the most distinct years wins!

Rules

Each program must print out the language year and nothing more. A trailing newline (windows style or *nix style) is allowed.

No programs may take any input.

In case of a tie, the shortest code scored in bytes wins. You may use whatever encoding you like for this, but all programs must use the same encoding.

Any of the programs may print to STDERR, or throw runtime/compile time errors and warnings as long as the correct output is still printed to STDOUT or a file.

Different languages may use different IO methods, but they most all be full programs, (functions not allowed for this challenge) and follow one of our default IO methods allowed.

Happy <s>golfing</s> polyglotting!

Body:
5 years

#define q/*-[>+<-----]>--.++++++++..------.[-][
print('2010'if len(bin.__doc__)==86else'2015')
"""*/
main(c){c=-4.5//**/
-4.5;printf("19%d",90-c);}
#define w/*]
*/"""

1989: C89[1], and 1999: C99

The single line comment // was added in C99, so a C89 compiler would read that code as c=-4.5 / /*comment*/ -4.5, which is the same as c=-4.5 / -4.5, whereas a C99 compiler would read as c=-4.5 //comment/**/

- 4.5, which is the same as c=-4.5 - 4.5.

The Python part is a comment in the C program.

2010: Python 2.7, and 2015: Python 3.5

The docs vary between Python 3 and 2, this program uses the length of the docs to detect the Python version.

The C part is in a string in the Python program.

1993[2]: Brainfuck

It basically ignores everything that aren't .,[]+-<>. Since C program has a , in it, I had to make Brainfuck to dismiss that part by setting the current byte to 0.

The C89 spec was released in 1990. More info.

I couldn't find an official release date, so I'll believe Esolangs and Wikipedia.


问:
Compute the Mertens function
Given a positive integer n, compute the value of the Mertens function \$M(n)\$ where:

$$M(n) = \Sigma_{k=1}^{n}\mu(k)$$

and \$\mu(k)\$ is the Möbius function where \$μ(k) = 1\$ if \$k\$ has an even number of distinct prime factors, \$-1\$ if \$k\$ has an odd number of distinct prime factors, and \$0\$ if the prime factors are not distinct.

This is code-golf so create the shortest code for a function or program that computes the Mertens function for an input integer n > 0.

This is the OEIS sequence A002321.

Test Cases

```<code>n M(n)
1 1
2 0
3 -1
4 -1
5 -2
6 -1
7 -2
8 -2
9 -2
10 -1
117 -5
5525 5
7044 -25
8888 4
10000 -23
</code>```

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

Thanks to @miles for saving 2 bytes.

```<code>Tr@*MoebiusMu@*Range
</code>```

Explanation

```<code>Range
</code>```

Generate a list from 1 to input.

```<code>MoebiusMu
</code>```

Find MoebiusMu of each number

```<code>Tr
</code>```

Sum the result.

Title: Compute the Mertens function

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

Thanks to @miles for saving 2 bytes.

Tr@*MoebiusMu@*Range

Explanation

Range

Generate a list from 1 to input.

MoebiusMu

Find MoebiusMu of each number

Tr

Sum the result.


答:
05AB1E, <s>16</s> 15 bytes

```<code>LÒvX(ygmyyÙïQ*O
</code>```

Explanation

```<code>L        # range [1 .. n]
Ò        # list of prime factors for each in list
v        # for each prime factor list
 X(ygm   # (-1)^len(factors)
 yyÙïQ*  # multiplied by factors == (unique factors)
 O       # sum
</code>```

Try it online!

Title: Compute the Mertens function

Body:
Given a positive integer n, compute the value of the Mertens function \$M(n)\$ where:

$$M(n) = \Sigma_{k=1}^{n}\mu(k)$$

and \$\mu(k)\$ is the Möbius function where \$μ(k) = 1\$ if \$k\$ has an even number of distinct prime factors, \$-1\$ if \$k\$ has an odd number of distinct prime factors, and \$0\$ if the prime factors are not distinct.

This is code-golf so create the shortest code for a function or program that computes the Mertens function for an input integer n > 0.

This is the OEIS sequence A002321.

Test Cases

```<code>n M(n)
1 1
2 0
3 -1
4 -1
5 -2
6 -1
7 -2
8 -2
9 -2
10 -1
117 -5
5525 5
7044 -25
8888 4
10000 -23
</code>```

Body:
05AB1E, <s>16</s> 15 bytes

LÒvX(ygmyyÙïQ*O

Explanation

L        # range [1 .. n]
Ò        # list of prime factors for each in list
v        # for each prime factor list
 X(ygm   # (-1)^len(factors)
 yyÙïQ*  # multiplied by factors == (unique factors)
 O       # sum

Try it online!


答:
Short and sweet; the three APLs (K, J201, Dyalog  7.1) in 8 bytes

```<code>1993+1^2
</code>```

1993 plus...

K: the first 1 integer {0} except {2}, i.e. {0}; 1993 – Try it online!

J: 12 = 1; 1994 – Try it online!

APL: LCM(1,2) = 2; 1995 – Try it online!

Title: When was this language released?

Body:
Short and sweet; the three APLs (K, J201, Dyalog  7.1) in 8 bytes

1993+1^2

1993 plus...

K: the first 1 integer {0} except {2}, i.e. {0}; 1993 – Try it online!

J: 12 = 1; 1994 – Try it online!

APL: LCM(1,2) = 2; 1995 – Try it online!


答:
Jelly, 9 bytes

```<code>RÆFỊNP€FS
</code>```

Try it online! or verify all test cases.

How it works

```<code>RÆFỊNP€FS  Main link. Argument: n

R          Range; yield [1, ..., n].
 ÆF        Factor; decompose each integer in that range into prime-exponent pairs.
   Ị       Insignificant; yield 1 for argument 1, 0 for all others.
    N      Negative; map n to -n.
           This maps primes to 0, exponent 1 to -1, and all other exponents to 0.
     P€    Reduce the columns of the resulting 2D arrays by multiplication.
           The product of the prime values will always be 0; the product of the
           exponent values is 0 if any exponent is greater than, 1 if there is an
           even number of them, -1 is there is an odd number of them.
       FS  Flatten and sum, computing the sum of µ(k) for k in [1, ..., n].
</code>```

Title: Compute the Mertens function

Body:
Jelly, 9 bytes

RÆFỊNP€FS

Try it online! or verify all test cases.

How it works

RÆFỊNP€FS  Main link. Argument: n

R          Range; yield [1, ..., n].
 ÆF        Factor; decompose each integer in that range into prime-exponent pairs.
   Ị       Insignificant; yield 1 for argument 1, 0 for all others.
    N      Negative; map n to -n.
           This maps primes to 0, exponent 1 to -1, and all other exponents to 0.
     P€    Reduce the columns of the resulting 2D arrays by multiplication.
           The product of the prime values will always be 0; the product of the
           exponent values is 0 if any exponent is greater than, 1 if there is an
           even number of them, -1 is there is an odd number of them.
       FS  Flatten and sum, computing the sum of µ(k) for k in [1, ..., n].


答:
Jelly, 7 bytes

```<code>Ị*%ðþÆḊ
</code>```

Not very efficient; determinants are hard.

Try it online! or verify the smaller test cases. (takes a while)

Background

This uses a formula from A002321:

M(n) is the determinant of the Boolean matrix An×n, where ai,j is 1 if j = 1 or i | j, and 0 otherwise.

How it works

```<code>Ị*%ðþÆḊ  Main link. Argument: n

   ð     Combine the preceding atoms into a chain (unknown arity).
         Begin a new, dyadic chain with arguments a and b.
Ị        Insignificant; return 1 iff a = 1.
  %      Compute a % b.
 *       Compute (a == 1) ** (a % b).
         This yields 1 if a = 1, or if a ≠ 1 and a % b = 0; otherwise, it yields 0.
    þ    Table; construct the matrix A by calling the defined chain for every pair
         of integers in [1, ..., n].
     ÆḊ  Compute the determinant of the resulting matrix.
</code>```

Title: Compute the Mertens function

Body:
Jelly, 7 bytes

Ị*%ðþÆḊ

Not very efficient; determinants are hard.

Try it online! or verify the smaller test cases. (takes a while)

Background

This uses a formula from A002321:

M(n) is the determinant of the Boolean matrix An×n, where ai,j is 1 if j = 1 or i | j, and 0 otherwise.

How it works

Ị*%ðþÆḊ  Main link. Argument: n

   ð     Combine the preceding atoms into a chain (unknown arity).
         Begin a new, dyadic chain with arguments a and b.
Ị        Insignificant; return 1 iff a = 1.
  %      Compute a % b.
 *       Compute (a == 1) ** (a % b).
         This yields 1 if a = 1, or if a ≠ 1 and a % b = 0; otherwise, it yields 0.
    þ    Table; construct the matrix A by calling the defined chain for every pair
         of integers in [1, ..., n].
     ÆḊ  Compute the determinant of the resulting matrix.


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

```<code>yb:1a+
$p#dl:_1r^|,0
</code>```

Try it online!

Explanation

```<code>yb                 The list [1, 2, …, Input]
  :1a              Apply predicate 1 (second line) to each element
     +             Sum the resulting list

    $p#d               All elements of the list of prime factors of the Input are distinct
        l:_1r^         Output = (-1)^(<length of the list of prime factors>)
|                  Or
    ,0                 Output = 0
</code>```

Title: Compute the Mertens function

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

yb:1a+
$p#dl:_1r^|,0

Try it online!

Explanation

yb                 The list [1, 2, …, Input]
  :1a              Apply predicate 1 (second line) to each element
     +             Sum the resulting list

    $p#d               All elements of the list of prime factors of the Input are distinct
        l:_1r^         Output = (-1)^(<length of the list of prime factors>)
|                  Or
    ,0                 Output = 0


答:
3 years (GolfScript, CJam, MATL), <s>24</s> 23 bytes

```<code>[A11]Wd%;200 1e2/0 8_+(
</code>```

This outputs

2007  in GolfScript.

2015 in CJam (version 0.6.5).

2016 in MATL (version 19.2.0).

Explanation

Golfscript

Undefined tokens are noops in GolfScript. The only parts of the code that actually do something are:

```<code>200      Push 200
           STACK: 200
1        Push 1
            STACK: 200, 1
/        Divide
           STACK: 200
0        Push 0
           STACK: 200, 0
8        Push 8
           STACK: 200, 0, 8
+        Add
           STACK: 200, 8
(        Subtract 1
           STACK: 200, 7
         Implicitly display 200, 7 as "2007"
</code>```

CJam

```<code>[A11]    Push array [10 11]
           STACK: [10 11]
W        Push -1
           STACK: [10 11], -1
d        Convert to double
           STACK: [10 11], -1.0
%        Select elements from array
           STACK: [11 10]
;        Pop
           STACK is empty
200      Push 200
           STACK: 200
1e2      Push 100
           STACK: 100
/        Divide
           STACK: 2
0        Push 0
           STACK: 2, 0
8_       Push 8 and duplicate
           STACK: 2, 0, 8, 8
+        Add
           STACK: 2, 0, 16
(        Subtract 1
           STACK: 2, 0, 15
         Implicitly display 2, 0, 15 as "2015"
</code>```

MATL

Everything from % onwards is a comment.

```<code>[A11]    Push array [5 11]
           STACK: [5 11]
W        2 raised to that
           STACK: [32 2048]
d        Compute increment
           STACK: 2016
         Implicitly display as "2016"
</code>```

Title: When was this language released?

Body:
3 years (GolfScript, CJam, MATL), <s>24</s> 23 bytes

[A11]Wd%;200 1e2/0 8_+(

This outputs

2007  in GolfScript.

2015 in CJam (version 0.6.5).

2016 in MATL (version 19.2.0).

Explanation

Golfscript

Undefined tokens are noops in GolfScript. The only parts of the code that actually do something are:

200      Push 200
           STACK: 200
1        Push 1
            STACK: 200, 1
/        Divide
           STACK: 200
0        Push 0
           STACK: 200, 0
8        Push 8
           STACK: 200, 0, 8
+        Add
           STACK: 200, 8
(        Subtract 1
           STACK: 200, 7
         Implicitly display 200, 7 as "2007"

CJam

[A11]    Push array [10 11]
           STACK: [10 11]
W        Push -1
           STACK: [10 11], -1
d        Convert to double
           STACK: [10 11], -1.0
%        Select elements from array
           STACK: [11 10]
;        Pop
           STACK is empty
200      Push 200
           STACK: 200
1e2      Push 100
           STACK: 100
/        Divide
           STACK: 2
0        Push 0
           STACK: 2, 0
8_       Push 8 and duplicate
           STACK: 2, 0, 8, 8
+        Add
           STACK: 2, 0, 16
(        Subtract 1
           STACK: 2, 0, 15
         Implicitly display 2, 0, 15 as "2015"

MATL

Everything from % onwards is a comment.

[A11]    Push array [5 11]
           STACK: [5 11]
W        2 raised to that
           STACK: [32 2048]
d        Compute increment
           STACK: 2016
         Implicitly display as "2016"


答:
6 languages, Turtlèd and brainfuck, Python 3.5, Python 2.7, ><>, Fission

Turtlèd has not existed before this year, and so easily objective, even if the github commits don't count, and BF has the esolang page evidence, released 1993. Python 3.5 is 2015, 2.7 is 2010. ><> also has esolang page, stating 2009, as does Fission, 2014

```<code>#-[>+<-----]>--.++++++++..------#"2016"/
print(2015 if len(len.__doc__)==42 else 2010)
#;                           oooo"2009"/
#;"4102"L
</code>```

I should probably give credit to the bf constants page on esolangs... ¯\_(ツ)_/¯

How it works, kind of:

Turtlèd:

Turtlèd doesn't really do anything for lines other than the first:

```<code>#-[>+<-----]>--.++++++++..------#"2016"/
  ^sets string variable to this   ^ prints 2016
</code>```

/ is a nop

Brainfuck

Brainfuck ignores chars not in its commands

it sees -[>+<-----]>--.++++++++..------. (the last . is from the python part)

which just does Brainfuck stuff, it uses wrapping to divide 255 by 5, then subtract 2 from the result, print, increment 8 times, print twice, decrement 6 times, print

Python 2 and 3

```<code>print(2015 if len(len.__doc__)==42 else 2010)
</code>```

the length of the docs for len vary between the versions, so it prints the year for version 3 if it is the right length, else for version 2.

><>

# reflects the pointer backwards, so it hits the / on the other side of that line, passes through the space between else and 2010, then reflects again to hit "2009", pushing 9,0,0,2 onto stack, then printing out reversed.

Fission

Fission has spawners, so we can have a line at the bottom that it executes alone:

```<code>#;"4102"L
        L spawn left moving atom
  "4102"  print this right to left
 ;        halt
# python comment
</code>```

Title: When was this language released?

Body:
6 languages, Turtlèd and brainfuck, Python 3.5, Python 2.7, ><>, Fission

Turtlèd has not existed before this year, and so easily objective, even if the github commits don't count, and BF has the esolang page evidence, released 1993. Python 3.5 is 2015, 2.7 is 2010. ><> also has esolang page, stating 2009, as does Fission, 2014

#-[>+<-----]>--.++++++++..------#"2016"/
print(2015 if len(len.__doc__)==42 else 2010)
#;                           oooo"2009"/
#;"4102"L

I should probably give credit to the bf constants page on esolangs... ¯\_(ツ)_/¯

How it works, kind of:

Turtlèd:

Turtlèd doesn't really do anything for lines other than the first:

#-[>+<-----]>--.++++++++..------#"2016"/
  ^sets string variable to this   ^ prints 2016

/ is a nop

Brainfuck

Brainfuck ignores chars not in its commands

it sees -[>+<-----]>--.++++++++..------. (the last . is from the python part)

which just does Brainfuck stuff, it uses wrapping to divide 255 by 5, then subtract 2 from the result, print, increment 8 times, print twice, decrement 6 times, print

Python 2 and 3

print(2015 if len(len.__doc__)==42 else 2010)

the length of the docs for len vary between the versions, so it prints the year for version 3 if it is the right length, else for version 2.

><>

# reflects the pointer backwards, so it hits the / on the other side of that line, passes through the space between else and 2010, then reflects again to hit "2009", pushing 9,0,0,2 onto stack, then printing out reversed.

Fission

Fission has spawners, so we can have a line at the bottom that it executes alone:

#;"4102"L
        L spawn left moving atom
  "4102"  print this right to left
 ;        halt
# python comment


答:
Racket 103 bytes

```<code>(λ(N)(for/sum((n(range 1 N)))(define c(length(factorize n)))(cond[(= 0 c)0][(even? c)1][(odd? c)-1])))
</code>```

Ungolfed:

```<code>(define f
  (λ(N)
    (for/sum ((n (range 1 N)))
      (define c (length (factorize n)))
      (cond
        [(= 0 c) 0]
        [(even? c) 1]
        [(odd? c) -1]))))
</code>```

Title: Compute the Mertens function

Body:
Racket 103 bytes

(λ(N)(for/sum((n(range 1 N)))(define c(length(factorize n)))(cond[(= 0 c)0][(even? c)1][(odd? c)-1])))

Ungolfed:

(define f
  (λ(N)
    (for/sum ((n (range 1 N)))
      (define c (length (factorize n)))
      (cond
        [(= 0 c) 0]
        [(even? c) 1]
        [(odd? c) -1]))))


答:
Python 2, <s>45</s> 37 bytes

f=lambda n,k=2:n<k or f(n,k+1)-f(n/k)
```

<p>Test it on Ideone.</p>

<h3>Background</h3>

<p>This uses the property</p>

<p><img src="https://i.stack.imgur.com/rhDhP.png" alt="property by David W. Wilson"></p>

<p>from A002321, which leads to the following recursive formula.</p>

<p><img src="https://i.stack.imgur.com/VjAmY.png" alt="recursive formula"></p>

<h3>How it works</h3>

<p>We use recursion not only to compute <strong>M</strong> for the quotients, but to compute the sum of those images as well. This saves 8 bytes over the following, straightforward implementation.</p>

<pre class="lang-python prettyprint-override"><code>M=lambda n:1-sum(M(n/k)for k in range(2,n+1))
</code>```

When f is called with a single argument n, the optional argument k defaults to 2.

If n = 1, n<k yields True and f returns this value. This is our base case.

If n > 1, n<k initially returns False and the code following or is executed. f(n/k) recursively computes one term of the sum, which is subtracted from the return value of f(n,k+1). The latter increments k and recursively calls f, thus iterating over the possible values of k. Once n < k + 1 or n = 1, f(n,k+1) will return 1, ending the recursion.

Title: Compute the Mertens function

Body:
Python 2, <s>45</s> 37 bytes

f=lambda n,k=2:n<k or f(n,k+1)-f(n/k)

Test it on Ideone.

Background

This uses the property

from A002321, which leads to the following recursive formula.

How it works

We use recursion not only to compute M for the quotients, but to compute the sum of those images as well. This saves 8 bytes over the following, straightforward implementation.

M=lambda n:1-sum(M(n/k)for k in range(2,n+1))

When f is called with a single argument n, the optional argument k defaults to 2.

If n = 1, n<k yields True and f returns this value. This is our base case.

If n > 1, n<k initially returns False and the code following or is executed. f(n/k) recursively computes one term of the sum, which is subtracted from the return value of f(n,k+1). The latter increments k and recursively calls f, thus iterating over the possible values of k. Once n < k + 1 or n = 1, f(n,k+1) will return 1, ending the recursion.


答:
Jelly, 6 bytes

```<code>:Ḋß€SC
</code>```

Try it online! or verify the smaller test cases. (takes a while)

Background

This uses the property

from A002321, which leads to the following recursive formula.

How it works

```<code>:Ḋß€SC  Main link. Argument: n

 Ḋ      Dequeue; yield [2, ..., n].
:       Perform the integer division of n by each k in [2, ..., n].
  ß€    Recursively call the main link on each result.
    S   Sum; add the results from the recursive calls.
     C  Complement; map the sum r to 1 - r.
</code>```

Title: Compute the Mertens function

Body:
Jelly, 6 bytes

:Ḋß€SC

Try it online! or verify the smaller test cases. (takes a while)

Background

This uses the property

from A002321, which leads to the following recursive formula.

How it works

:Ḋß€SC  Main link. Argument: n

 Ḋ      Dequeue; yield [2, ..., n].
:       Perform the integer division of n by each k in [2, ..., n].
  ß€    Recursively call the main link on each result.
    S   Sum; add the results from the recursive calls.
     C  Complement; map the sum r to 1 - r.