问:
Shortest infinite loop producing no output
Your task is to create the shortest infinite loop!

The point of this challenge is to create an infinite loop producing no output, unlike its possible duplicate. The reason to this is because the code might be shorter if no output is given.

Rules

Each submission must be a full program.

You must create the shortest infinite loop.

Even if your program runs out of memory eventually, it is still accepted as long as it is running the whole time from the start to when it runs out of memory. Also when it runs out of memory, it should still not print anything to STDERR.

The program must take no input (however, reading from a file is allowed), and should not print anything to STDOUT. Output to a file is also forbidden.

The program must not write anything to STDERR.

Feel free to use a language (or language version) even if it's newer than this challenge.
-Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language. :D

Submissions are scored in bytes, in an appropriate (pre-existing) encoding, usually (but not necessarily) UTF-8. Some languages, like Folders, are a bit tricky to score - if in doubt, please ask on Meta.

This is not about finding the language with the shortest infinite loop program. This is about finding the shortest infinite loop program in every language. Therefore, I will not accept an answer.

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

There should be a website such as Wikipedia, Esolangs, or GitHub for the language. For example, if the language is CJam, then one could link to the site in the header like #[CJam](http://sourceforge.net/p/cjam/wiki/Home/), X bytes.

Standard loopholes are not allowed.

(I have taken some of these rules from Martin Büttner's "Hello World" challenge)

Please feel free to post in the comments to tell me how this challenge could be  improved.

Catalogue

This is a Stack Snippet which generates both an alphabetical catalogue of the used languages, and an overall leaderboard. To make sure your answer shows up, please start it with this Markdown header:

```<code># Language name, X bytes
</code>```

Obviously replacing Language name and X bytes with the proper items. If you want to link to the languages' website, use this template, as posted above:

```<code>#[Language name](http://link.to/the/language), X bytes
</code>```

Now, finally, here's the snippet: (Try pressing "Full page" for a better view.)

var QUESTION_ID=59347;var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";var COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk";var OVERRIDE_USER=41805;var answers=[],answers_hash,answer_ids,answer_page=1,more_answers=true,comment_page;function answersUrl(index){return"//api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+index+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(index,answers){return"//api.stackexchange.com/2.2/answers/"+answers.join(';')+"/comments?page="+index+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:true,success:function(data){answers.push.apply(answers,data.items);answers_hash=[];answer_ids=[];data.items.forEach(function(a){a.comments=[];var id=+a.share_link.match(/\d+/);answer_ids.push(id);answers_hash[id]=a});if(!data.has_more)more_answers=false;comment_page=1;getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:true,success:function(data){data.items.forEach(function(c){if(c.owner.user_id===OVERRIDE_USER)answers_hash[c.post_id].comments.push(c)});if(data.has_more)getComments();else if(more_answers)getAnswers();else process()}})}getAnswers();var SCORE_REG=/<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;var OVERRIDE_REG=/^Override\s*header:\s*/i;function getAuthorName(a){return a.owner.display_name}function process(){var valid=[];answers.forEach(function(a){var body=a.body;a.comments.forEach(function(c){if(OVERRIDE_REG.test(c.body))body='
'+c.body.replace(OVERRIDE_REG,'')+'
'});var match=body.match(SCORE_REG);if(match)valid.push({user:getAuthorName(a),size:+match[2],language:match[1],link:a.share_link,});else console.log(body)});valid.sort(function(a,b){var aB=a.size,bB=b.size;return aB-bB});var languages={};var place=1;var lastSize=null;var lastPlace=1;valid.forEach(function(a){if(a.size!=lastSize)lastPlace=place;lastSize=a.size;++place;var answer=jQuery("#answer-template").html();answer=answer.replace("{{PLACE}}",lastPlace+".").replace("{{NAME}}",a.user).replace("{{LANGUAGE}}",a.language).replace("{{SIZE}}",a.size).replace("{{LINK}}",a.link);answer=jQuery(answer);jQuery("#answers").append(answer);var lang=a.language;lang=jQuery(''+lang+'').text();languages[lang]=languages[lang]||{lang:a.language,lang_raw:lang,user:a.user,size:a.size,link:a.link}});var langs=[];for(var lang in languages)if(languages.hasOwnProperty(lang))langs.push(languages[lang]);langs.sort(function(a,b){if(a.lang_raw.toLowerCase()>b.lang_raw.toLowerCase())return 1;if(a.lang_raw.toLowerCase()<b.lang_raw.toLowerCase())return-1;return 0});for(var i=0;i<langs.length;++i){var language=jQuery("#language-template").html();var lang=langs[i];language=language.replace("{{LANGUAGE}}",lang.lang).replace("{{NAME}}",lang.user).replace("{{SIZE}}",lang.size).replace("{{LINK}}",lang.link);language=jQuery(language);jQuery("#languages").append(language)}}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list{padding:10px;width:500px;float:left}#language-list{padding:10px;padding-right:40px;width:500px;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">

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
Sh, 17 bytes

```<code>while :;do :;done
</code>```

Probably the shortest one.

Ungolfed:

```<code>while [ : ]; do
:
done
</code>```

: is a command that always returns 0 (a.k.a. the same as true).

Sh+coreutils, 13 bytes

```<code>yes>/dev/null
</code>```

yes is a program from the coreutils package, that, when not given an argument, continuously outputs y  (note the newline), while given an argument, outputs that argument plus a newline continuously. --help and --version display usage and version number, respectively.

Body:
Sh, 17 bytes

while :;do :;done

Probably the shortest one.

Ungolfed:

while [ : ]; do
:
done

: is a command that always returns 0 (a.k.a. the same as true).

Sh+coreutils, 13 bytes

yes>/dev/null

yes is a program from the coreutils package, that, when not given an argument, continuously outputs y  (note the newline), while given an argument, outputs that argument plus a newline continuously. --help and --version display usage and version number, respectively.


答:
Fuzzy Octo Guacamole, 2 bytes

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

A empty infinite loop.

ContentLicense: CC BY-SA 3.0

Title: Shortest infinite loop producing no output

Body:
Your task is to create the shortest infinite loop!

The point of this challenge is to create an infinite loop producing no output, unlike its possible duplicate. The reason to this is because the code might be shorter if no output is given.

Rules

Each submission must be a full program.

You must create the shortest infinite loop.

Even if your program runs out of memory eventually, it is still accepted as long as it is running the whole time from the start to when it runs out of memory. Also when it runs out of memory, it should still not print anything to STDERR.

The program must take no input (however, reading from a file is allowed), and should not print anything to STDOUT. Output to a file is also forbidden.

The program must not write anything to STDERR.

Feel free to use a language (or language version) even if it's newer than this challenge.
-Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language. :D

Submissions are scored in bytes, in an appropriate (pre-existing) encoding, usually (but not necessarily) UTF-8. Some languages, like Folders, are a bit tricky to score - if in doubt, please ask on Meta.

This is not about finding the language with the shortest infinite loop program. This is about finding the shortest infinite loop program in every language. Therefore, I will not accept an answer.

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

There should be a website such as Wikipedia, Esolangs, or GitHub for the language. For example, if the language is CJam, then one could link to the site in the header like #[CJam](http://sourceforge.net/p/cjam/wiki/Home/), X bytes.

Standard loopholes are not allowed.

(I have taken some of these rules from Martin Büttner's "Hello World" challenge)

Please feel free to post in the comments to tell me how this challenge could be  improved.

Catalogue

This is a Stack Snippet which generates both an alphabetical catalogue of the used languages, and an overall leaderboard. To make sure your answer shows up, please start it with this Markdown header:

```<code># Language name, X bytes
</code>```

Obviously replacing Language name and X bytes with the proper items. If you want to link to the languages' website, use this template, as posted above:

```<code>#[Language name](http://link.to/the/language), X bytes
</code>```

Now, finally, here's the snippet: (Try pressing "Full page" for a better view.)

var QUESTION_ID=59347;var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";var COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk";var OVERRIDE_USER=41805;var answers=[],answers_hash,answer_ids,answer_page=1,more_answers=true,comment_page;function answersUrl(index){return"//api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+index+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(index,answers){return"//api.stackexchange.com/2.2/answers/"+answers.join(';')+"/comments?page="+index+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:true,success:function(data){answers.push.apply(answers,data.items);answers_hash=[];answer_ids=[];data.items.forEach(function(a){a.comments=[];var id=+a.share_link.match(/\d+/);answer_ids.push(id);answers_hash[id]=a});if(!data.has_more)more_answers=false;comment_page=1;getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:true,success:function(data){data.items.forEach(function(c){if(c.owner.user_id===OVERRIDE_USER)answers_hash[c.post_id].comments.push(c)});if(data.has_more)getComments();else if(more_answers)getAnswers();else process()}})}getAnswers();var SCORE_REG=/<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;var OVERRIDE_REG=/^Override\s*header:\s*/i;function getAuthorName(a){return a.owner.display_name}function process(){var valid=[];answers.forEach(function(a){var body=a.body;a.comments.forEach(function(c){if(OVERRIDE_REG.test(c.body))body='
'+c.body.replace(OVERRIDE_REG,'')+'
'});var match=body.match(SCORE_REG);if(match)valid.push({user:getAuthorName(a),size:+match[2],language:match[1],link:a.share_link,});else console.log(body)});valid.sort(function(a,b){var aB=a.size,bB=b.size;return aB-bB});var languages={};var place=1;var lastSize=null;var lastPlace=1;valid.forEach(function(a){if(a.size!=lastSize)lastPlace=place;lastSize=a.size;++place;var answer=jQuery("#answer-template").html();answer=answer.replace("{{PLACE}}",lastPlace+".").replace("{{NAME}}",a.user).replace("{{LANGUAGE}}",a.language).replace("{{SIZE}}",a.size).replace("{{LINK}}",a.link);answer=jQuery(answer);jQuery("#answers").append(answer);var lang=a.language;lang=jQuery(''+lang+'').text();languages[lang]=languages[lang]||{lang:a.language,lang_raw:lang,user:a.user,size:a.size,link:a.link}});var langs=[];for(var lang in languages)if(languages.hasOwnProperty(lang))langs.push(languages[lang]);langs.sort(function(a,b){if(a.lang_raw.toLowerCase()>b.lang_raw.toLowerCase())return 1;if(a.lang_raw.toLowerCase()<b.lang_raw.toLowerCase())return-1;return 0});for(var i=0;i<langs.length;++i){var language=jQuery("#language-template").html();var lang=langs[i];language=language.replace("{{LANGUAGE}}",lang.lang).replace("{{NAME}}",lang.user).replace("{{SIZE}}",lang.size).replace("{{LINK}}",lang.link);language=jQuery(language);jQuery("#languages").append(language)}}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list{padding:10px;width:500px;float:left}#language-list{padding:10px;padding-right:40px;width:500px;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">

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

Body:
Fuzzy Octo Guacamole, 2 bytes

()

A empty infinite loop.


问:
Is it really a comcoin?

Very interesting background

Comcoins are a currency like any other. The residents of Multibaseania (an economically robust system of city-states with very few residents in a galaxy far, far away) use Comcoins to conduct transactions between themselves. Comcoins are represented by unique codes on special not-paper slips, and when you pay you give the vendor your slip.

However, just like any currency, there are those villainous types that try to take advantage of the system and inflate the currency because they are bored.

To combat this unquestionably illegal behavior, the Multibaseanian governments came together and devised a way to prove that the money is legitimate. The top idea from the think tank was: whenever a Comcoin is given to a vendor, the vendor runs a program that checks if it is legitimate. How does one know if a Comcoin is legitimate?

A legitimate Comcoin is one where:

When the Comcoin's unique code is converted into the bases 2-10, inclusive, that number is composite (i.e. not prime). Also, all of the unique code's digits in base 10 are either 1 or 0, and its length in base 10 is between 1 and 5 inclusive.

Very important example: in base 5, 111 is 421. Even though 111 is not prime, 421 is, so the Comcoin is invalid.

The challenge

Write a function or program that takes a Comcoin's code (a number), which is in base 10 and is an integer. Then, print or return a truthy or falsy value depending on whether that Comcoin is legitimate (criteria above), respectively.

I/O examples

```<code>Input     Output

101         False // because it is prime in base 2
1010        True
10101       True
1010111     False // because it is longer than 5 digits
123         False // because it does not contain *only* 0's and 1's
10111       False // because it is prime in base 6
</code>```

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

Edit

A Comcoin is not a number that is not prime, but is a number that is composite.

Inspiration from qualification round of Google CodeJam 2016.

答:
Python 3, 222 bytes

I wanted to try to do the naive method purely functionally, without looping. Here it is.

```<code>(lambda A:all([F(A)for F in[lambda r:all(map(lambda s:not(lambda i,b:lambda n:list(filter(lambda i:not n%i,range(2,n)))(int(i,b))(r,s),range(2,11))),lambda r:0!= len(filter(lambda d:d not in"01",r)),lambda r:0<len(r)<6]]))
</code>```

Ungolfed:

```<code>(lambda A:
    all(
        [F(A) for F in [
            lambda r: all(
                map(
                    lambda s:
                        not(
                            lambda i, b:
                                lambda n:
                                    list(filter(
                                        lambda i: not n % i, range(2, n)))
                            )(int(i, b))(r, s),
                            range(2, 11))),
            lambda r: 0 != len(filter(lambda d: d not in "01", r)),
            lambda r: 0 < len(r) < 6
            ]
        ]
    )
)
</code>```

Title: Is it really a comcoin?

Body:
Python 3, 222 bytes

I wanted to try to do the naive method purely functionally, without looping. Here it is.

(lambda A:all([F(A)for F in[lambda r:all(map(lambda s:not(lambda i,b:lambda n:list(filter(lambda i:not n%i,range(2,n)))(int(i,b))(r,s),range(2,11))),lambda r:0!= len(filter(lambda d:d not in"01",r)),lambda r:0<len(r)<6]]))

Ungolfed:

(lambda A:
    all(
        [F(A) for F in [
            lambda r: all(
                map(
                    lambda s:
                        not(
                            lambda i, b:
                                lambda n:
                                    list(filter(
                                        lambda i: not n % i, range(2, n)))
                            )(int(i, b))(r, s),
                            range(2, 11))),
            lambda r: 0 != len(filter(lambda d: d not in "01", r)),
            lambda r: 0 < len(r) < 6
            ]
        ]
    )
)


问:
Implement a Truth-Machine
A truth-machine (credits goes to this guy for coming up with it) is a very simple program designed to demonstrate the I/O and control flow of a language. Here's what a truth-machine does:

Gets a number (either 0 or 1) from STDIN.

If that number is 0, print out 0 and terminate.

If that number is 1, print out 1 forever.

Challenge

Write a truth-machine as described above in your language of choice. The truth-machine must be a full program that follows these rules:

take input from STDIN or an acceptable alternative

If your language cannot take input from STDIN, it may take input from a hardcoded variable or suitable equivalent in the program

must output to STDOUT or an acceptable alternative

If your language is incapable of outputting the characters 0 or 1, byte or unary I/O is acceptable.

when the input is 1, it must continually print 1s and only stop if the program is killed or runs out of memory

the output must only be either a 0 followed by either one or no newline or space, or infinite 1s with each 1 followed by either one or no newline or space. No other output can be generated, except constant output of your language's interpreter that cannot be suppressed (such as a greeting, ANSI color codes or indentation). Your usage of newlines or spaces must be consistent: for example, if you choose to output 1 with a newline after it all 1s must have a newline after them.

if and only if your language cannot possibly terminate on an input of 0 it is acceptable for the code to enter an infinite loop in which nothing is outputted.

Since this is a catalog, languages created after this challenge are allowed to compete. Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language. Other than that, all the standard rules of code-golf must be obeyed. Submissions in most languages will be scored in bytes in an appropriate preexisting encoding (usually UTF-8).

Catalog

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

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

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

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

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

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

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

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

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
Javascript, <s>33</s> 31 chars

```<code>while(alert(x=x||+prompt()),x);
</code>```

Title: Implement a Truth-Machine

Body:
Javascript, <s>33</s> 31 chars

while(alert(x=x||+prompt()),x);


答:
Common Lisp, <s>34</s> 32 bytes

```<code>(if (= 1(read))(loop (print 1)))
</code>```

Title: Implement a Truth-Machine

Body:
A truth-machine (credits goes to this guy for coming up with it) is a very simple program designed to demonstrate the I/O and control flow of a language. Here's what a truth-machine does:

Gets a number (either 0 or 1) from STDIN.

If that number is 0, print out 0 and terminate.

If that number is 1, print out 1 forever.

Challenge

Write a truth-machine as described above in your language of choice. The truth-machine must be a full program that follows these rules:

take input from STDIN or an acceptable alternative

If your language cannot take input from STDIN, it may take input from a hardcoded variable or suitable equivalent in the program

must output to STDOUT or an acceptable alternative

If your language is incapable of outputting the characters 0 or 1, byte or unary I/O is acceptable.

when the input is 1, it must continually print 1s and only stop if the program is killed or runs out of memory

the output must only be either a 0 followed by either one or no newline or space, or infinite 1s with each 1 followed by either one or no newline or space. No other output can be generated, except constant output of your language's interpreter that cannot be suppressed (such as a greeting, ANSI color codes or indentation). Your usage of newlines or spaces must be consistent: for example, if you choose to output 1 with a newline after it all 1s must have a newline after them.

if and only if your language cannot possibly terminate on an input of 0 it is acceptable for the code to enter an infinite loop in which nothing is outputted.

Since this is a catalog, languages created after this challenge are allowed to compete. Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language. Other than that, all the standard rules of code-golf must be obeyed. Submissions in most languages will be scored in bytes in an appropriate preexisting encoding (usually UTF-8).

Catalog

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

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

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

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

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

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

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

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

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

Body:
Common Lisp, <s>34</s> 32 bytes

(if (= 1(read))(loop (print 1)))


问:
Find the program that prints this integer sequence (Cops' thread)
This is the cops' thread. The robbers' thread goes here.

The last cops-and-robbers thread was already 4 months ago.

The cop's task

The cop's task is to write a program/function that takes a positive (or non-negative) integer and outputs/returns another integer.

The cop must state it if the program is intolerant towards zero.

The cop will provide at least 2 sample inputs/outputs.

For example, if I have decided to write the Fibonacci sequence, I would write this in my answer:

```
a(0) returns 0
a(3) returns 2
```

The number of examples is up to the cop's discretion.

However, the sequence must actually exist in the On-Line Encyclopedia of Integer Sequences®, so no pseudo-random number generator for you. :(

The cop can hide as many characters as is so wished.

For example, if my program is:

```<code>function a(n)
    if n>2 then
        return n
    else
        return a(n-1) + a(n-2)
    end
end
</code>```

Then I would hide these characters as I want:

```<code>function a(n)
    if ### then
        ########
    else
        ######################
    end
end
</code>```

The robber's task

is obviously to find the original source code.

However, any proposed source code that produces the same set of output also counts as valid, as long as it is also found in OEIS.

Tips for the cops

<s>The search function in the OEIS only works for consecutive terms, so if you want to hide your sequence, then just leave a hole anywhere.</s>

Apparently there is no way to hide the sequence. Put this in mind when you choose the sequence.

Your score is the number of bytes in your code.

The winner will be the submission with the lowest score that hasn't been cracked in 7 days.

Only submissions that are posted in 2016 April are eligible for the win. Submissions that are posted later than this are welcome, but cannot win.

In order to claim the win you need to reveal the full code and the OEIS sequence (after 7 days).

Your post should be formatted like this (NN is the number of characters):

Lua, 98 bytes

Output:

```<code>a(0) returns 0
a(3) returns 2
</code>```

Code (# marks unrevealed characters):

```<code>function a(n)
    if ### then
        ########
    else
        ######################
    end
end
</code>```

If the code is cracked, insert [Cracked](link to cracker) in the header.
If the submission is safe, insert "Safe" in the header and reveal the full code in your answer. Only answers that have revealed the full code will be eligible for the win.

Body:
C++, 55 bytes (Safe)

This one should be easy...

source:

bool f(int###########;##r#;r###&1#####+######r######r;}

Output:

f(1)=>0
f(2)=>1
f(3)=>1
f(4)=>0
f(5)=>1
f(6)=>0
f(7)=>1
f(8)=>0
f(9)=>0
f(10)=>0
f(11)=>1

answer

Sequence:

 A010051 (Characteristic function of primes: 1 if n is prime else 0.)

code:

 bool f(int r){int i=2;for(;r%i&&1-r;i++);return i ==r;}


问:
Find the program that prints this integer sequence (Robbers' thread)
This is the robbers' thread. The cops' thread goes here.

In the cops thread, the task was to write a program/function that takes a positive (or non-negative) integer and outputs/returns another number (not necessarily integer). The robbers task is to unscramble the code the cops used to produce this output.

The cracked code doesn't have to be identical, as long as it has the same length and any revealed characters are in the correct positions. The language must also be the same (version numbers can be different). The output must of course be identical.

No-ops can be used in robber's solution.

The winner of the robbers thread will be the user who has cracked the
most submissions by May 7th 2016. If there's a tie, the user who has cracked submissions with the longest combined code will win.

The submission should be formatted like this:

Language, nn characters (including link to answer), Cop's username

Code:

```<code>function a(n)
    if n<2 then
        return n
    else
        return a(n-1) + a(n-2)
    end
end
</code>```

Output

```<code>a(0) returns 0
a(3) returns 2
</code>```

Optional explanation and comments.

答:
Python 2 (72 bytes) by Sp3000

There's an unbelievable amount of sequences starting with 1,2,3,6,9,18 from the 1 element. I was fortunate to find one on the 3rd page where these are the only 6 terms: Divisors of 18.

```<code>print[1,#((#y
2,3,6,9,#.####c###6#####16#.
18][#)#131963
~-input()#3
]#)
</code>```

Body:
Python 2 (72 bytes) by Sp3000

There's an unbelievable amount of sequences starting with 1,2,3,6,9,18 from the 1 element. I was fortunate to find one on the 3rd page where these are the only 6 terms: Divisors of 18.

print[1,#((#y
2,3,6,9,#.####c###6#####16#.
18][#)#131963
~-input()#3
]#)


Title: Find the program that prints this integer sequence (Cops' thread)

Body:
This is the cops' thread. The robbers' thread goes here.

The last cops-and-robbers thread was already 4 months ago.

The cop's task

The cop's task is to write a program/function that takes a positive (or non-negative) integer and outputs/returns another integer.

The cop must state it if the program is intolerant towards zero.

The cop will provide at least 2 sample inputs/outputs.

For example, if I have decided to write the Fibonacci sequence, I would write this in my answer:

```
a(0) returns 0
a(3) returns 2
```

The number of examples is up to the cop's discretion.

However, the sequence must actually exist in the On-Line Encyclopedia of Integer Sequences®, so no pseudo-random number generator for you. :(

The cop can hide as many characters as is so wished.

For example, if my program is:

```<code>function a(n)
    if n>2 then
        return n
    else
        return a(n-1) + a(n-2)
    end
end
</code>```

Then I would hide these characters as I want:

```<code>function a(n)
    if ### then
        ########
    else
        ######################
    end
end
</code>```

The robber's task

is obviously to find the original source code.

However, any proposed source code that produces the same set of output also counts as valid, as long as it is also found in OEIS.

Tips for the cops

<s>The search function in the OEIS only works for consecutive terms, so if you want to hide your sequence, then just leave a hole anywhere.</s>

Apparently there is no way to hide the sequence. Put this in mind when you choose the sequence.

Your score is the number of bytes in your code.

The winner will be the submission with the lowest score that hasn't been cracked in 7 days.

Only submissions that are posted in 2016 April are eligible for the win. Submissions that are posted later than this are welcome, but cannot win.

In order to claim the win you need to reveal the full code and the OEIS sequence (after 7 days).

Your post should be formatted like this (NN is the number of characters):

Lua, 98 bytes

Output:

```<code>a(0) returns 0
a(3) returns 2
</code>```

Code (# marks unrevealed characters):

```<code>function a(n)
    if ### then
        ########
    else
        ######################
    end
end
</code>```

If the code is cracked, insert [Cracked](link to cracker) in the header.
If the submission is safe, insert "Safe" in the header and reveal the full code in your answer. Only answers that have revealed the full code will be eligible for the win.

Body:
05AB1E, 5 bytes, cracked

Output:

a(0) = 0
a(1) = 0
a(2) = 1
a(3) = 1
a(4) = 1
a(5) = 1
a(6) = 1
a(7) = 1
a(8) = 1
a(9) = 1
a(10) = 0
a(11) = 0

Obfuscated code:

_____

Try it online!-link.


答:
Pyth, 4 bytes, FliiFe, A000041

Code:

```<code>l./Q
</code>```

Explanation:

```<code> ./Q  # Calculate the paritions of Q (input)
l     # Take the length, which counts the number of partitions.
</code>```

Try it here.

Title: Find the program that prints this integer sequence (Robbers' thread)

Body:
This is the robbers' thread. The cops' thread goes here.

In the cops thread, the task was to write a program/function that takes a positive (or non-negative) integer and outputs/returns another number (not necessarily integer). The robbers task is to unscramble the code the cops used to produce this output.

The cracked code doesn't have to be identical, as long as it has the same length and any revealed characters are in the correct positions. The language must also be the same (version numbers can be different). The output must of course be identical.

No-ops can be used in robber's solution.

The winner of the robbers thread will be the user who has cracked the
most submissions by May 7th 2016. If there's a tie, the user who has cracked submissions with the longest combined code will win.

The submission should be formatted like this:

Language, nn characters (including link to answer), Cop's username

Code:

```<code>function a(n)
    if n<2 then
        return n
    else
        return a(n-1) + a(n-2)
    end
end
</code>```

Output

```<code>a(0) returns 0
a(3) returns 2
</code>```

Optional explanation and comments.

Body:
Pyth, 4 bytes, FliiFe, A000041

Code:

l./Q

Explanation:

 ./Q  # Calculate the paritions of Q (input)
l     # Take the length, which counts the number of partitions.

Try it here.


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

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

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

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

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

答:
Java 7, 158 bytes

```<code>class B{public static void main(String[]a){a('a',Byte.valueOf(a[0]));}static void a(char a,int c){if(c>=0){a(a,c-1);System.out.print((char)(a+c));a(a,c-1);}}}
</code>```

I like to lurk around PPCG and I would enjoy being able to vote/comment on other answers.

Input is given as program parameters. This follows the same format as many other answers here in that it's a straight forward recursive implementation. I would have commented on the other answer but I don't have the rep to comment yet. It's also slightly different in that the recursive call is done twice rather than building a string and passing it along.

ContentLicense: CC BY-SA 4.0

Title: Generate the Abacaba sequence

Body:
Java 7, 158 bytes

class B{public static void main(String[]a){a('a',Byte.valueOf(a[0]));}static void a(char a,int c){if(c>=0){a(a,c-1);System.out.print((char)(a+c));a(a,c-1);}}}

I like to lurk around PPCG and I would enjoy being able to vote/comment on other answers.

Input is given as program parameters. This follows the same format as many other answers here in that it's a straight forward recursive implementation. I would have commented on the other answer but I don't have the rep to comment yet. It's also slightly different in that the recursive call is done twice rather than building a string and passing it along.


问:
Draw an indexed fractal

Introduction

In this challenge, a 2×2 matrix is indexed like this:

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

We define a family of fractal-like patterns F(L), where L is a length-n list of these indices and F(L) has size 2n-1 × 2n-1.

If L == [], then F(L) is the 1×1 pattern #.

If L != [], then F(L) is constructed as follows. Let P be the pattern obtained from L with first element removed. Take four grids of size 2n-1-1 × 2n-1-1 filled with periods ., and replace the grid indexed by L[0] with the pattern P. Then, glue the grids together using one layer of hashes # between them. Here are diagrams for the four cases:

```<code>L[0]==0  L[0]==1  L[0]==2  L[0]==3
   #...  ...#     ...#...  ...#...
[P]#...  ...#[P]  ...#...  ...#...
   #...  ...#     ...#...  ...#...
#######  #######  #######  #######
...#...  ...#...     #...  ...#
...#...  ...#...  [P]#...  ...#[P]
...#...  ...#...     #...  ...#
</code>```

Example

Consider the input L = [2,0].
We begin with the 1×1 grid #, and traverse L from the right.
The rightmost element is 0, so we take four copies of the 1×1 grid ., replace the first one by #, and glue them together with hashes.
This results in the 3×3 grid

```<code>##.
###
.#.
</code>```

The next element is 2, so we take four copies of the 3×3 grid of .s, and replace the third one with the above grid.
The four grids are

```<code>...  ...  ##.  ...
...  ...  ###  ...
...  ...  .#.  ...
</code>```

and gluing them together with #s results in the 7×7 grid

```<code>...#...
...#...
...#...
#######
##.#...
####...
.#.#...
</code>```

This is our final output.

Input

Your input is a list L of the indices 0, 1, 2, 3.
You can take it as a list of integers, or a string of digits.
Note that it may be empty, and it may contain duplicates.
The length of L is at most 5.

Output

Your output is the pattern F(L) as a newline-delimited string.

Rules and scoring

You can write a full program or a function.
the lowest byte count wins, and standard loopholes are disallowed.

Test cases

```<code>[]
#

[0]
##.
###
.#.

[3]
.#.
###
.##

[2,0]
...#...
...#...
...#...
#######
##.#...
####...
.#.#...

[1,1]
...#.##
...####
...#.#.
#######
...#...
...#...
...#...

[1,2,0]
.......#...#...
.......#...#...
.......#...#...
.......########
.......###.#...
.......#####...
.......#.#.#...
###############
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......

[3,3,1]
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
###############
.......#...#...
.......#...#...
.......#...#...
.......########
.......#...#.##
.......#...####
.......#...#.#.

[0,1,2,3]
.......#...#...#...............
.......#...#...#...............
.......#...#...#...............
.......#########...............
.......#.#.#...#...............
.......#####...#...............
.......#.###...#...............
################...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
###############################
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............

[0,0,1,2,3]
.......#...#...#...............#...............................
.......#...#...#...............#...............................
.......#...#...#...............#...............................
.......#########...............#...............................
.......#.#.#...#...............#...............................
.......#####...#...............#...............................
.......#.###...#...............#...............................
################...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
################################...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
###############################################################
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
</code>```

答:
Python 3.5, 1151 bytes:

Not much of a code golf, but oh well. Will try to prune it more over time where I can.

```<code>def x(s):
 y=[''];l=['#'];k=[' ']
 for z in s[::-1]:y.append(z)
 y=y[::-1]
 for h in range(len(y)):
  if y[-1]!='':u=(int(y.pop())&3)
  else:u=y.pop()
  if len(l)<2:k.append(u);p=((2**(len(k)-1))-1);l.append((('.'*p+'#'+'.'*p+'\n')*p)+'#'*((p*2)+1)+'\n'+(('.'*p+'#'+'.'*p+'\n')*p))
  else:
   if len(l)>2:del l[0]
   p=((2**(len(k)-1))-1);a=[[_+i for i in range(p)]for _ in range(len(l[1]))if _%((p*2)+2)==0 and _!=(((p*2)+2)*(p))];b=[[_+i for i in range(p)]for _ in range(len(l[1]))if _%(int(((p*2)+2)/2))==0 and _!=(int(((p*2)+2)/2)*((p)*2))and _ not in[g for i in a for g in i]];W=[g for i in a[:len(a)-(int(len(a)/2)):1]for g in i];B=[g for i in b[:len(b)-(int(len(b)/2)):1]for g in i];C=[g for i in a[len(a)-(int(len(a)/2)):len(a):1]for g in i];T=[g for i in b[len(b)-(int(len(b)/2)):len(b):1]for g in i];f=list(l[1])
   for i in list(''.join(l[0].split())):
    if u==0:f[W[0]]=i;del W[0]
    elif u==1:f[B[0]]=i;del B[0]
    elif u==2:f[C[0]]=i;del C[0]
    elif u==3:f[T[0]]=i;del T[0]
   del l[0];k.append(u);p=((2**(len(k)-1))-1);l.append(''.join(f));l.append((('.'*p+'#'+'.'*p+'\n')*p)+'#'*((p*2)+1)+'\n'+(('.'*p+'#'+'.'*p+'\n')*p))
 print(l[-2])
</code>```

A pretty naive way to do this, but, nonetheless, currently works perfectly and, as you can see, uses no external modules/libraries. Additionally, it can take on way more than 5 items in the provided list s without losing any accuracy (that is, if your hardware can handle it). It satisfies all the requirements, and I could not be happier with what I got. :)

It can also now not only accept any number within the range 0=>3 as any of the values, but any number, period, thanks to the & bitwise operator ! You can read more about them here. Now, for instance, [4,4,1,2,3] as the input list is the same as [0,0,1,2,3].

Note: Input must be provided as a list

Ungolfed with explanation:

```<code>def x(s):
 # Create 3 lists:
 # `y` is for the values of `s` (the list provided) and an empty element for the
 # first pattern
 # `l` is reserved for the pattersn created through each item in list `y`
 # `k` is created for the value of `p` which is the main value through which the
 # pattern is created.
 y=[''];l=['#'];k=[' ']
 # Reverse s, and then add each element from `s` to `y`
 # (in addition to the empty element)
 for z in s[::-1]:
     y.append(z)
 # `y` should now equal the list created, but reversed
 # If not reversed, then, if, for instance, the input is `0,1,2` and list `y`
 # therefore contains `'',2,1,0`, the empty element will be called at the end,
 # which is NOT what we want.
 y=y[::-1]
 # The main loop; will be iterated through the length of `y` number of times
 for h in range(len(y)):
  # Here is where each element from the end of `y` is recieved as `u` for
  # use in the pattern in each iteration.
  # As you can also see, a bitwise operator (`&`) is used here so that
  # ALL numbers can be accepted. Not just those in the range `0-4`.
  # However, that will happen only if the value of y[-1] (the last elment in y) is
  # NOT ''.
  if y[-1]!='':
      u=(int(y.pop())&3)
  else:
      u=y.pop()
  # If the length of list `l` is less than 2
  # (which means it only contains `#`), then do the following:
  if len(l)<2:
      # Append `u` to `k`
      k.append(u)
      # Use the length of `k` as `n` in the operation `(2^(n-1)-1)` to get the
      # length of the dot filled part of the new pattern.
      p=((2**(len(k)-1))-1)
      # Add that pattern to the list (currently empty,
      # i.e. containing no other pattern in any other quadrant)
      l.append((('.'*p+'#'+'.'*p+'\n')*p)+'#'*((p*2)+1)+'\n'+(('.'*p+'#'+'.'*p+'\n')*p))
  # Now, if the length of l is >=2, do the following:
  else:
   # If the length of l is >2, then delete the first element in list `l`
   # (this will happen only once, when the `#` is still the first element)
   if len(l)>2:
       del l[0]
   # Again, use the length of `k` as `n` in the operation `(2^(n-1)-1)`
   # to get the length of the dot filled part of the pattern.
   p=((2**(len(k)-1))-1)
   # Create a list with all the index values of all the dot elements on the left hand
   # side of the grid l[-1], and the index value + i where i is every integer in
   # the range `0-p` (this way, it will create lists within a list, each
   # which contain `p` number of integers, which are all indexes of all the dots on
   # the very left side of the grid)
   a=[[_+i for i in range(p)]for _ in range(len(l[1]))if _%((p
      *2)+2)==0 and _!=(((p*2)+2)*(p))]
   # Create another list with all the index values of the dots using the same
   # strategy as above, but this time, those in the right half of the grid.
   b=[[_+i for i in range(p)]for _ in range(len(l[1]))if _%(int(((p*2)+2)/2))==0
      and _!=(int(((p*2)+2)/2)*((p)*2))and _ not in[g for i in a for g in i]]
   # Create 4 lists, each containing index values specific to each of the
   # 4 quadrants of the grid.
   # W is the list, based on A, containing all the indexes for the 1st quadrant of
   # the grid in l[-1] containing dots (index 0 in the grid)
   W=[g for i in a[:len(a)-(int(len(a)/2)):1]for g in i]
   # B is the list, this time based on b, containing all indexes for the 2nd
   # dot-filled quadrant of the grid l[-1] (index 1 in the grid)
   B=[g for i in b[:len(b)-(int(len(b)/2)):1]for g in i]
   # C is the list, also, like W, based on a, containg all the index values for
   # the 3rd dot-filled quadrant of the grid in l[-1] (index 2 in the grid)
   C=[g for i in a[len(a)-(int(len(a)/2)):len(a):1]for g in i]
   # T is the final list, which, also like B, is based on b, and contains all the
   # index values for the final (4th) dot-filled quadrant of the grid in l[-1]
   T=[g for i in b[len(b)-(int(len(b)/2)):len(b):1]for g in i];f=list(l[1])
   # Finally, in this `for` loop, utilize all the above lists to create the new
   # pattern, using the last two elements in list `l`, where each character of grid
   # l[-2] (the second to last element) is added to the correct index of grid l[-1]
   # based on the value of `u`
   for i in list(''.join(l[0].split())):
    if u==0:
        f[W[0]]=i
        del W[0]
    elif u==1:
        f[B[0]]=i
        del B[0]
    elif u==2:
        f[C[0]]=i
        del C[0]
    elif u==3:
        f[T[0]]=i
        del T[0]
   # Delete the very first element of `l`, as it is now not needed anymore
   del l[0]
   # Append `u` to list`k` at the end of the loop this time
   k.append(u)
   # Update the value of `p` with the new value of length(k)
   p=((2**(len(k)-1))-1)
   # Append the new patter created from the for-loop above to list `l`
   l.append(''.join(f))
   # Append a new, empty pattern to list `l` for use in the next iteration
   l.append((('.'*p+'#'+'.'*p+'\n')*p)+'#'*((p*2)+1)+'\n'+(('.'*p+'#'+'.'*p+'\n')*p))
 # When the above main loop is all finished, print out the second-to-last elment in
 # list `l` as the very last element is the new, empty grid created just in case
 # there is another iteration
 print(l[-2])
</code>```

Broader & far more visually appealing explanation:

For a broader and far more visually appealing explanation, consider the second time going through the "main"-loop in the above code, in which the input list is [0,2]. In this case, the elements in the "main" list l would be:

```<code>.#.
###
##.
</code>```

and

```<code>...#...
...#...
...#...
#######
...#...
...#...
...#...
</code>```

and list y would only contain 0. Taking advantage of Python's way of indexing the last element of grid l[-1], we can label the very left elements of the grid like so:

```<code> 0 ...#...\n 7
 8 ...#...\n 15
16 ...#...\n 23
   #######\n <- Ignore this as it is nothing but `#`s and a new line
32 ...#...\n 39
40 ...#...\n 47
48 ...#...\n 55
</code>```

What pattern do you see? Every index on the very left of the grid is a multiple of 8, and since, using the equation 2^(n-1)-1 yields the length of each segment of dots in the grid, we can do ((2^(n-1)-1)*2)+2 to find the length of the top edge of the grid as a whole (+2 to include the middle #s and the \n at the end). We can use that equation, which we will call i to find the index values of each element on the left side of a grid of any size by creating a list, and appending to the list every integer, which we will call _, in the range 0=>length of grid l[-1], such that that item is a multiple of i, AND also such that _ does NOT equal i*(2^(n-1)-1), so that we can exclude the middle segment of #s separating the top half from the lower half. But we want ALL the dot elements from the left, and not only the elements on the very left side. Well, there is a fix to that, and that would be to simply append to the list a list containing i+h where h is every integer in the range 0=>2^(n-1) each time a value from range 0=>length of grid l[-1] is added to the list, so that each time, there will be as many number of values added to the list as the length of one quadrant of dots. And that is list a.

But now, how about the dots on the right half? Well, let us look at the indexing a different way:

```<code>   0 ...# 4  ...\n 7
   8 ...# 12 ...\n 15
  16 ...# 20 ...\n 23
     #######\n <- Ignore this as it is nothing but `#`s and a new line
  32 ...# 36 ...\n 39
  40 ...# 44 ...\n 47
  48 ...# 52 ...\n 55

          ^
          |

          These are the values we are looking at now
</code>```

As you can see, the values now in the middle are those that we need, as they are the beginning of the index of every segment of dots on the right hand side of the grid. Now, what is the pattern here? Well, if it's not already obvious enough, now the middle values are all multiples of i/2! With that information, we can now create another list, b, to which the multiples of i/2 are added from the range 0=>length of grid l[-1] such that each integer from that range, which we will again call _, is NOT equal to (i/2)*(p*2) to exclude the line of #s separating the top and lower halves, AND such that _ is NOT already in list a, since we don't really need 8,16,32,etc. in list b. And now, again, we don't only want those specific indexes. We want ALL the dot characters on the right side of the grid. Well, just like we did in list a, here we can also add to list b lists of _+h where h is each integer in the range 0=>2^(n-1).

Now, we have both lists a and b packed and ready to go. How would we bring these together now? This is where lists W, T, G, and C come in. They will hold the indexes to each specific quadrant of dots in grid l[-1]. For instance, let us reserve list W as the list for all the indexes equal to quadrant 1 (index 0) of the grid. In this list, we would then add the first 2^(n-1) lists from list a, since list a contains all the indexes for dots in the left half of the grid, and then split them all up so that W now contains (2^(n-1))*(2^(n-1)) elements. We would do the same for list T, but with the difference that T would contain elements from list b, since Tis reserved for quadrant 2 (index 1). List G would be the same as list W, except it would contain the rest of the elements from list a, and list C is the same as list T, except it now contains the rest of the elements from list b. And, that's it! We now have out index values for every quadrant containing dots in the grid, all split up into four lists corresponding to each quadrant. We can now use these 4 lists (W,T,G,C) to tell the program which characters it should replace in grid l[-1] with each character from grid l[0], which is the very first element of list l. Since the value is 0 here, it would replace all the dots in the first quadrant (index 0) with grid l[0] utilizing list W.

Therefore, we finally have the following:

```<code>.#.#...
####...
##.#...
#######
...#...
...#...
...#...
</code>```

Whew! Long process, isn't it? However, it works perfectly, and, again, I could not be happier. :)

Title: Draw an indexed fractal

Body:
Python 3.5, 1151 bytes:

Not much of a code golf, but oh well. Will try to prune it more over time where I can.

def x(s):
 y=[''];l=['#'];k=[' ']
 for z in s[::-1]:y.append(z)
 y=y[::-1]
 for h in range(len(y)):
  if y[-1]!='':u=(int(y.pop())&3)
  else:u=y.pop()
  if len(l)<2:k.append(u);p=((2**(len(k)-1))-1);l.append((('.'*p+'#'+'.'*p+'\n')*p)+'#'*((p*2)+1)+'\n'+(('.'*p+'#'+'.'*p+'\n')*p))
  else:
   if len(l)>2:del l[0]
   p=((2**(len(k)-1))-1);a=[[_+i for i in range(p)]for _ in range(len(l[1]))if _%((p*2)+2)==0 and _!=(((p*2)+2)*(p))];b=[[_+i for i in range(p)]for _ in range(len(l[1]))if _%(int(((p*2)+2)/2))==0 and _!=(int(((p*2)+2)/2)*((p)*2))and _ not in[g for i in a for g in i]];W=[g for i in a[:len(a)-(int(len(a)/2)):1]for g in i];B=[g for i in b[:len(b)-(int(len(b)/2)):1]for g in i];C=[g for i in a[len(a)-(int(len(a)/2)):len(a):1]for g in i];T=[g for i in b[len(b)-(int(len(b)/2)):len(b):1]for g in i];f=list(l[1])
   for i in list(''.join(l[0].split())):
    if u==0:f[W[0]]=i;del W[0]
    elif u==1:f[B[0]]=i;del B[0]
    elif u==2:f[C[0]]=i;del C[0]
    elif u==3:f[T[0]]=i;del T[0]
   del l[0];k.append(u);p=((2**(len(k)-1))-1);l.append(''.join(f));l.append((('.'*p+'#'+'.'*p+'\n')*p)+'#'*((p*2)+1)+'\n'+(('.'*p+'#'+'.'*p+'\n')*p))
 print(l[-2])

A pretty naive way to do this, but, nonetheless, currently works perfectly and, as you can see, uses no external modules/libraries. Additionally, it can take on way more than 5 items in the provided list s without losing any accuracy (that is, if your hardware can handle it). It satisfies all the requirements, and I could not be happier with what I got. :)

It can also now not only accept any number within the range 0=>3 as any of the values, but any number, period, thanks to the & bitwise operator ! You can read more about them here. Now, for instance, [4,4,1,2,3] as the input list is the same as [0,0,1,2,3].

Note: Input must be provided as a list

Ungolfed with explanation:

def x(s):
 # Create 3 lists:
 # `y` is for the values of `s` (the list provided) and an empty element for the
 # first pattern
 # `l` is reserved for the pattersn created through each item in list `y`
 # `k` is created for the value of `p` which is the main value through which the
 # pattern is created.
 y=[''];l=['#'];k=[' ']
 # Reverse s, and then add each element from `s` to `y`
 # (in addition to the empty element)
 for z in s[::-1]:
     y.append(z)
 # `y` should now equal the list created, but reversed
 # If not reversed, then, if, for instance, the input is `0,1,2` and list `y`
 # therefore contains `'',2,1,0`, the empty element will be called at the end,
 # which is NOT what we want.
 y=y[::-1]
 # The main loop; will be iterated through the length of `y` number of times
 for h in range(len(y)):
  # Here is where each element from the end of `y` is recieved as `u` for
  # use in the pattern in each iteration.
  # As you can also see, a bitwise operator (`&`) is used here so that
  # ALL numbers can be accepted. Not just those in the range `0-4`.
  # However, that will happen only if the value of y[-1] (the last elment in y) is
  # NOT ''.
  if y[-1]!='':
      u=(int(y.pop())&3)
  else:
      u=y.pop()
  # If the length of list `l` is less than 2
  # (which means it only contains `#`), then do the following:
  if len(l)<2:
      # Append `u` to `k`
      k.append(u)
      # Use the length of `k` as `n` in the operation `(2^(n-1)-1)` to get the
      # length of the dot filled part of the new pattern.
      p=((2**(len(k)-1))-1)
      # Add that pattern to the list (currently empty,
      # i.e. containing no other pattern in any other quadrant)
      l.append((('.'*p+'#'+'.'*p+'\n')*p)+'#'*((p*2)+1)+'\n'+(('.'*p+'#'+'.'*p+'\n')*p))
  # Now, if the length of l is >=2, do the following:
  else:
   # If the length of l is >2, then delete the first element in list `l`
   # (this will happen only once, when the `#` is still the first element)
   if len(l)>2:
       del l[0]
   # Again, use the length of `k` as `n` in the operation `(2^(n-1)-1)`
   # to get the length of the dot filled part of the pattern.
   p=((2**(len(k)-1))-1)
   # Create a list with all the index values of all the dot elements on the left hand
   # side of the grid l[-1], and the index value + i where i is every integer in
   # the range `0-p` (this way, it will create lists within a list, each
   # which contain `p` number of integers, which are all indexes of all the dots on
   # the very left side of the grid)
   a=[[_+i for i in range(p)]for _ in range(len(l[1]))if _%((p
      *2)+2)==0 and _!=(((p*2)+2)*(p))]
   # Create another list with all the index values of the dots using the same
   # strategy as above, but this time, those in the right half of the grid.
   b=[[_+i for i in range(p)]for _ in range(len(l[1]))if _%(int(((p*2)+2)/2))==0
      and _!=(int(((p*2)+2)/2)*((p)*2))and _ not in[g for i in a for g in i]]
   # Create 4 lists, each containing index values specific to each of the
   # 4 quadrants of the grid.
   # W is the list, based on A, containing all the indexes for the 1st quadrant of
   # the grid in l[-1] containing dots (index 0 in the grid)
   W=[g for i in a[:len(a)-(int(len(a)/2)):1]for g in i]
   # B is the list, this time based on b, containing all indexes for the 2nd
   # dot-filled quadrant of the grid l[-1] (index 1 in the grid)
   B=[g for i in b[:len(b)-(int(len(b)/2)):1]for g in i]
   # C is the list, also, like W, based on a, containg all the index values for
   # the 3rd dot-filled quadrant of the grid in l[-1] (index 2 in the grid)
   C=[g for i in a[len(a)-(int(len(a)/2)):len(a):1]for g in i]
   # T is the final list, which, also like B, is based on b, and contains all the
   # index values for the final (4th) dot-filled quadrant of the grid in l[-1]
   T=[g for i in b[len(b)-(int(len(b)/2)):len(b):1]for g in i];f=list(l[1])
   # Finally, in this `for` loop, utilize all the above lists to create the new
   # pattern, using the last two elements in list `l`, where each character of grid
   # l[-2] (the second to last element) is added to the correct index of grid l[-1]
   # based on the value of `u`
   for i in list(''.join(l[0].split())):
    if u==0:
        f[W[0]]=i
        del W[0]
    elif u==1:
        f[B[0]]=i
        del B[0]
    elif u==2:
        f[C[0]]=i
        del C[0]
    elif u==3:
        f[T[0]]=i
        del T[0]
   # Delete the very first element of `l`, as it is now not needed anymore
   del l[0]
   # Append `u` to list`k` at the end of the loop this time
   k.append(u)
   # Update the value of `p` with the new value of length(k)
   p=((2**(len(k)-1))-1)
   # Append the new patter created from the for-loop above to list `l`
   l.append(''.join(f))
   # Append a new, empty pattern to list `l` for use in the next iteration
   l.append((('.'*p+'#'+'.'*p+'\n')*p)+'#'*((p*2)+1)+'\n'+(('.'*p+'#'+'.'*p+'\n')*p))
 # When the above main loop is all finished, print out the second-to-last elment in
 # list `l` as the very last element is the new, empty grid created just in case
 # there is another iteration
 print(l[-2])

Broader & far more visually appealing explanation:

For a broader and far more visually appealing explanation, consider the second time going through the "main"-loop in the above code, in which the input list is [0,2]. In this case, the elements in the "main" list l would be:

.#.
###
##.

and

...#...
...#...
...#...
#######
...#...
...#...
...#...

and list y would only contain 0. Taking advantage of Python's way of indexing the last element of grid l[-1], we can label the very left elements of the grid like so:

 0 ...#...\n 7
 8 ...#...\n 15
16 ...#...\n 23
   #######\n <- Ignore this as it is nothing but `#`s and a new line
32 ...#...\n 39
40 ...#...\n 47
48 ...#...\n 55

What pattern do you see? Every index on the very left of the grid is a multiple of 8, and since, using the equation 2^(n-1)-1 yields the length of each segment of dots in the grid, we can do ((2^(n-1)-1)*2)+2 to find the length of the top edge of the grid as a whole (+2 to include the middle #s and the \n at the end). We can use that equation, which we will call i to find the index values of each element on the left side of a grid of any size by creating a list, and appending to the list every integer, which we will call _, in the range 0=>length of grid l[-1], such that that item is a multiple of i, AND also such that _ does NOT equal i*(2^(n-1)-1), so that we can exclude the middle segment of #s separating the top half from the lower half. But we want ALL the dot elements from the left, and not only the elements on the very left side. Well, there is a fix to that, and that would be to simply append to the list a list containing i+h where h is every integer in the range 0=>2^(n-1) each time a value from range 0=>length of grid l[-1] is added to the list, so that each time, there will be as many number of values added to the list as the length of one quadrant of dots. And that is list a.

But now, how about the dots on the right half? Well, let us look at the indexing a different way:

   0 ...# 4  ...\n 7
   8 ...# 12 ...\n 15
  16 ...# 20 ...\n 23
     #######\n <- Ignore this as it is nothing but `#`s and a new line
  32 ...# 36 ...\n 39
  40 ...# 44 ...\n 47
  48 ...# 52 ...\n 55

          ^
          |

          These are the values we are looking at now

As you can see, the values now in the middle are those that we need, as they are the beginning of the index of every segment of dots on the right hand side of the grid. Now, what is the pattern here? Well, if it's not already obvious enough, now the middle values are all multiples of i/2! With that information, we can now create another list, b, to which the multiples of i/2 are added from the range 0=>length of grid l[-1] such that each integer from that range, which we will again call _, is NOT equal to (i/2)*(p*2) to exclude the line of #s separating the top and lower halves, AND such that _ is NOT already in list a, since we don't really need 8,16,32,etc. in list b. And now, again, we don't only want those specific indexes. We want ALL the dot characters on the right side of the grid. Well, just like we did in list a, here we can also add to list b lists of _+h where h is each integer in the range 0=>2^(n-1).

Now, we have both lists a and b packed and ready to go. How would we bring these together now? This is where lists W, T, G, and C come in. They will hold the indexes to each specific quadrant of dots in grid l[-1]. For instance, let us reserve list W as the list for all the indexes equal to quadrant 1 (index 0) of the grid. In this list, we would then add the first 2^(n-1) lists from list a, since list a contains all the indexes for dots in the left half of the grid, and then split them all up so that W now contains (2^(n-1))*(2^(n-1)) elements. We would do the same for list T, but with the difference that T would contain elements from list b, since Tis reserved for quadrant 2 (index 1). List G would be the same as list W, except it would contain the rest of the elements from list a, and list C is the same as list T, except it now contains the rest of the elements from list b. And, that's it! We now have out index values for every quadrant containing dots in the grid, all split up into four lists corresponding to each quadrant. We can now use these 4 lists (W,T,G,C) to tell the program which characters it should replace in grid l[-1] with each character from grid l[0], which is the very first element of list l. Since the value is 0 here, it would replace all the dots in the first quadrant (index 0) with grid l[0] utilizing list W.

Therefore, we finally have the following:

.#.#...
####...
##.#...
#######
...#...
...#...
...#...

Whew! Long process, isn't it? However, it works perfectly, and, again, I could not be happier. :)


问:
Print NxN spiral of ascending numbers
The numbers should be printed with leading zeroes in a field with length = (number of digits of N^2).

Input (N):

```<code>4
</code>```

Output:

```<code>01 12 11 10
02 13 16 09
03 14 15 08
04 05 06 07
</code>```

I am interested in the algorithm and the cleanliness of the implementation.
So, the white space does not count and the upper limit for N is 42.

答:
Java Solution

```<code>public static void main(String[] args) {
        int INPUT = 5;
        String[][] grid = new String[INPUT][INPUT];
        int xDirection = 0;
        int yDirection = 0;
        int flag = 1;
        for (int i = 0; i < INPUT * INPUT; i++) {
            String temp = "";
            for (int k = 0; k < (""+INPUT*INPUT).length() - ("" + (i + 1)).length(); k++) {
                temp += "" + 0;
            }
            temp += (i + 1);

            if (xDirection > INPUT-1)
                {flag=2; yDirection++; xDirection--; i--; continue;}
            else if (yDirection > INPUT -1)
                {flag=3; yDirection--; xDirection--; i--; continue;}
            else if (xDirection < 0)
                {flag=4; xDirection++; yDirection--; i--; continue;}

            if ( grid[xDirection][yDirection]==null ){
                    grid[xDirection][yDirection] = ""+temp;
            }
                else{
                if (flag ==1 ) {
                    flag=2;
                    xDirection--;
                }
                else if (flag ==2){
                    flag=3;
                    yDirection--;
                }
                else if (flag==3){
                    flag=4;
                    xDirection++;
                }
                else{
                    flag=1;
                    yDirection++;
                }
                i--;
            }
            switch(flag){
            case 1: xDirection++;break;
            case 2: yDirection++;break;
            case 3: xDirection--;break;
            case 4: yDirection--; break;
            }
        }
        for (int i = 0; i < INPUT; i++) {
            for (int k = 0; k < INPUT; k++)
                System.out.print(grid[i][k] + " ");
            System.out.println();
        }
    }
</code>```

sample output for input 10

```<code>001 036 035 034 033 032 031 030 029 028
002 037 064 063 062 061 060 059 058 027
003 038 065 084 083 082 081 080 057 026
004 039 066 085 096 095 094 079 056 025
005 040 067 086 097 100 093 078 055 024
006 041 068 087 098 099 092 077 054 023
007 042 069 088 089 090 091 076 053 022
008 043 070 071 072 073 074 075 052 021
009 044 045 046 047 048 049 050 051 020
010 011 012 013 014 015 016 017 018 019
</code>```

Title: Print NxN spiral of ascending numbers

Body:
Java Solution

public static void main(String[] args) {
        int INPUT = 5;
        String[][] grid = new String[INPUT][INPUT];
        int xDirection = 0;
        int yDirection = 0;
        int flag = 1;
        for (int i = 0; i < INPUT * INPUT; i++) {
            String temp = "";
            for (int k = 0; k < (""+INPUT*INPUT).length() - ("" + (i + 1)).length(); k++) {
                temp += "" + 0;
            }
            temp += (i + 1);

            if (xDirection > INPUT-1)
                {flag=2; yDirection++; xDirection--; i--; continue;}
            else if (yDirection > INPUT -1)
                {flag=3; yDirection--; xDirection--; i--; continue;}
            else if (xDirection < 0)
                {flag=4; xDirection++; yDirection--; i--; continue;}

            if ( grid[xDirection][yDirection]==null ){
                    grid[xDirection][yDirection] = ""+temp;
            }
                else{
                if (flag ==1 ) {
                    flag=2;
                    xDirection--;
                }
                else if (flag ==2){
                    flag=3;
                    yDirection--;
                }
                else if (flag==3){
                    flag=4;
                    xDirection++;
                }
                else{
                    flag=1;
                    yDirection++;
                }
                i--;
            }
            switch(flag){
            case 1: xDirection++;break;
            case 2: yDirection++;break;
            case 3: xDirection--;break;
            case 4: yDirection--; break;
            }
        }
        for (int i = 0; i < INPUT; i++) {
            for (int k = 0; k < INPUT; k++)
                System.out.print(grid[i][k] + " ");
            System.out.println();
        }
    }

sample output for input 10

001 036 035 034 033 032 031 030 029 028
002 037 064 063 062 061 060 059 058 027
003 038 065 084 083 082 081 080 057 026
004 039 066 085 096 095 094 079 056 025
005 040 067 086 097 100 093 078 055 024
006 041 068 087 098 099 092 077 054 023
007 042 069 088 089 090 091 076 053 022
008 043 070 071 072 073 074 075 052 021
009 044 045 046 047 048 049 050 051 020
010 011 012 013 014 015 016 017 018 019

ContentLicense: CC BY-SA 2.5


答:
Haskell, 51 bytes (Cracked)

Outputs:

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

Code:

```<code>f e=sum[#########$#####(f######=#####e####)#######]
</code>```

This defines a function named f, with # as the wildcard character.
Shouldn't bee too hard to crack.

Body:
Haskell, 51 bytes (Cracked)

Outputs:

f 0 -> 0
f 1 -> 1
f 2 -> 1
f 3 -> 0
f 4 -> 0
f 5 -> 3
f 6 -> 5

Code:

f e=sum[#########$#####(f######=#####e####)#######]

This defines a function named f, with # as the wildcard character.
Shouldn't bee too hard to crack.


答:
JavaScript (ES6), 37

<s>This should work better than the current ES6 answer</s> Now the other ES6 answer is clearly better

Edit 0 and 1 not valid, the magic number changes

n=>180006585..toString(2)['0b'+n-4]|0
```

<p><strong>Test</strong> (see below to see how the magic number is built)</p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>F=n=>180006585..toString(2)['0b'+n-4]|0

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

function test() {
  var x=+I.value
  console.log(x+' '+F(x))
}

test()

// How the mask is built

isPrime=x=>{
  if(x<=2)return x==2
  if(x%2==0)return false
  var i,q=Math.sqrt(x)
  for(i=3;i<=q;i+=2)
    if(x%i==0)return false
  return true;
}

buildMask=_=>{
  var n,m,i,p,mask=''
  for(i=1;i<32;i++)
  {
    n=+i.toString(2)
    for(p=0,b=10;b>1;--b)
    {
      m=+n.toString(b)
      p=m<2 || isPrime(m)
      if(p)
      {
        console.log('N',i,n,m,b)
        break;
      }
    }
    mask+=p?0:1
    if(!p) console.log('Y',i,n)
  }
  console.log(mask, parseInt(mask,2))
  // result
  // 0001010101110101010111010111001,180006585}
}</code>```

<input value='11111' type='number' id=I oninput='test()'>
```</code>```

Title: Is it really a comcoin?

Body:
Very interesting background

Comcoins are a currency like any other. The residents of Multibaseania (an economically robust system of city-states with very few residents in a galaxy far, far away) use Comcoins to conduct transactions between themselves. Comcoins are represented by unique codes on special not-paper slips, and when you pay you give the vendor your slip.

However, just like any currency, there are those villainous types that try to take advantage of the system and inflate the currency because they are bored.

To combat this unquestionably illegal behavior, the Multibaseanian governments came together and devised a way to prove that the money is legitimate. The top idea from the think tank was: whenever a Comcoin is given to a vendor, the vendor runs a program that checks if it is legitimate. How does one know if a Comcoin is legitimate?

A legitimate Comcoin is one where:

When the Comcoin's unique code is converted into the bases 2-10, inclusive, that number is composite (i.e. not prime). Also, all of the unique code's digits in base 10 are either 1 or 0, and its length in base 10 is between 1 and 5 inclusive.

Very important example: in base 5, 111 is 421. Even though 111 is not prime, 421 is, so the Comcoin is invalid.

The challenge

Write a function or program that takes a Comcoin's code (a number), which is in base 10 and is an integer. Then, print or return a truthy or falsy value depending on whether that Comcoin is legitimate (criteria above), respectively.

I/O examples

```<code>Input     Output

101         False // because it is prime in base 2
1010        True
10101       True
1010111     False // because it is longer than 5 digits
123         False // because it does not contain *only* 0's and 1's
10111       False // because it is prime in base 6
</code>```

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

Edit

A Comcoin is not a number that is not prime, but is a number that is composite.

Inspiration from qualification round of Google CodeJam 2016.

Body:
JavaScript (ES6), 37

<s>This should work better than the current ES6 answer</s> Now the other ES6 answer is clearly better

Edit 0 and 1 not valid, the magic number changes

n=>180006585..toString(2)['0b'+n-4]|0

Test (see below to see how the magic number is built)

F=n=>180006585..toString(2)['0b'+n-4]|0

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

function test() {
  var x=+I.value
  console.log(x+' '+F(x))
}

test()

// How the mask is built

isPrime=x=>{
  if(x<=2)return x==2
  if(x%2==0)return false
  var i,q=Math.sqrt(x)
  for(i=3;i<=q;i+=2)
    if(x%i==0)return false
  return true;
}

buildMask=_=>{
  var n,m,i,p,mask=''
  for(i=1;i<32;i++)
  {
    n=+i.toString(2)
    for(p=0,b=10;b>1;--b)
    {
      m=+n.toString(b)
      p=m<2 || isPrime(m)
      if(p)
      {
        console.log('N',i,n,m,b)
        break;
      }
    }
    mask+=p?0:1
    if(!p) console.log('Y',i,n)
  }
  console.log(mask, parseInt(mask,2))
  // result
  // 0001010101110101010111010111001,180006585}
}

<input value='11111' type='number' id=I oninput='test()'><pre id=O></pre>


Body:
Ruby, 11 bytes, cracked

Code:

->i{######}

Output:

f(0) = 0
f(1) = 0
f(2) = 0
f(3) = 1
f(4) = 0
f(5) = 0
f(6) = 0
f(7) = 1
f(8) = 0
f(9) = 0
f(10) = 0
f(11) = 1
f(12) = 0
f(13) = 0
f(14) = 0
f(15) = 1

And so on, forming A011765. Curious to see if there's more than one way to do this in 6 bytes.


答:
Ruby, 11 bytes, histocrat, A011765

It only needs 5...

```<code>->i{i%4/3 }
</code>```

I'd like to note though that the sequence is off-by-one compared to OEIS (which specifies that the first term corresponds to A(1)).

Body:
Ruby, 11 bytes, histocrat, A011765

It only needs 5...

->i{i%4/3 }

I'd like to note though that the sequence is off-by-one compared to OEIS (which specifies that the first term corresponds to A(1)).


答:
MATL, <s>42</s> 41 bytes

```<code>'.#'4:He!XIiP"Iq@=wX*1X@WZ(l5MY(]3Lt3$)Q)
</code>```

Try it online!

Explanation

This works iteratively using a Kronecker product to extend the array in each iteration. The array is built with 0 and 1 instead of . and #, and at the end they are replaced by the appropriate characters.

There will be as many iterations as the input size. Input is processed from right to left. Iteration index starts at 1.

Using the example in the challenge, with input [2,0], the array is initiallized as

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

This corresponds to the initial 1 (#) extended by one row and one column, whose purpose will be clear later. The values in those columns are not important, as they will be overwritten; they could equally be ones:

```<code>1 1
1 1
</code>```

At each iteration, the existing array is Kronecker-multiplied by a 2×2 zero-one array that contains 1 at the position indicated by the current entry of the input, and 0 at the other entries. In the example at iteration i = 1, since the rightmost input entry is 0, the zero-one array is

```<code>1 0
0 0
</code>```

and the Kronecker product of these two arrays is

```<code> 1 1 0 0
 1 1 0 0
 0 0 0 0
 0 0 0 0
</code>```

Next, the row and column with index 2^i are filled with ones:

```<code> 1 1 0 0
 1 1 1 1
 0 1 0 0
 0 1 0 0
</code>```

The first three rows and columns constitute the result of the first iteration. As before, there are an extra row and column, which are useful for extending the array in the next iteration.

At iteration i = 2, since the current input value contains 2 the array above is Kronecker-multiplied by

```<code>0 0
1 0
</code>```

which gives

```<code> 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0
 1 1 0 0 0 0 0 0
 1 1 1 1 0 0 0 0
 0 1 0 0 0 0 0 0
 0 1 0 0 0 0 0 0
</code>```

Filling the 2^i-th row and column with ones gives

```<code> 0 0 0 1 0 0 0 0
 0 0 0 1 0 0 0 0
 0 0 0 1 0 0 0 0
 1 1 1 1 1 1 1 1
 1 1 0 1 0 0 0 0
 1 1 1 1 0 0 0 0
 0 1 0 1 0 0 0 0
 0 1 0 1 0 0 0 0
</code>```

Since this is the last iteration, the extra row and column are removed:

```<code> 0 0 0 1 0 0 0
 0 0 0 1 0 0 0
 0 0 0 1 0 0 0
 1 1 1 1 1 1 1
 1 1 0 1 0 0 0
 1 1 1 1 0 0 0
 0 1 0 1 0 0 0
</code>```

and the character substitution is done to produce the final result:

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

Detailed description of the code follows:

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

Title: Draw an indexed fractal

Body:
Introduction

In this challenge, a 2×2 matrix is indexed like this:

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

We define a family of fractal-like patterns F(L), where L is a length-n list of these indices and F(L) has size 2n-1 × 2n-1.

If L == [], then F(L) is the 1×1 pattern #.

If L != [], then F(L) is constructed as follows. Let P be the pattern obtained from L with first element removed. Take four grids of size 2n-1-1 × 2n-1-1 filled with periods ., and replace the grid indexed by L[0] with the pattern P. Then, glue the grids together using one layer of hashes # between them. Here are diagrams for the four cases:

```<code>L[0]==0  L[0]==1  L[0]==2  L[0]==3
   #...  ...#     ...#...  ...#...
[P]#...  ...#[P]  ...#...  ...#...
   #...  ...#     ...#...  ...#...
#######  #######  #######  #######
...#...  ...#...     #...  ...#
...#...  ...#...  [P]#...  ...#[P]
...#...  ...#...     #...  ...#
</code>```

Example

Consider the input L = [2,0].
We begin with the 1×1 grid #, and traverse L from the right.
The rightmost element is 0, so we take four copies of the 1×1 grid ., replace the first one by #, and glue them together with hashes.
This results in the 3×3 grid

```<code>##.
###
.#.
</code>```

The next element is 2, so we take four copies of the 3×3 grid of .s, and replace the third one with the above grid.
The four grids are

```<code>...  ...  ##.  ...
...  ...  ###  ...
...  ...  .#.  ...
</code>```

and gluing them together with #s results in the 7×7 grid

```<code>...#...
...#...
...#...
#######
##.#...
####...
.#.#...
</code>```

This is our final output.

Input

Your input is a list L of the indices 0, 1, 2, 3.
You can take it as a list of integers, or a string of digits.
Note that it may be empty, and it may contain duplicates.
The length of L is at most 5.

Output

Your output is the pattern F(L) as a newline-delimited string.

Rules and scoring

You can write a full program or a function.
the lowest byte count wins, and standard loopholes are disallowed.

Test cases

```<code>[]
#

[0]
##.
###
.#.

[3]
.#.
###
.##

[2,0]
...#...
...#...
...#...
#######
##.#...
####...
.#.#...

[1,1]
...#.##
...####
...#.#.
#######
...#...
...#...
...#...

[1,2,0]
.......#...#...
.......#...#...
.......#...#...
.......########
.......###.#...
.......#####...
.......#.#.#...
###############
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......

[3,3,1]
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
###############
.......#...#...
.......#...#...
.......#...#...
.......########
.......#...#.##
.......#...####
.......#...#.#.

[0,1,2,3]
.......#...#...#...............
.......#...#...#...............
.......#...#...#...............
.......#########...............
.......#.#.#...#...............
.......#####...#...............
.......#.###...#...............
################...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
###############################
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............

[0,0,1,2,3]
.......#...#...#...............#...............................
.......#...#...#...............#...............................
.......#...#...#...............#...............................
.......#########...............#...............................
.......#.#.#...#...............#...............................
.......#####...#...............#...............................
.......#.###...#...............#...............................
################...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
################################...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
###############################################################
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
</code>```

Body:
MATL, <s>42</s> 41 bytes

'.#'4:He!XIiP"Iq@=wX*1X@WZ(l5MY(]3Lt3$)Q)

Try it online!

Explanation

This works iteratively using a Kronecker product to extend the array in each iteration. The array is built with 0 and 1 instead of . and #, and at the end they are replaced by the appropriate characters.

There will be as many iterations as the input size. Input is processed from right to left. Iteration index starts at 1.

Using the example in the challenge, with input [2,0], the array is initiallized as

1 2
3 4

This corresponds to the initial 1 (#) extended by one row and one column, whose purpose will be clear later. The values in those columns are not important, as they will be overwritten; they could equally be ones:

1 1
1 1

At each iteration, the existing array is Kronecker-multiplied by a 2×2 zero-one array that contains 1 at the position indicated by the current entry of the input, and 0 at the other entries. In the example at iteration i = 1, since the rightmost input entry is 0, the zero-one array is

1 0
0 0

and the Kronecker product of these two arrays is

 1 1 0 0
 1 1 0 0
 0 0 0 0
 0 0 0 0

Next, the row and column with index 2^i are filled with ones:

 1 1 0 0
 1 1 1 1
 0 1 0 0
 0 1 0 0

The first three rows and columns constitute the result of the first iteration. As before, there are an extra row and column, which are useful for extending the array in the next iteration.

At iteration i = 2, since the current input value contains 2 the array above is Kronecker-multiplied by

0 0
1 0

which gives

 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0
 1 1 0 0 0 0 0 0
 1 1 1 1 0 0 0 0
 0 1 0 0 0 0 0 0
 0 1 0 0 0 0 0 0

Filling the 2^i-th row and column with ones gives

 0 0 0 1 0 0 0 0
 0 0 0 1 0 0 0 0
 0 0 0 1 0 0 0 0
 1 1 1 1 1 1 1 1
 1 1 0 1 0 0 0 0
 1 1 1 1 0 0 0 0
 0 1 0 1 0 0 0 0
 0 1 0 1 0 0 0 0

Since this is the last iteration, the extra row and column are removed:

 0 0 0 1 0 0 0
 0 0 0 1 0 0 0
 0 0 0 1 0 0 0
 1 1 1 1 1 1 1
 1 1 0 1 0 0 0
 1 1 1 1 0 0 0
 0 1 0 1 0 0 0

and the character substitution is done to produce the final result:

...#...
...#...
...#...
#######
##.#...
####...
.#.#...

Detailed description of the code follows:

'.#'      % Push this string. Will be indexed into
4:He!     % Push 2×2 array [1 2; 3 4]
XI        % Copy it into clipboard I
iP        % Input array and reverse it
"         % For each entry of the reversed input
  I       %   Push [1 2; 3 4] from clipboard I
  q       %   Subtract 1 to yield [0 1; 2 3]
  @=      %   Compare with current entry of the input. Gives 2×2 array
          %   with an entry equal to `1` and the rest `0`
  wX*     %   Swap. Kronecker product
  1       %   Push 1
  X@      %   Push iteration index, i
  W       %   Compute 2^i
  Z(      %   Write 1 into column 2^i
  l       %   Push 1
  5M      %   Push 2^i again
  Y(      %   Write 1 into row 2^i
]         % End for each
3Lt       % Push [1, -1j] (corresponding to index 1:end-1) twice
3$)       % Apply index. Removes last row and column
Q         % Add 1. Gives an array of values 1 and 2
)         % Index into initial string


问:
Primes in Different Bases
Challenge:

You are given a base 10 number.  For each base from 10 counting down to base 2:

Take the original input number as a base 10 string, and remove any
digits of the number which are invalid for the base.

Interpret the resulting number string in the that base. If this gives 1 or 0, terminate the whole process.

Output or print its largest prime factor, as decimal number.

The output can be an array of the largest prime factors.

Sample cases:

Input:

```<code>987654321
</code>```

Output:

```<code>379721
10593529
1091
179
1493
293
19
7
</code>```

Alternately:

```<code>[379721,10593529,1091,179,1493,293,19,7]
</code>```

This prints the largest prime factors of \$987654321\$, \$87654321_9 = 42374116_{10}\$, \$7654321_{8} = 2054353_{10}\$, and so on until it reaches \$1_2\$, where it stops.

答:
Pyke, 19 bytes, noncompeting

(add splat_node functon)
```<code>DTAbPe
;1TtD=T`"":r
</code>```

Try it here!

Takes input in quotes, exits with an error.

Explanation (newline replaced with \n):

```<code>D                    - Duplicate the first item on the stack (And get it from input first time)
 TAb                 - Convert input to base (whatever's in T, 10 default)
    Pe               - get the highest prime factor of the number
      \n;1           - print it out and get rid of it
          TtD=T      - T -= 1
               `"":  - input = input.replace(str(t), "")
                   r - GOTO start
</code>```

Title: Primes in Different Bases

Body:
Pyke, 19 bytes, noncompeting

(add splat_node functon)

DTAbPe
;1TtD=T`"":r

Try it here!

Takes input in quotes, exits with an error.

Explanation (newline replaced with \n):

D                    - Duplicate the first item on the stack (And get it from input first time)
 TAb                 - Convert input to base (whatever's in T, 10 default)
    Pe               - get the highest prime factor of the number
      \n;1           - print it out and get rid of it
          TtD=T      - T -= 1
               `"":  - input = input.replace(str(t), "")
                   r - GOTO start


答:
Python, 123 bytes, Cracked

Probably not winning any prizes, but fun nonetheless.

# marks a hidden character, it is not used anywhere in the code.

```<code>def #(#):
 if n<2:
  return n
 else:
  return #(n-1)+#(n-2)

def g(n):
 ######:
  return n
 else:
  return (#(n##)+#(##2))###
</code>```

Sample cases:

```<code>g(1) -> 1
g(6) -> 8
g(10) -> 7
</code>```

My sequence was A089911, Fibonacci Numbers mod 12.

Original code:

```<code>def f(n):
 if n<2:
  return n
 else:
  return f(n-1)+f(n-2)

def g(n):
 if n<2:
  return n
 else:
  return (f(n-1)+f(n-2))%12
</code>```

Body:
Python, 123 bytes, Cracked

Probably not winning any prizes, but fun nonetheless.

# marks a hidden character, it is not used anywhere in the code.

def #(#):
 if n<2:
  return n
 else:
  return #(n-1)+#(n-2)

def g(n):
 ######:
  return n
 else:
  return (#(n##)+#(##2))###

Sample cases:

g(1) -> 1
g(6) -> 8
g(10) -> 7

My sequence was A089911, Fibonacci Numbers mod 12.

Original code:

def f(n):
 if n<2:
  return n
 else:
  return f(n-1)+f(n-2)

def g(n):
 if n<2:
  return n
 else:
  return (f(n-1)+f(n-2))%12


问:
Convert phrases to reverse style

The Challenge

Convert a phrase of two words to reverse style: candy bar -> bar le candy.

Specifications

There will be one word (only a-zA-Z0-9 + -), a space (), and then another word.

For equal length, score is used to determine winner.

Test cases:

```<code>candy bar -> bar le candy
code golf -> golf le code
programming puzzles -> puzzles le programming
</code>```

答:
Python, 37 bytes

```<code>lambda s:" le ".join(s.split()[::-1])
</code>```

Title: Convert phrases to reverse style

Body:
Python, 37 bytes

lambda s:" le ".join(s.split()[::-1])