答:
Perl + curl + feh, <s>86</s> <s>84</s> 75 bytes

```<code>`curl xkcd.com/$_/`=~/<img src="(.*)" title="(.*?)"/;$_=$2;`feh "http:$1"`
</code>```

Requires the -p switch. I have accounted for this in the byte count.

Title: Display an xkcd

Body:
xkcd is everyone's favorite webcomic, and you will be writing a program that will bring a little bit more humor to us all.

Your objective in this challenge is to write a program which will take a number as input and display that xkcd and its title-text (mousover text).

Input

Your program will take a positive integer as input (not necessarily one for which there exists a valid comic) and display that xkcd: for example, an input of 1500 should display the comic "Upside-Down Map" at xkcd.com/1500, and then either print its title-text to the console or display it with the image.

Due to their proximity across the channel, there's long been tension between North Korea and the United Kingdom of Great Britain and Southern Ireland.

Test case 2, for n=859:

<img src="https://i.stack.imgur.com/ItL7a.png" alt="Brains aside, I wonder how many poorly-written xkcd.com-parsing scripts will break on this title (or ;;"''{<<[' this mouseover text."">

Brains aside, I wonder how many poorly-written xkcd.com-parsing scripts will break on this title (or ;;"''{<<[' this mouseover text."

Your program should also be able to function without any input, and perform the same task for the most recent xkcd found at xkcd.com, and it should always display the most recent one even when a new one goes up.

You do not have to get the image directly from xkcd.com, you can use another database as long as it is up-to-date and already existed before this challenge went up. URL shortners, that is, urls with no purpose other than redirecting to somewhere else, are not allowed.

You may display the image in any way you chose, including in a browser. You may not, however, directly display part of another page in an iframe or similar. CLARIFICATION: you cannot open a preexisting webpage, if you wish to use the browser you have to create a new page. You must also actually display an image - outputting an image file is not allowed.

You can handle the case that there isn't an image for a particular comic (e.g. it is interactive or the program was passed a number greater than the amount of comics that have been released) in any reasonable way you wish, including throwing an exception, or printing out an at least single-character string, as long as it somehow signifies to the user that there isn't an image for that input.

You can only display an image and output its title-text, or output an error message for an invalid comic. Other output is not allowed.

This is a code-golf challenge, so the fewest bytes wins.

Body:
Perl + curl + feh, <s>86</s> <s>84</s> 75 bytes

`curl xkcd.com/$_/`=~/<img src="(.*)" title="(.*?)"/;$_=$2;`feh "http:$1"`

Requires the -p switch. I have accounted for this in the byte count.


问:
Print the digital root
This is different from My Word can beat up your Word as it is less complex and only requires you to calculate it, and not compare them.

To find the digital root, take all of the digits of a number, add them, and repeat until you get a one-digit number. For example, if the number was 12345, you would add 1, 2, 3, 4, and 5, getting 15. You would then add 1 and 5, giving you 6.

Your task

Given an integer N (0 <= N <= 10000) through STDIN, print the digital root of N.

Test cases

```<code>1 -> 1
45 -> 9
341 -> 8
6801 -> 6
59613 -> 6
495106 -> 7
</code>```

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

答:
Haskell, <s>35</s> 34 bytes

until(<10)$sum.map(read.pure).show
```
<p>Try it on Ideone.</p>
<p><strong>Explanation:</strong></p>
<pre class="lang-haskell prettyprint-override"><code>until(<10)$sum.map(read.pure).show
                              show  -- convert int to string
               map(         ).      -- turn each char (digit) into
                        pure        --    a string
                   read.            --    and then a number
           sum.                     -- sum up the list of numbers
until(<10)$                         -- repeat until the result is < 10
</code>```

ContentLicense: CC BY-SA 3.0

Title: Print the digital root

Body:
Haskell, <s>35</s> 34 bytes

until(<10)$sum.map(read.pure).show

Try it on Ideone.

Explanation:

until(<10)$sum.map(read.pure).show
                              show  -- convert int to string
               map(         ).      -- turn each char (digit) into
                        pure        --    a string
                   read.            --    and then a number
           sum.                     -- sum up the list of numbers
until(<10)$                         -- repeat until the result is < 10


答:
Haskell, <s>101</s> 100 bytes

Thanks to @nimi for a byte.

```<code>f n=take(n+2).show$sum[1/16^k*(4/(l+1)-2/(l+4)-1/(l+5)-1/(l+6))|k<-[0..100+n],l<-[8*fromIntegral k]]
</code>```

Straightforward implementation. Calculates n up to 15 digits (standard double precision).

Title: Bailey–Borwein–Plouffe Iterations

Body:
Bailey–Borwein–Plouffe Iterations

We've seen a few pi challenges on PPCG, but none that specifically dictate the algorithm you should be using. I'd like to see implementations of the Bailey–Borwein–Plouffe algorithm in any language up to iteration n. The formula is as follows:

Your algorithm should output each iteration up to n, showing intermediate sums as well as the final result to form a "piangle". You may also use the reduced polynomial form of the algorithm shown on the wikipedia page. An example run for n=50 is shown below:

```<code>3
3.1
3.14
3.141
3.1415
3.14159
3.141592
3.1415926
3.14159265
3.141592653
3.1415926535
3.14159265358
3.141592653589
3.1415926535897
3.14159265358979
3.141592653589793
3.1415926535897932
3.14159265358979323
3.141592653589793238
3.1415926535897932384
3.14159265358979323846
3.141592653589793238462
3.1415926535897932384626
3.14159265358979323846264
3.141592653589793238462643
3.1415926535897932384626433
3.14159265358979323846264338
3.141592653589793238462643383
3.1415926535897932384626433832
3.14159265358979323846264338327
3.141592653589793238462643383279
3.1415926535897932384626433832795
3.14159265358979323846264338327950
3.141592653589793238462643383279502
3.1415926535897932384626433832795028
3.14159265358979323846264338327950288
3.141592653589793238462643383279502884
3.1415926535897932384626433832795028841
3.14159265358979323846264338327950288419
3.141592653589793238462643383279502884197
3.1415926535897932384626433832795028841971
3.14159265358979323846264338327950288419716
3.141592653589793238462643383279502884197169
3.1415926535897932384626433832795028841971693
3.14159265358979323846264338327950288419716939
3.141592653589793238462643383279502884197169399
3.1415926535897932384626433832795028841971693993
3.14159265358979323846264338327950288419716939937
3.141592653589793238462643383279502884197169399375
3.1415926535897932384626433832795028841971693993751
3.14159265358979323846264338327950288419716939937510
</code>```

The precision of each iteration should equal the n that is passed to the algorithm, that is to say that each iteration should calculate pi up to the passed n for all k.

Rules:

Built-ins are not allowed, nor is pi, you must use the formula.

You must support n up to a maximum that your language allows in terms of the calculation of 16^n. If the input is causing an arithmetic overflow during calculation after x<n executions because your language only supports decimals up to 2^32-1, this is fine. Any other assumptions on n are not fine.

You MUST provide an explanation of how you got the output if it is not obvious. For instance, if you're posting in a Golfing language a break-down is 100% required. This is to ensure you're using the algorithm that is specified.

Standard loop-holes are disallowed.

This is code-golf, lowest byte count wins here.

Reference Code (Code used to Generate Example):

```<code>public static void main(String[] args) {
    (0..50).each {
        n->
        def x=(0..n).collect {
            j->
            def k=new BigDecimal(j)
            def s={it.setScale(n)}
            def a=s(1.0g).divide(s(16.0g)**s(k))
            def b=s(4.0g)/(s(8.0g)*s(k)+s(1.0g))
            def c=s(2.0g)/(s(8.0g)*s(k)+s(4.0g))
            def d=s(1.0g)/(s(8.0g)*s(k)+s(5.0g))
            def e=s(1.0g)/(s(8.0g)*s(k)+s(6.0g))
            def f=a*(b-c-d-e)
        }.sum()
        println(n + "\t" + x.setScale(n, BigDecimal.ROUND_DOWN))
    }
}
</code>```

This implementation caps out at n=255, you may cap out at less or more.

This implementation was done in Groovy.

Body:
Haskell, <s>101</s> 100 bytes

Thanks to @nimi for a byte.

f n=take(n+2).show$sum[1/16^k*(4/(l+1)-2/(l+4)-1/(l+5)-1/(l+6))|k<-[0..100+n],l<-[8*fromIntegral k]]

Straightforward implementation. Calculates n up to 15 digits (standard double precision).


Title: Bailey–Borwein–Plouffe Iterations

Body:
Python 2, 174 Bytes

Man, this is a time when I wish that Python had some easier way of keeping infinite precision for decimals.. Possibly implementing your own infite accuracy type for this challenge is shorter but I can't imagine how. The formula is written verbatim.

from decimal import*
n=input();d=Decimal;getcontext().prec=n+2;p=d(0)
for i in range(n+1):f=8.*i;p+=d(16**(-i))*(4/d(f+1)-2/d(f+4)-1/d(f+5)-1/d(f+6));print str(p)[:-~i+(i>0)]

Example output for n=100 (with some added line numbers):

3
3.1
3.14
3.141
3.1415
3.14159
3.141592
3.1415926
3.14159265
3.141592653
3.1415926535
3.14159265358
3.141592653589
3.1415926535897
3.14159265358979
3.141592653589793
3.1415926535897932
3.14159265358979323
3.141592653589793238
3.1415926535897932384
3.14159265358979323846
3.141592653589793238462
3.1415926535897932384626
3.14159265358979323846264
3.141592653589793238462643
3.1415926535897932384626433
3.14159265358979323846264338
3.141592653589793238462643383
3.1415926535897932384626433832
3.14159265358979323846264338327
3.141592653589793238462643383279
3.1415926535897932384626433832795
3.14159265358979323846264338327950
3.141592653589793238462643383279502
3.1415926535897932384626433832795028
3.14159265358979323846264338327950288
3.141592653589793238462643383279502884
3.1415926535897932384626433832795028841
3.14159265358979323846264338327950288419
3.141592653589793238462643383279502884197
3.1415926535897932384626433832795028841971
3.14159265358979323846264338327950288419716
3.141592653589793238462643383279502884197169
3.1415926535897932384626433832795028841971693
3.14159265358979323846264338327950288419716939
3.141592653589793238462643383279502884197169399
3.1415926535897932384626433832795028841971693993
3.14159265358979323846264338327950288419716939937
3.141592653589793238462643383279502884197169399375
3.1415926535897932384626433832795028841971693993751
3.14159265358979323846264338327950288419716939937510
3.141592653589793238462643383279502884197169399375105
3.1415926535897932384626433832795028841971693993751058
3.14159265358979323846264338327950288419716939937510582
3.141592653589793238462643383279502884197169399375105820
3.1415926535897932384626433832795028841971693993751058209
3.14159265358979323846264338327950288419716939937510582097
3.141592653589793238462643383279502884197169399375105820974
3.1415926535897932384626433832795028841971693993751058209749
3.14159265358979323846264338327950288419716939937510582097494
3.141592653589793238462643383279502884197169399375105820974944
3.1415926535897932384626433832795028841971693993751058209749445
3.14159265358979323846264338327950288419716939937510582097494459
3.141592653589793238462643383279502884197169399375105820974944592
3.1415926535897932384626433832795028841971693993751058209749445923
3.14159265358979323846264338327950288419716939937510582097494459230
3.141592653589793238462643383279502884197169399375105820974944592307
3.1415926535897932384626433832795028841971693993751058209749445923078
3.14159265358979323846264338327950288419716939937510582097494459230781
3.141592653589793238462643383279502884197169399375105820974944592307816
3.1415926535897932384626433832795028841971693993751058209749445923078164
3.14159265358979323846264338327950288419716939937510582097494459230781640
3.141592653589793238462643383279502884197169399375105820974944592307816406
3.1415926535897932384626433832795028841971693993751058209749445923078164062
3.14159265358979323846264338327950288419716939937510582097494459230781640628
3.141592653589793238462643383279502884197169399375105820974944592307816406286
3.1415926535897932384626433832795028841971693993751058209749445923078164062862
3.14159265358979323846264338327950288419716939937510582097494459230781640628620
3.141592653589793238462643383279502884197169399375105820974944592307816406286208
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679

This does seem to work for larger numbers, n=1000 runs in a couple seconds and n=10000 doesn't seem to have given me any errors yet!


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

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

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

Your program has to do the following:

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

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

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

A few explanations:

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

```<code>"trick"

"Treat"

"    TReAt"

"
     tRICk          "
</code>```

Invalid outputs:

```<code>"tri ck"

"tr
eat"

"trck"
</code>```

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

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

Leaderboards

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

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

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

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

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

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

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

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

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

var QUESTION_ID=97472,OVERRIDE_USER=23417;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i,TAGS_REG = /(<([^>]+)>)/ig;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:400px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
Dart, Dart2JS, 49 bytes

main(){print(identical(1,1.0)?"Treat":"Trick");}

running by
dart gives:

```<code>$ dart web/test.dart
Trick
</code>```

for compiled version:

```<code>$ dart2js web/test.dart
$ nodejs out.js
Treat
</code>```

Title: Trick or Treat polyglot

Body:
Dart, Dart2JS, 49 bytes

main(){print(identical(1,1.0)?"Treat":"Trick");}

running by
dart gives:

$ dart web/test.dart
Trick

for compiled version:

$ dart2js web/test.dart
$ nodejs out.js
Treat


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

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

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

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

Test cases:

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

Or as CSV:

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

Leaderboard

var QUESTION_ID=84260,OVERRIDE_USER=8478;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
awk, 14 bytes

```<code>{print $1+$2}
</code>```

I am not sure if this is acceptable because the arguments must be passed through a pipe using echo, or through the stdin stream in a file like so:

```<code>[user@localhost ~]$ echo '15 6' | awk -E add.awk
21
[user@localhost ~]$ echo '15 6' > numbers
[user@localhost ~]$ awk -E add.awk < numbers
21
</code>```

Permissible or not, I am excited to take my first swing at code golf!

Title: Add two numbers

Body:
awk, 14 bytes

{print $1+$2}

I am not sure if this is acceptable because the arguments must be passed through a pipe using echo, or through the stdin stream in a file like so:

[user@localhost ~]$ echo '15 6' | awk -E add.awk
21
[user@localhost ~]$ echo '15 6' > numbers
[user@localhost ~]$ awk -E add.awk < numbers
21

Permissible or not, I am excited to take my first swing at code golf!


问:
Yes, of course I'm an adult!
I think we've all done this as a kid: some websites require a minimum age of 18, so we just subtract a few years from the year of birth and voilà, we 'are' 18+.

In addition, for most rides at amusement parks the minimum height to enter is 1.40 meters (here in The Netherlands it as at least). Of course this can be cheated less easily than age, but you could wear shoes with thick heels, put your hair up, wear a hat, stand on your toes, etc.

Input:

Your program/function accepts a positive integer or decimal.

Output:

Is the input an integer >= 18? Simply print the input.

Is the input an integer 0-17? Print 18.

Is the input a decimal >= 1.4? Simply print the input.

Is the input a decimal 0.0-1.4? Print 1.4.

Challenge rules:

Assume the input will always be in the range of 0-122 (oldest woman ever was 122) or 0.0-2.72 (tallest man ever was 2.72).

You are allowed to take the input as a String, object, or anything else you prefer.

The decimal inputs will never have more than three decimal places after the decimal point.

2 or 2. both aren't valid outputs for 2.0. You are free to output 2.00 or 2.000 instead of 2.0 however.

Just like the input the output will never have more than three decimal places after the point.

General rules:

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

Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.

Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.

Default Loopholes are forbidden.

If possible, please add a link with a test for your code.

Also, please add an explanation if necessary.

Test cases:

```<code>0      ->  18
1      ->  18
2      ->  18
12     ->  18
18     ->  18
43     ->  43
115    ->  115
122    ->  122

0.0    ->  1.4
1.04   ->  1.4
1.225  ->  1.4
1.399  ->  1.4
1.4    ->  1.4
1.74   ->  1.74
2.0    ->  2.0
2.72   ->  2.72
</code>```

答:
C++14, 52 bytes

As unnamed lambda:

[](auto t){auto l=sizeof t-4?1.4:18;return t<l?l:t;}
```
<p>Assumes <code>sizeof int==4</code> and <code>sizeof double!=4</code> which is true on most systems. Only side effect: the returned value is always a double.</p>
<p>Usage:</p>
<pre class="lang-c++ prettyprint-override"><code>//assign to variable
auto f=[](auto t){auto l=sizeof t-4?1.4:18;return t<l?l:t;};
f(10)
f(2.0)

//use directly
[](auto t){auto l=sizeof t-4?1.4:18;return t<l?l:t;}(10);
[](auto t){auto l=sizeof t-4?1.4:18;return t<l?l:t;}(2.0);
</code>```

Title: Yes, of course I'm an adult!

Body:
C++14, 52 bytes

As unnamed lambda:

[](auto t){auto l=sizeof t-4?1.4:18;return t<l?l:t;}

Assumes sizeof int==4 and sizeof double!=4 which is true on most systems. Only side effect: the returned value is always a double.

Usage:

//assign to variable
auto f=[](auto t){auto l=sizeof t-4?1.4:18;return t<l?l:t;};
f(10)
f(2.0)

//use directly
[](auto t){auto l=sizeof t-4?1.4:18;return t<l?l:t;}(10);
[](auto t){auto l=sizeof t-4?1.4:18;return t<l?l:t;}(2.0);


答:
05AB1E, <s>63</s> <s>52</s> 50 bytes

Specialization formula

```<code>Îƒ0NU62201122vyÍ¹Ì°*8X*N>+÷+}16Xm÷+DX>£X__iÀ'.ìÁ},
</code>```

Try it online!

BBP formula

```<code>ƒ4¹>°UX*8N*©>÷YX*®4+÷-1X*®5+÷-1X*®6+÷-1X*16Nm÷*ODN>£N__iÀ'.ìÁ},
</code>```

Try it online!

Title: Bailey–Borwein–Plouffe Iterations

Body:
05AB1E, <s>63</s> <s>52</s> 50 bytes

Specialization formula

Îƒ0NU62201122vyÍ¹Ì°*8X*N>+÷+}16Xm÷+DX>£X__iÀ'.ìÁ},

Try it online!

BBP formula

ƒ4¹>°UX*8N*©>÷YX*®4+÷-1X*®5+÷-1X*®6+÷-1X*16Nm÷*ODN>£N__iÀ'.ìÁ},

Try it online!


问:
The Last Monday
Monday, October 31st, is Halloween. And it got me thinking -- I wonder what other months have the last day of the month also be a Monday?

Input

A positive integer in any convenient format representing a year, 10000 > y > 0.

The input can be padded with zeros (e.g., 0025 for year 25) if
required.

Output

A list of the months of that year where the last day of the month is a Monday.

This can be as month names (e.g., January, March, October), or shortnames (Jan, Mar, Oct), or numbers (1, 3, 10), as separate lines or a list or delimited, etc., just so long as it's unambiguous to the reader.

The output format must be consistent:

For all years input (meaning, you can't output month names for some inputs, and month numbers for other inputs)

As well as consistent per output (meaning, you can't output 1 for January in the same output as Jul for July)

Basically, pick one format and stick to it.

Rules

Assume the Gregorian calendar for input/output, even down to y = 1.

Leap years must be properly accounted for (as a reminder: every year divisible by 4, except not years divisible by 100, unless also divisible by 400 -- 1700, 1800, 1900 all weren't leap years, but 2000 was).

You may use any built-ins or other date calculation tools you like.

Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.

Standard loopholes are forbidden.

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

Examples

```<code>   1 --> Apr, Dec
 297 --> May
1776 --> Sep
2000 --> Jan, Jul
2016 --> Feb, Oct
3385 --> Jan, Feb, Oct
</code>```

Leaderboard

var QUESTION_ID=97585,OVERRIDE_USER=42963;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
PHP, 109 bytes

```<code>$y=$argv[1];for($i;++$i<13;)echo(date('N',strtotime($y."-$i-".date('t',strtotime("$y-$i-1"))))==1?"$i ":'');
</code>```

The code produces a notice due to for($i; but the question mentions nothing about avoiding errors.

Outputs months numbers separated by a space.

```
   1 --> 1 12
 297 --> 5
1776 --> 9
2000 --> 1 7
2016 --> 2 10
3385 --> 1 2 10
```

Works in PHP 5.2.16 and onward at http://sandbox.onlinephpfunctions.com/

Title: The Last Monday

Body:
PHP, 109 bytes

$y=$argv[1];for($i;++$i<13;)echo(date('N',strtotime($y."-$i-".date('t',strtotime("$y-$i-1"))))==1?"$i ":'');

The code produces a notice due to for($i; but the question mentions nothing about avoiding errors.

Outputs months numbers separated by a space.

   1 --> 1 12
 297 --> 5
1776 --> 9
2000 --> 1 7
2016 --> 2 10
3385 --> 1 2 10

Works in PHP 5.2.16 and onward at http://sandbox.onlinephpfunctions.com/


问:
Write a Semiquine
Suppose you have 2 languages, A and B. A string s is a semiquine in A and B if it satisfies the following conditions:

s is a quine in language A.

s is a polyglot in A and B.

The output of running s as a B program is a different string s', which is a quine in B.

The goal of this challenge is to write a semiquine in two distinct languages. This is code-golf, so shortest code wins, with earliest answer used as a tiebreaker.

Rules for Quines

Only true quines are accepted. That is, you need to print the entire source code verbatim to STDOUT, without:

reading your source code, directly or indirectly.

relying on a REPL environment which just simply evaluates and prints every expression you feed it.

relying on language features which just print out the source in certain cases.

using error messages or STDERR to write all or part of the quine. (You may write things to STDERR or produce warnings/non-fatal errors as long as STDOUT is a valid quine and the error messages are not part of it.)

Furthermore, your source code must not consist purely of literals (whether they be string literals, numeric literals, etc.) and/or NOPs. For example, `12 is a polyglot in Jelly and Pyth, but in Jelly it is a NOP and a numeric literal, so it is not valid.

Any non-suppressible output (such as copyright notices, startup/shutdown messages, or a trailing line feed) may be ignored in the output for the sake of the validity of the quine.

Rules for Polyglots

The two languages used must be distinctly different. In particular:

They must not be different versions of the same language (e.g. Python 2 vs. Python 3).

They must not be different dialects of the same language (e.g. Pascal vs. Delphi).

One language may not be a subset of the other one (e.g. C vs. C++1).

One language may not be a trivial derivative of the other (e.g. Matlab vs. Octave2, brainfuck vs boolfuck vs TinyBF vs ShadyAsFuck vs all the other trivial brainfuck derivatives).

Miscellaneous Rules

You may not accept input from STDIN (or any other source). If your chosen language must take input, then either the input must be empty (empty string, piped from /dev/null, etc.), or the output of the program must not depend on the input.

For this challenge, you must write a complete program. Requiring additional code to run the solution is not allowed (such as assigning and calling a lambda function defined in the solution).

1: Yes I know that C is not really a subset of C++. It's close enough to be considered one for the purpose of polyglots, though, so I'm counting it for this challenge.

2: Like point 1 above, though Octave is technically not 100% compatible with Matlab, it was designed to be compatible, and is close enough that allowing a Matlab/Octave polyglot would trivialize the challenge.

答:
CJam + GolfScript, 9 bytes

```<code>"0$p"
0$p
</code>```

This is a quine in CJam. In GolfScript, it outputs itself with a trailing newline, which is a quine in GolfScript.

I'm not sure whether CJam should be considered a trivial derivative of GolfScript. But I think they are quite different and at least not trivial.

Title: Write a Semiquine

Body:
CJam + GolfScript, 9 bytes

"0$p"
0$p

This is a quine in CJam. In GolfScript, it outputs itself with a trailing newline, which is a quine in GolfScript.

I'm not sure whether CJam should be considered a trivial derivative of GolfScript. But I think they are quite different and at least not trivial.


问:
Folding Numbers
Given a number determine if it is a folding number.

A folding number is a number such that if you take it binary representation and "fold" it in half,  That is take the result of XNOR multiplication of the first half of the number and the second half with it digits in reverse, you will get zero.

If the number has a odd number of digits in binary its middle digit must be 1 and is ignored when folding.

Since that might be a bit confusing I will give some examples:

178

The binary representation of 178 is

```<code>10110010
</code>```

To fold this we first split it in half

```<code>1011 0010
</code>```

We reverse the second half

```<code>1011
0100
</code>```

And we XNOR the two halves:

```<code>0000
</code>```

This is zero so this is a folding number.

1644

The binary representation of 1644 is

```<code>11001101100
</code>```

To fold this we first split it in half

```<code>11001 1 01100
</code>```

The middle bit is 1 so we throw it out.

```<code>11001 01100
</code>```

We reverse the second half

```<code>11001
00110
</code>```

And we XNOR the two halves:

```<code>00000
</code>```

This is zero so this is a folding number.

4254

The binary representation of 4254 is

```<code>1000010011110
</code>```

To fold this we first split it in half

```<code>100001 0 011110
</code>```

The middle bit is 0 so this is not a folding number.

Task

Your task is to take in a positive number and return a truthy if the number is folding and falsy if it is not.  This is code golf so try to keep the byte count down.

Test Cases

Here are the first 99 folding numbers:

```<code>[1, 2, 6, 10, 12, 22, 28, 38, 42, 52, 56, 78, 90, 108, 120, 142, 150, 170, 178, 204, 212, 232, 240, 286, 310, 346, 370, 412, 436, 472, 496, 542, 558, 598, 614, 666, 682, 722, 738, 796, 812, 852, 868, 920, 936, 976, 992, 1086, 1134, 1206, 1254, 1338, 1386, 1458, 1506, 1596, 1644, 1716, 1764, 1848, 1896, 1968, 2016, 2110, 2142, 2222, 2254, 2358, 2390, 2470, 2502, 2618, 2650, 2730, 2762, 2866, 2898, 2978, 3010, 3132, 3164, 3244, 3276, 3380, 3412, 3492, 3524, 3640, 3672, 3752, 3784, 3888, 3920, 4000, 4032, 4222, 4318, 4462, 4558]
</code>```

答:
Python 2, <s>61</s> 59 bytes

Saving two bytes for converting shifts to multiplications

m=n=input()
i=0
while m:i*=2;i+=m&1;m/=2
print(n+i+1)&(n+i)
```

Returns 0 for a folding number and anything else for non-folding. Uses the bit-twiddling approach.

Title: Folding Numbers

Body:
Python 2, <s>61</s> 59 bytes

Saving two bytes for converting shifts to multiplications

m=n=input()
i=0
while m:i*=2;i+=m&1;m/=2
print(n+i+1)&(n+i)

Returns 0 for a folding number and anything else for non-folding. Uses the bit-twiddling approach.


答:
C, <s>65</s> 63 bytes

Two bytes for converting shifts to multiplications

i,m;
f(n){
 m=n;i=0;
 while(m)i*=2,i+=m&1,m/=2;
 return(n+i+1)&(n+i);
}
```

Whitespace is already excluded from bytecount, returns 0 for a folding number and anything else for non-folding. Uses the bit-twiddling approach.

Title: Folding Numbers

Body:
Given a number determine if it is a folding number.

A folding number is a number such that if you take it binary representation and "fold" it in half,  That is take the result of XNOR multiplication of the first half of the number and the second half with it digits in reverse, you will get zero.

If the number has a odd number of digits in binary its middle digit must be 1 and is ignored when folding.

Since that might be a bit confusing I will give some examples:

178

The binary representation of 178 is

```<code>10110010
</code>```

To fold this we first split it in half

```<code>1011 0010
</code>```

We reverse the second half

```<code>1011
0100
</code>```

And we XNOR the two halves:

```<code>0000
</code>```

This is zero so this is a folding number.

1644

The binary representation of 1644 is

```<code>11001101100
</code>```

To fold this we first split it in half

```<code>11001 1 01100
</code>```

The middle bit is 1 so we throw it out.

```<code>11001 01100
</code>```

We reverse the second half

```<code>11001
00110
</code>```

And we XNOR the two halves:

```<code>00000
</code>```

This is zero so this is a folding number.

4254

The binary representation of 4254 is

```<code>1000010011110
</code>```

To fold this we first split it in half

```<code>100001 0 011110
</code>```

The middle bit is 0 so this is not a folding number.

Task

Your task is to take in a positive number and return a truthy if the number is folding and falsy if it is not.  This is code golf so try to keep the byte count down.

Test Cases

Here are the first 99 folding numbers:

```<code>[1, 2, 6, 10, 12, 22, 28, 38, 42, 52, 56, 78, 90, 108, 120, 142, 150, 170, 178, 204, 212, 232, 240, 286, 310, 346, 370, 412, 436, 472, 496, 542, 558, 598, 614, 666, 682, 722, 738, 796, 812, 852, 868, 920, 936, 976, 992, 1086, 1134, 1206, 1254, 1338, 1386, 1458, 1506, 1596, 1644, 1716, 1764, 1848, 1896, 1968, 2016, 2110, 2142, 2222, 2254, 2358, 2390, 2470, 2502, 2618, 2650, 2730, 2762, 2866, 2898, 2978, 3010, 3132, 3164, 3244, 3276, 3380, 3412, 3492, 3524, 3640, 3672, 3752, 3784, 3888, 3920, 4000, 4032, 4222, 4318, 4462, 4558]
</code>```

Body:
C, <s>65</s> 63 bytes

Two bytes for converting shifts to multiplications

i,m;
f(n){
 m=n;i=0;
 while(m)i*=2,i+=m&1,m/=2;
 return(n+i+1)&(n+i);
}

Whitespace is already excluded from bytecount, returns 0 for a folding number and anything else for non-folding. Uses the bit-twiddling approach.


问:
Display an xkcd
xkcd is everyone's favorite webcomic, and you will be writing a program that will bring a little bit more humor to us all.

Your objective in this challenge is to write a program which will take a number as input and display that xkcd and its title-text (mousover text).

Input

Your program will take a positive integer as input (not necessarily one for which there exists a valid comic) and display that xkcd: for example, an input of 1500 should display the comic "Upside-Down Map" at xkcd.com/1500, and then either print its title-text to the console or display it with the image.

Due to their proximity across the channel, there's long been tension between North Korea and the United Kingdom of Great Britain and Southern Ireland.

Test case 2, for n=859:

<img src="https://i.stack.imgur.com/ItL7a.png" alt="Brains aside, I wonder how many poorly-written xkcd.com-parsing scripts will break on this title (or ;;"''{<<[' this mouseover text."">

Brains aside, I wonder how many poorly-written xkcd.com-parsing scripts will break on this title (or ;;"''{<<[' this mouseover text."

Your program should also be able to function without any input, and perform the same task for the most recent xkcd found at xkcd.com, and it should always display the most recent one even when a new one goes up.

You do not have to get the image directly from xkcd.com, you can use another database as long as it is up-to-date and already existed before this challenge went up. URL shortners, that is, urls with no purpose other than redirecting to somewhere else, are not allowed.

You may display the image in any way you chose, including in a browser. You may not, however, directly display part of another page in an iframe or similar. CLARIFICATION: you cannot open a preexisting webpage, if you wish to use the browser you have to create a new page. You must also actually display an image - outputting an image file is not allowed.

You can handle the case that there isn't an image for a particular comic (e.g. it is interactive or the program was passed a number greater than the amount of comics that have been released) in any reasonable way you wish, including throwing an exception, or printing out an at least single-character string, as long as it somehow signifies to the user that there isn't an image for that input.

You can only display an image and output its title-text, or output an error message for an invalid comic. Other output is not allowed.

This is a code-golf challenge, so the fewest bytes wins.

答:
AutoIt, 440 bytes

Yes, it's long, but it's stable.

```<code>#include<IE.au3>
#include<GDIPlus.au3>
Func _($0='')
_GDIPlus_Startup()
$1=_IECreate('xkcd.com/'&$0)
For $3 In $1.document.images
ExitLoop $3.title<>''
Next
$4=_GDIPlus_BitmapCreateFromMemory(InetRead($3.src),1)
$6=_GDIPlus_ImageGetDimension(_GDIPlus_BitmapCreateFromHBITMAP($4))
GUICreate(ToolTip($3.title),$6[0],$6[1])
GUICtrlSendMsg(GUICtrlCreatePic('',0,0,$6[0],$6[1]),370,0,$4)
_IEQuit($1)
GUISetState()
Do
Until GUIGetMsg()=-3
EndFunc
</code>```

First of all, this doesn't use RegEx to scrape the site (because I have no time to test this on all comics), but rather uses the Internet Explorer API to iterate through the DOM's img tags until it finds one with a title text.

The binary stream is read from the image URL and rendered into a bitmap using GDIPlus. This is then displayed in a nice, auto-sized GUI with an actual tooltip to make it behave almost exactly like the website.

Here's a test case (_(859)):

)

Title: Display an xkcd

Body:
AutoIt, 440 bytes

Yes, it's long, but it's stable.

#include<IE.au3>
#include<GDIPlus.au3>
Func _($0='')
_GDIPlus_Startup()
$1=_IECreate('xkcd.com/'&$0)
For $3 In $1.document.images
ExitLoop $3.title<>''
Next
$4=_GDIPlus_BitmapCreateFromMemory(InetRead($3.src),1)
$6=_GDIPlus_ImageGetDimension(_GDIPlus_BitmapCreateFromHBITMAP($4))
GUICreate(ToolTip($3.title),$6[0],$6[1])
GUICtrlSendMsg(GUICtrlCreatePic('',0,0,$6[0],$6[1]),370,0,$4)
_IEQuit($1)
GUISetState()
Do
Until GUIGetMsg()=-3
EndFunc

First of all, this doesn't use RegEx to scrape the site (because I have no time to test this on all comics), but rather uses the Internet Explorer API to iterate through the DOM's img tags until it finds one with a title text.

The binary stream is read from the image URL and rendered into a bitmap using GDIPlus. This is then displayed in a nice, auto-sized GUI with an actual tooltip to make it behave almost exactly like the website.

Here's a test case (_(859)):

)


问:
Simplificate an array

Input

An array that can contain arrays or positive, consecutive, ascending integers. The arrays can have any number of arrays inside of them, and so on and so forth. No arrays will be empty.

Output

This array simplificated

How to simplificate an array

We will use the array, [1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]] as our example.

First, we check how deep the values are nested. Here are the depths and the numbers at those depths:

```<code>0  1
1  2 3 9
2  4 7
3  5 6
5  8
</code>```

We construct the output array by taking the numbers in the original array, grouping them by how deep they are nested, and then nesting the groups at depths of the original depths of their  elements. Arrange the numbers in ascending order and ascending depth.

So, our output is [1, [2, 3, 9], [[4, 7]], [[[5, 6]]], [[[[[8]]]]]]

Examples

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

ContentLicense: CC BY-SA 4.0

Title: Simplificate an array

Body:
JavaScript (ES6) 168 bytes

f=a=>(s=[],b=-1,k=0,a.replace(/\d+|\[|\]/g,a=>a=='['?b++:a==']'?b--:(s[b]=s[b]||[]).push(a)),'['+s.map((a,b)=>k=a&&(k?',':'')+'['.repeat(b)+a+']'.repeat(b)).join``+']')

Demo


问:
Draw an hourglass
Again inspired by a task for Programming 101 here's another challenge.

Input:

A positive integer n >= 3. (has to be odd)

Output:

n lines of asterisks, where the first line has n asterisks and every new line has two asterisks less than the line before. Until hitting 1 asterisk. From there every new line has two asterisks more than the line before until getting back to n asterisks. Spaces or something like spaces have to used to align the asterisks so that it really will look like an hourglass.

General rules:

Trailing newlines are allowed but do not have to be used.

indentation is a must.

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

Since the course is taught in C++, I'm eager to see solutions in C++.

Test case (n=5):

```<code>*****
 ***
  *
 ***
*****
</code>```

答:
Haskell, 84 bytes

```<code>f n|l<-div n 2,k<-[-l..l]=putStr$unlines[[" *"!!(fromEnum$abs x<=abs y)|x<-k]|y<-k]
</code>```

Title: Draw an hourglass

Body:
Haskell, 84 bytes

f n|l<-div n 2,k<-[-l..l]=putStr$unlines[[" *"!!(fromEnum$abs x<=abs y)|x<-k]|y<-k]


问:
Does the code terminate?
This is a code golf challenge I thought of with a mathematical bent. The challenge is to write the shortest code possible such that it is an open question whether or not the code terminates. An example of what I mean could be the following piece of python code, adapted from an anwser to this cs stackexchange question.

```<code>def is_perfect(n):
    return sum(i for i in range(1, n) if n % i == 0) == n

n = 3
while not is_perfect(n):
    n = n + 2
</code>```

Mathematicians conjecture that there are no odd perfect numbers, but it has never been proven, so no one knows if this piece of code will ever terminate. Can you come up with other pieces of code (perhaps relying on other open problems like the Collatz conjecture, or the twin primes conjecture) that are shorter, but for which it is unknown whether or not they terminate?

Edit: Some people have brought up a good additional rule - The solutions to the question should be deterministic. Although it might be even more interesting if you could find shorter solutions using nondeterminism. In this case, the rule would be to find a snippet for which the probability of termination is unknown.

答:
Python 3, 101 bytes

I know it's longer than many others, but I spent a lot of time seeing how short I could golf this.

This attempts to disprove Euler's Sum of Powers Conjecture for k=6 (there exists no positive integer solution to the Diophantine equation A^6+B^6+C^6+D^6+E^6==F^6), for which no counterexample has been found.

R=[1]
while 1:R+=[R[-1]+1];eval(("[1/("+"+%s**6"*5+"!=%%s**6)%s]"%("for %s in R "*6))%(*"ABCDEF"*2,))
```
<p><strong>In Python 2 (104 bytes):</strong></p>
<pre class="lang-python prettyprint-override"><code>R=[1]
while 1:R+=[R[-1]+1];eval(("[1/("+"+%s**6"*5+"!=%%s**6)%s]"%("for %s in R "*6))%tuple("ABCDEF"*2))
</code>```

Less golfed:

x=2
while 1:
    R=range(1,x)
    [1/(A**6+B**6+C**6+D**6+E**6!=F**6)for F in R for E in R for D in R for C in R for B in R for A in R]
    x+=1
```
<p><strong>Mathy version with no eval:</strong></p>
<pre class="lang-python prettyprint-override"><code>R=range
x=2
while 1:
    for i in R(x**6):1/(sum(map(lambda x:x**6,[1+(i%x**-~j/x**j)for j in R(6)]))-i%x-1)
    x+=1
</code>```

Alternate reference: Euler's Sum of Powers Conjecture - MathWorld

Title: Does the code terminate?

Body:
Python 3, 101 bytes

I know it's longer than many others, but I spent a lot of time seeing how short I could golf this.

This attempts to disprove Euler's Sum of Powers Conjecture for k=6 (there exists no positive integer solution to the Diophantine equation A^6+B^6+C^6+D^6+E^6==F^6), for which no counterexample has been found.

R=[1]
while 1:R+=[R[-1]+1];eval(("[1/("+"+%s**6"*5+"!=%%s**6)%s]"%("for %s in R "*6))%(*"ABCDEF"*2,))

In Python 2 (104 bytes):

R=[1]
while 1:R+=[R[-1]+1];eval(("[1/("+"+%s**6"*5+"!=%%s**6)%s]"%("for %s in R "*6))%tuple("ABCDEF"*2))

Less golfed:

x=2
while 1:
    R=range(1,x)
    [1/(A**6+B**6+C**6+D**6+E**6!=F**6)for F in R for E in R for D in R for C in R for B in R for A in R]
    x+=1

Mathy version with no eval:

R=range
x=2
while 1:
    for i in R(x**6):1/(sum(map(lambda x:x**6,[1+(i%x**-~j/x**j)for j in R(6)]))-i%x-1)
    x+=1

Alternate reference: Euler's Sum of Powers Conjecture - MathWorld


答:
Julia, 12 bytes

```<code>!n=mod1(n,9)
</code>```

or

```<code>n->mod1(n,9)
</code>```

mod1 is an alternative to mod which maps to the range [1, n] instead of [0, n).

Title: Print the digital root

Body:
This is different from My Word can beat up your Word as it is less complex and only requires you to calculate it, and not compare them.

To find the digital root, take all of the digits of a number, add them, and repeat until you get a one-digit number. For example, if the number was 12345, you would add 1, 2, 3, 4, and 5, getting 15. You would then add 1 and 5, giving you 6.

Your task

Given an integer N (0 <= N <= 10000) through STDIN, print the digital root of N.

Test cases

```<code>1 -> 1
45 -> 9
341 -> 8
6801 -> 6
59613 -> 6
495106 -> 7
</code>```

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

Body:
Julia, 12 bytes

!n=mod1(n,9)

or

n->mod1(n,9)

mod1 is an alternative to mod which maps to the range [1, n] instead of [0, n).


Title: Bailey–Borwein–Plouffe Iterations

Body:
Bailey–Borwein–Plouffe Iterations

We've seen a few pi challenges on PPCG, but none that specifically dictate the algorithm you should be using. I'd like to see implementations of the Bailey–Borwein–Plouffe algorithm in any language up to iteration n. The formula is as follows:

Your algorithm should output each iteration up to n, showing intermediate sums as well as the final result to form a "piangle". You may also use the reduced polynomial form of the algorithm shown on the wikipedia page. An example run for n=50 is shown below:

```<code>3
3.1
3.14
3.141
3.1415
3.14159
3.141592
3.1415926
3.14159265
3.141592653
3.1415926535
3.14159265358
3.141592653589
3.1415926535897
3.14159265358979
3.141592653589793
3.1415926535897932
3.14159265358979323
3.141592653589793238
3.1415926535897932384
3.14159265358979323846
3.141592653589793238462
3.1415926535897932384626
3.14159265358979323846264
3.141592653589793238462643
3.1415926535897932384626433
3.14159265358979323846264338
3.141592653589793238462643383
3.1415926535897932384626433832
3.14159265358979323846264338327
3.141592653589793238462643383279
3.1415926535897932384626433832795
3.14159265358979323846264338327950
3.141592653589793238462643383279502
3.1415926535897932384626433832795028
3.14159265358979323846264338327950288
3.141592653589793238462643383279502884
3.1415926535897932384626433832795028841
3.14159265358979323846264338327950288419
3.141592653589793238462643383279502884197
3.1415926535897932384626433832795028841971
3.14159265358979323846264338327950288419716
3.141592653589793238462643383279502884197169
3.1415926535897932384626433832795028841971693
3.14159265358979323846264338327950288419716939
3.141592653589793238462643383279502884197169399
3.1415926535897932384626433832795028841971693993
3.14159265358979323846264338327950288419716939937
3.141592653589793238462643383279502884197169399375
3.1415926535897932384626433832795028841971693993751
3.14159265358979323846264338327950288419716939937510
</code>```

The precision of each iteration should equal the n that is passed to the algorithm, that is to say that each iteration should calculate pi up to the passed n for all k.

Rules:

Built-ins are not allowed, nor is pi, you must use the formula.

You must support n up to a maximum that your language allows in terms of the calculation of 16^n. If the input is causing an arithmetic overflow during calculation after x<n executions because your language only supports decimals up to 2^32-1, this is fine. Any other assumptions on n are not fine.

You MUST provide an explanation of how you got the output if it is not obvious. For instance, if you're posting in a Golfing language a break-down is 100% required. This is to ensure you're using the algorithm that is specified.

Standard loop-holes are disallowed.

This is code-golf, lowest byte count wins here.

Reference Code (Code used to Generate Example):

```<code>public static void main(String[] args) {
    (0..50).each {
        n->
        def x=(0..n).collect {
            j->
            def k=new BigDecimal(j)
            def s={it.setScale(n)}
            def a=s(1.0g).divide(s(16.0g)**s(k))
            def b=s(4.0g)/(s(8.0g)*s(k)+s(1.0g))
            def c=s(2.0g)/(s(8.0g)*s(k)+s(4.0g))
            def d=s(1.0g)/(s(8.0g)*s(k)+s(5.0g))
            def e=s(1.0g)/(s(8.0g)*s(k)+s(6.0g))
            def f=a*(b-c-d-e)
        }.sum()
        println(n + "\t" + x.setScale(n, BigDecimal.ROUND_DOWN))
    }
}
</code>```

This implementation caps out at n=255, you may cap out at less or more.

This implementation was done in Groovy.

Body:
Python 2, <s>109</s> 108 bytes

def f(n):k=1;s=0;t=100**n;exec-~n*'s+=4*t/k-2*t/(k+3)-t/(k+4)-t/(k+5)>>k/2;print"3."[:k]+`s`[1:k/8+1];k+=8;'

Test it on Ideone.


问:
Alphabet wings!
Your task is to print this exact text:

```<code>az                                               za
abyz                                           zyba
abcxyz                                       zyxcba
abcdwxyz                                   zyxwdcba
abcdevwxyz                               zyxwvedcba
abcdefuvwxyz                           zyxwvufedcba
abcdefgtuvwxyz                       zyxwvutgfedcba
abcdefghstuvwxyz                   zyxwvutshgfedcba
abcdefghirstuvwxyz               zyxwvutsrihgfedcba
abcdefghijqrstuvwxyz           zyxwvutsrqjihgfedcba
abcdefghijkpqrstuvwxyz       zyxwvutsrqpkjihgfedcba
abcdefghijklopqrstuvwxyz   zyxwvutsrqpolkjihgfedcba
abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba
  abcdefghijklopqrstuvwxyzyxwvutsrqpolkjihgfedcba
    abcdefghijkpqrstuvwxyzyxwvutsrqpkjihgfedcba
      abcdefghijqrstuvwxyzyxwvutsrqjihgfedcba
        abcdefghirstuvwxyzyxwvutsrihgfedcba
          abcdefghstuvwxyzyxwvutshgfedcba
            abcdefgtuvwxyzyxwvutgfedcba
              abcdefuvwxyzyxwvufedcba
                abcdevwxyzyxwvedcba
                  abcdwxyzyxwdcba
                    abcxyzyxcba
                      abyzyba
                        aza
</code>```

The following are allowed:

Leaving out trailing spaces at the end of lines

Doing everything in uppercase instead of lowercase

Trailing newlines

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

答:
JavaScript (ES6), <s>215</s> 211 bytes

```<code>_=>[...Array(25)].map((_,i)=>` `.repeat(++i>13&&i*2-26)+a.slice(0,j=i>13?26-i:i)+a.slice(-j)+` `.repeat(i<13&&51-i*4)+b.slice(i>12,j)+b.slice(-j),a=`abcdefghijklmnopqrstuvwxyz`,b=[...a].reverse().join``).join`\n`
</code>```

Where \n represents the literal newline character. This just edged out my character building answer at 213 bytes:

```<code>_=>[...Array(25)].map((_,i)=>` `.repeat(51).replace(/./g,(b,j)=>(j=i<13?j<i?j+10:j<h?36+j-h:j<51-h?0:j<51-i?86-h-j:60-j:j<h-26?0:j<i?36+j-h:j<26?j+10:j<51-i?60-j:j<77-h?86-h-j:0)?j.toString(36):b,h=++i+i)).join`\n`
</code>```

Title: Alphabet wings!

Body:
JavaScript (ES6), <s>215</s> 211 bytes

_=>[...Array(25)].map((_,i)=>` `.repeat(++i>13&&i*2-26)+a.slice(0,j=i>13?26-i:i)+a.slice(-j)+` `.repeat(i<13&&51-i*4)+b.slice(i>12,j)+b.slice(-j),a=`abcdefghijklmnopqrstuvwxyz`,b=[...a].reverse().join``).join`\n`

Where \n represents the literal newline character. This just edged out my character building answer at 213 bytes:

_=>[...Array(25)].map((_,i)=>` `.repeat(51).replace(/./g,(b,j)=>(j=i<13?j<i?j+10:j<h?36+j-h:j<51-h?0:j<51-i?86-h-j:60-j:j<h-26?0:j<i?36+j-h:j<26?j+10:j<51-i?60-j:j<77-h?86-h-j:0)?j.toString(36):b,h=++i+i)).join`\n`


问:
A penny saved is a penny

...counted!

You will pass your program a variable which represents a quantity of money in dollars and/or cents and an array of coin values.  Your challenge is to output the number of possible combinations of the given array of coin values that would add up to the amount passed to the code.  If it is not possible with the coins named, the program should return 0.

Note on American numismatic terminology:

1-cent coin: penny

5-cent coin: nickel

10-cent coin: dime

25-cent coin: quarter (quarter dollar)

Example 1:

Program is passed:

```<code>12, [1, 5, 10]
</code>```

(12 cents)

Output:

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

There are 4 possible ways of combining the coins named to produce 12 cents:

12 pennies

1 nickel and 7 pennies

2 nickels and 2 pennies

1 dime and 2 pennies

Example 2:

Program is passed:

```<code>26, [1, 5, 10, 25]
</code>```

(26 cents)

Output:

```<code>13
</code>```

There are 13 possible ways of combining the coins named to produce 26 cents:

26 pennies

21 pennies and 1 nickel

16 pennies and 2 nickels

11 pennies and 3 nickels

6 pennies and 4 nickels

1 penny and 5 nickels

16 pennies and 1 dime

6 pennies and 2 dimes

11 pennies, 1 dime, and 1 nickel

6 pennies, 1 dime, and 2 nickels

1 penny, 1 dime, and 3 nickels

1 penny, 2 dimes, and 1 nickel

1 quarter and 1 penny

Example 3:

Program is passed:

```<code>19, [2, 7, 12]
</code>```

Output:

```<code>2
</code>```

There are 2 possible ways of combining the coins named to produce 19 cents:

1 12-cent coin and 1 7-cent coin

1 7-cent coin and 6 2-cent coins

Example 4:

Program is passed:

```<code>13, [2, 8, 25]
</code>```

Output:

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

There are no possible ways of combining the coins named to produce 13 cents.

This has been through the Sandbox.  Standard loopholes apply.  This is code golf, so the answer with the fewest bytes wins.

答:
Python, 120 bytes

from itertools import*
lambda t,L:[sum(map(lambda x,y:x*y,C,L))-t for C in product(range(t+1),repeat=len(L))].count(0)
```

Bruteforces through all combinations of coins up to target value (even if the smallest is not 1).

Title: A penny saved is a penny

Body:
Python, 120 bytes

from itertools import*
lambda t,L:[sum(map(lambda x,y:x*y,C,L))-t for C in product(range(t+1),repeat=len(L))].count(0)

Bruteforces through all combinations of coins up to target value (even if the smallest is not 1).


答:
PHP, 92 Bytes

```<code>for($d=new DateTime("$argv[1]-1-1");$i++<12;)$d->modify("1month")->format(w)!=2?:print"$i,";
</code>```

check 12 times 1 month after first day of a year is a tuesday. If it is then is the day before the last day in the month is a monday.

Title: The Last Monday

Body:
Monday, October 31st, is Halloween. And it got me thinking -- I wonder what other months have the last day of the month also be a Monday?

Input

A positive integer in any convenient format representing a year, 10000 > y > 0.

The input can be padded with zeros (e.g., 0025 for year 25) if
required.

Output

A list of the months of that year where the last day of the month is a Monday.

This can be as month names (e.g., January, March, October), or shortnames (Jan, Mar, Oct), or numbers (1, 3, 10), as separate lines or a list or delimited, etc., just so long as it's unambiguous to the reader.

The output format must be consistent:

For all years input (meaning, you can't output month names for some inputs, and month numbers for other inputs)

As well as consistent per output (meaning, you can't output 1 for January in the same output as Jul for July)

Basically, pick one format and stick to it.

Rules

Assume the Gregorian calendar for input/output, even down to y = 1.

Leap years must be properly accounted for (as a reminder: every year divisible by 4, except not years divisible by 100, unless also divisible by 400 -- 1700, 1800, 1900 all weren't leap years, but 2000 was).

You may use any built-ins or other date calculation tools you like.

Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.

Standard loopholes are forbidden.

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

Examples

```<code>   1 --> Apr, Dec
 297 --> May
1776 --> Sep
2000 --> Jan, Jul
2016 --> Feb, Oct
3385 --> Jan, Feb, Oct
</code>```

Leaderboard

var QUESTION_ID=97585,OVERRIDE_USER=42963;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Body:
PHP, 92 Bytes

for($d=new DateTime("$argv[1]-1-1");$i++<12;)$d->modify("1month")->format(w)!=2?:print"$i,";

check 12 times 1 month after first day of a year is a tuesday. If it is then is the day before the last day in the month is a monday.


Title: Bailey–Borwein–Plouffe Iterations

Body:
J, <s>73</s> <s>64</s> 62 bytes

(j.":"+10&^(<.@*%[)[:+/\16&^%~[:-/4 2 _1 1%1 4 5 6+/*&8)@i.@>:

This outputs each approximation to n digits as a formatted string. This uses the polynomial simplification of the formula and gets the first n digits by multiplying the sum by a power of 10, flooring it, and dividing by that same power of 10.

The input is taken as an extended integer, meaning that rationals are used when division occurs which keeps results exact.

Usage

This is the output for n = 100, showing the cumulative sums for k in [0, 100].

   f =: (j.":"+10&^(<.@*%[)[:+/\16&^%~[:-/4 2 _1 1%1 4 5 6+/*&8)@i.@>:
   f 100x
3
3.1
3.14
3.141
3.1415
3.14159
3.141592
3.1415926
3.14159265
3.141592653
3.1415926535
3.14159265358
3.141592653589
3.1415926535897
3.14159265358979
3.141592653589793
3.1415926535897932
3.14159265358979323
3.141592653589793238
3.1415926535897932384
3.14159265358979323846
3.141592653589793238462
3.1415926535897932384626
3.14159265358979323846264
3.141592653589793238462643
3.1415926535897932384626433
3.14159265358979323846264338
3.141592653589793238462643383
3.1415926535897932384626433832
3.14159265358979323846264338327
3.141592653589793238462643383279
3.1415926535897932384626433832795
3.14159265358979323846264338327950
3.141592653589793238462643383279502
3.1415926535897932384626433832795028
3.14159265358979323846264338327950288
3.141592653589793238462643383279502884
3.1415926535897932384626433832795028841
3.14159265358979323846264338327950288419
3.141592653589793238462643383279502884197
3.1415926535897932384626433832795028841971
3.14159265358979323846264338327950288419716
3.141592653589793238462643383279502884197169
3.1415926535897932384626433832795028841971693
3.14159265358979323846264338327950288419716939
3.141592653589793238462643383279502884197169399
3.1415926535897932384626433832795028841971693993
3.14159265358979323846264338327950288419716939937
3.141592653589793238462643383279502884197169399375
3.1415926535897932384626433832795028841971693993751
3.14159265358979323846264338327950288419716939937510
3.141592653589793238462643383279502884197169399375105
3.1415926535897932384626433832795028841971693993751058
3.14159265358979323846264338327950288419716939937510582
3.141592653589793238462643383279502884197169399375105820
3.1415926535897932384626433832795028841971693993751058209
3.14159265358979323846264338327950288419716939937510582097
3.141592653589793238462643383279502884197169399375105820974
3.1415926535897932384626433832795028841971693993751058209749
3.14159265358979323846264338327950288419716939937510582097494
3.141592653589793238462643383279502884197169399375105820974944
3.1415926535897932384626433832795028841971693993751058209749445
3.14159265358979323846264338327950288419716939937510582097494459
3.141592653589793238462643383279502884197169399375105820974944592
3.1415926535897932384626433832795028841971693993751058209749445923
3.14159265358979323846264338327950288419716939937510582097494459230
3.141592653589793238462643383279502884197169399375105820974944592307
3.1415926535897932384626433832795028841971693993751058209749445923078
3.14159265358979323846264338327950288419716939937510582097494459230781
3.141592653589793238462643383279502884197169399375105820974944592307816
3.1415926535897932384626433832795028841971693993751058209749445923078164
3.14159265358979323846264338327950288419716939937510582097494459230781640
3.141592653589793238462643383279502884197169399375105820974944592307816406
3.1415926535897932384626433832795028841971693993751058209749445923078164062
3.14159265358979323846264338327950288419716939937510582097494459230781640628
3.141592653589793238462643383279502884197169399375105820974944592307816406286
3.1415926535897932384626433832795028841971693993751058209749445923078164062862
3.14159265358979323846264338327950288419716939937510582097494459230781640628620
3.141592653589793238462643383279502884197169399375105820974944592307816406286208
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679

Explanation

First make the range [0, n], shown for n = 5

   i. >: 5
0 1 2 3 4 5

Multiply each by 8

   (*&8) i. >: 5
0 8 16 24 32 40

Form the addition table between [1, 4, 5, 6] and the products with 8

   (1 4 5 6+/*&8) i. >: 5
1  9 17 25 33 41
4 12 20 28 36 44
5 13 21 29 37 45
6 14 22 30 38 46

Divide each row by [4, 2, -1, 1]

   (4 2 _1 1%1 4 5 6+/*&8) i. >: 5
       4   0.444444  0.235294       0.16  0.121212   0.097561
     0.5   0.166667       0.1  0.0714286 0.0555556  0.0454545
    _0.2 _0.0769231 _0.047619 _0.0344828 _0.027027 _0.0222222
0.166667  0.0714286 0.0454545  0.0333333 0.0263158  0.0217391

Then reduce the columns from bottom-to-top using subtraction

   ([:-/4 2 _1 1%1 4 5 6+/*&8) i. >: 5
3.13333 0.129426 0.0422205 0.0207553 0.0123137 0.00814508

Divide each 16k for k in [0, n] by each result

   (16&^%~[:-/4 2 _1 1%1 4 5 6+/*&8) i. >: 5
3.13333 0.00808913 0.000164924 5.06722e_6 1.87893e_7 7.76775e_9

Find the cumulative sums

   ([:+/\16&^%~[:-/4 2 _1 1%1 4 5 6+/*&8) i. >: 5
3.13333 3.14142 3.14159 3.14159 3.14159 3.14159

Compute 10k for k in [0, n] and multiply it with each

   (10&^(*)[:+/\16&^%~[:-/4 2 _1 1%1 4 5 6+/*&8) i. >: 5
3.13333 31.4142 314.159 3141.59 31415.9 314159

Then floor each of the products

   (10&^(<.@*)[:+/\16&^%~[:-/4 2 _1 1%1 4 5 6+/*&8) i. >: 5
3 31 314 3141 31415 314159

Divide it by the same power of 10 to get the results

   (10&^(<.@*%[)[:+/\16&^%~[:-/4 2 _1 1%1 4 5 6+/*&8) i. >: 5
3 3.1 3.14 3.141 3.1415 3.14159


答:
05AB1E/2sable, 13 bytes

```<code>žQ„®Â „ÐË 1@=
</code>```

Try it online! (2sable),
Try it online! (05ab1e)

Explanations:

05ab1e:

```<code>žQ                Push list of printable ascii characters
  „®Â             Push dictionary compressed string "treat"
      „ÐË         Push dictionary compressed string "trick"
                  STACK: *ascii*, treat, trick
          1@=     Print second item on stack (treat)
</code>```

2sable:

```<code>žQ                Not a command (ignored)
  „®Â             Push dictionary compressed string "treat"
      „ÐË         Push dictionary compressed string "trick"
                  STACK: treat, trick
          1@=     Print second item on stack (trick)
</code>```

Title: Trick or Treat polyglot

Body:
Since Halloween is coming up I thought I might start a fun little code golf challenge!

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

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

Your program has to do the following:

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

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

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

A few explanations:

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

```<code>"trick"

"Treat"

"    TReAt"

"
     tRICk          "
</code>```

Invalid outputs:

```<code>"tri ck"

"tr
eat"

"trck"
</code>```

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

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

Leaderboards

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

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

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

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

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

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

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

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

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

var QUESTION_ID=97472,OVERRIDE_USER=23417;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i,TAGS_REG = /(<([^>]+)>)/ig;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:400px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Body:
05AB1E/2sable, 13 bytes

žQ„®Â „ÐË 1@=

Try it online! (2sable),
Try it online! (05ab1e)

Explanations:

05ab1e:

žQ                Push list of printable ascii characters
  „®Â             Push dictionary compressed string "treat"
      „ÐË         Push dictionary compressed string "trick"
                  STACK: *ascii*, treat, trick
          1@=     Print second item on stack (treat)

2sable:

žQ                Not a command (ignored)
  „®Â             Push dictionary compressed string "treat"
      „ÐË         Push dictionary compressed string "trick"
                  STACK: treat, trick
          1@=     Print second item on stack (trick)


答:
JavaScript, 65 bytes

```<code>v=>[...""+1e11].map((x,i)=>new Date(v+400,++i).getDay()==2?i:"")
</code>```

Stealing the ""+1e11 trick from the other JavaScript answer.

Returns ["", 2, "", "", "", "", "", "", "", 10, "", ""] for 2016, indicating that Feb and Oct end on a Monday.

Edited: Years 0-99 are parsed as 1900-1999 in JS.  Adding 400 causes them to be parsed as 400-499, which are equivalent calendar years.

Title: The Last Monday

Body:
JavaScript, 65 bytes

v=>[...""+1e11].map((x,i)=>new Date(v+400,++i).getDay()==2?i:"")

Stealing the ""+1e11 trick from the other JavaScript answer.

Returns ["", 2, "", "", "", "", "", "", "", 10, "", ""] for 2016, indicating that Feb and Oct end on a Monday.

Edited: Years 0-99 are parsed as 1900-1999 in JS.  Adding 400 causes them to be parsed as 400-499, which are equivalent calendar years.


问:
Monte Carlo estimator of Pi
Happy Pi Day everyone! For no reason at all, I'm trying to construct a Monte Carlo estimator of Pi that is as short as possible. Can we construct one that can fit in a tweet?

To clarify, what I have in mind is the typical approach of drawing random points from the unit square and calculating the ratio that fall within the unit circle. The number of samples can be hard coded or not. If you hardcode them, you must use at least 1000 samples. The result may be returned or printed as a floating point, fixed point or rational number.

No trig functions or Pi constants, must be a Monte Carlo approach.

This is code golf, so the shortest submission (in bytes) wins.

答:
C, 130 bytes

#include<stdlib.h>f(){double x,y,c=0;for(int i=0;i<8e6;++i)x=rand(),y=rand(),c+=x*x+y*y<1.0*RAND_MAX*RAND_MAX;printf("%f",c/2e6);}
```
<p>Ungolfed:</p>
<pre class="lang-c prettyprint-override"><code>#include <stdlib.h>
f(){
 double x,y,c=0;
 for(int i=0; i<8e6; ++i) x=rand(), y=rand(), c+=x*x+y*y<1.0*RAND_MAX*RAND_MAX;
 printf("%f",c/2e6);
}
</code>```

Title: Monte Carlo estimator of Pi

Body:
C, 130 bytes

#include<stdlib.h>f(){double x,y,c=0;for(int i=0;i<8e6;++i)x=rand(),y=rand(),c+=x*x+y*y<1.0*RAND_MAX*RAND_MAX;printf("%f",c/2e6);}

Ungolfed:

#include <stdlib.h>
f(){
 double x,y,c=0;
 for(int i=0; i<8e6; ++i) x=rand(), y=rand(), c+=x*x+y*y<1.0*RAND_MAX*RAND_MAX;
 printf("%f",c/2e6);
}


答:
Perl, 52 bytes

Just a recursive subroutine. (unusual for a Perl answer, I know..)

sub f{say"@{[grep!ref,@_]}";@_&&f(map/A/?@$_:(),@_)}
```

<p>Call it like that :</p>

```$ perl -E 'sub f{say"@{[grep!ref,@_]}";@_&&f(map/A/?@$_:(),@_)}f(1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9])'
1
2 3 9
4 7
5 6

8
```

<p>Each line of the output corresponds to a depth level of the array (hence the empty line in the example above).</p>

<p>It can be turned into a full program for just a few more bytes : add <code>-n</code> flag and an <code>eval</code> (inside <code>@{ }</code> to transform the input into an array and not an arrayref) to transform the input into a Perl array :</p>

```perl -nE 'sub f{say"@{[grep!ref,@_]}";@_&&f(map/A/?@$_:(),@_)}f(@{+eval})' <<< "[1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]]"
```

<hr>

<p>My previous approach was slightly longer (65 bytes), but still interesting, so I'll let it here :
</p>

```perl -nE '/\d/?push@{$;[$d-1]},$_:/]/?$d--:$d++for/\[|]|\d+/g;say"@$_"for@' <<< "[1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]]"
```

Title: Simplificate an array

Body:
Input

An array that can contain arrays or positive, consecutive, ascending integers. The arrays can have any number of arrays inside of them, and so on and so forth. No arrays will be empty.

Output

This array simplificated

How to simplificate an array

We will use the array, [1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]] as our example.

First, we check how deep the values are nested. Here are the depths and the numbers at those depths:

```<code>0  1
1  2 3 9
2  4 7
3  5 6
5  8
</code>```

We construct the output array by taking the numbers in the original array, grouping them by how deep they are nested, and then nesting the groups at depths of the original depths of their  elements. Arrange the numbers in ascending order and ascending depth.

So, our output is [1, [2, 3, 9], [[4, 7]], [[[5, 6]]], [[[[[8]]]]]]

Examples

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

Body:
Perl, 52 bytes

Just a recursive subroutine. (unusual for a Perl answer, I know..)

sub f{say"@{[grep!ref,@_]}";@_&&f(map/A/?@$_:(),@_)}

Call it like that :

$ perl -E 'sub f{say"@{[grep!ref,@_]}";@_&&f(map/A/?@$_:(),@_)}f(1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9])'
1
2 3 9
4 7
5 6

8

Each line of the output corresponds to a depth level of the array (hence the empty line in the example above).

It can be turned into a full program for just a few more bytes : add -n flag and an eval (inside @{ } to transform the input into an array and not an arrayref) to transform the input into a Perl array :

perl -nE 'sub f{say"@{[grep!ref,@_]}";@_&&f(map/A/?@$_:(),@_)}f(@{+eval})' <<< "[1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]]"

My previous approach was slightly longer (65 bytes), but still interesting, so I'll let it here :

perl -nE '/\d/?push@{$;[$d-1]},$_:/]/?$d--:$d++for/\[|]|\d+/g;say"@$_"for@' <<< "[1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]]"


答:
JavaScript (ES6) 121 <s>144 152</s>

Edit Revised a lot, 1 byte saved thx Patrick Roberts, and 21 more just reviewing the code

Recursive function working on arrays in input and output. I don't like the request of having elements at depth 1 as single elements in output array (while greater levels are grouped as one element): [l1,l1, [l2...], [[l3...]] ]. While this would be more direct: [ [l1...], [[l2...]], [[[l3...]]] ]

f=(l,d=0,r=[])=>l.map(v=>v[0]?f(v,d+1,r):r[d]=[...r[d]||[],v])
r.reduce((r,v,d)=>d?[...r,(n=d=>d-->1?[n(d)]:v)(d)]:v,[])
```
<p>Newline added for readability.</p>
<p>Some notes: the line 2 is evaluated again and again at each recursive call, but only the last iteration at the end of recursion is useful.<br />
The special handling when <code>d==0</code> in line 2 takes care of the anomaly for level 1 elements.<br />
The <code>n</code> recursive function handles the array nesting in output</p>
<p><strong>Test</strong></p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>f=(l,d=0,r=[])=>l.map(v=>v[0]?f(v,d+1,r):r[d]=[...r[d]||[],v])
&&r.reduce((r,v,d)=>d?[...r,(n=d=>d-->1?[n(d)]:v)(d)]:v,[])

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

test=[
 [
   [1, [2,3], 4], /* -> */ [1, 4, [2,3]]
 ]
,[
   [1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]],
   // ->
   [1, [2, 3, 9], [[4, 7]], [[[5, 6]]], [[[[[8]]]]]]
 ]
,[
  [[[1]], [2, [3]], 4, [5, [6, [7, [8], [9, [[10]]]]]]],
  // ->
  [4, [2, 5], [[1, 3, 6]], [[[7]]], [[[[8, 9]]]], [[[[[[10]]]]]]]
 ]
,[
  [1], /* -> */ [1]
 ]
,[
  [1, [2], [[3]], [[[4]]], [[[[5]]]]],
  // ->
  [1, [2], [[3]], [[[4]]], [[[[5]]]]]
 ]
,[
  [1, [[[[2], 3]]], [[4]]],
  [1, [[4]], [[[3]]], [[[[2]]]]]
]]

test.forEach(t=>{
  var i=t[0], k=t[1], r=f(i),
      si=JSON.stringify(i),
      sr=JSON.stringify(r),
      sk=JSON.stringify(k)

  console.log((sr==sk?'OK ':'KO ')+si + " => " + sr)
})</code>```

```</code>```

Title: Simplificate an array

Body:
JavaScript (ES6) 121 <s>144 152</s>

Edit Revised a lot, 1 byte saved thx Patrick Roberts, and 21 more just reviewing the code

Recursive function working on arrays in input and output. I don't like the request of having elements at depth 1 as single elements in output array (while greater levels are grouped as one element): [l1,l1, [l2...], [[l3...]] ]. While this would be more direct: [ [l1...], [[l2...]], [[[l3...]]] ]

f=(l,d=0,r=[])=>l.map(v=>v[0]?f(v,d+1,r):r[d]=[...r[d]||[],v])
r.reduce((r,v,d)=>d?[...r,(n=d=>d-->1?[n(d)]:v)(d)]:v,[])

Newline added for readability.

Some notes: the line 2 is evaluated again and again at each recursive call, but only the last iteration at the end of recursion is useful.

The special handling when d==0 in line 2 takes care of the anomaly for level 1 elements.

The n recursive function handles the array nesting in output

Test

f=(l,d=0,r=[])=>l.map(v=>v[0]?f(v,d+1,r):r[d]=[...r[d]||[],v])
&&r.reduce((r,v,d)=>d?[...r,(n=d=>d-->1?[n(d)]:v)(d)]:v,[])

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

test=[
 [
   [1, [2,3], 4], /* -> */ [1, 4, [2,3]]
 ]
,[
   [1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]],
   // ->
   [1, [2, 3, 9], [[4, 7]], [[[5, 6]]], [[[[[8]]]]]]
 ]
,[
  [[[1]], [2, [3]], 4, [5, [6, [7, [8], [9, [[10]]]]]]],
  // ->
  [4, [2, 5], [[1, 3, 6]], [[[7]]], [[[[8, 9]]]], [[[[[[10]]]]]]]
 ]
,[
  [1], /* -> */ [1]
 ]
,[
  [1, [2], [[3]], [[[4]]], [[[[5]]]]],
  // ->
  [1, [2], [[3]], [[[4]]], [[[[5]]]]]
 ]
,[
  [1, [[[[2], 3]]], [[4]]],
  [1, [[4]], [[[3]]], [[[[2]]]]]
]]

test.forEach(t=>{
  var i=t[0], k=t[1], r=f(i),
      si=JSON.stringify(i),
      sr=JSON.stringify(r),
      sk=JSON.stringify(k)

  console.log((sr==sk?'OK ':'KO ')+si + " => " + sr)
})

<pre id=O></pre>


答:
05AB1E, <s>27</s> <s>26</s> <s>25</s> 21 bytes

```<code>D˜gFvyydi„ÿ ?}}¶?.gG«
</code>```

Try it online! (slightly modified as .g isn't on TIO yet)

Explanation

```<code>D˜gF                    # flattened input length times do
    vy                  # for each y current level of list
      ydi„ÿ ?}          # if y is a digit, print with space
              }         # end v-loop
               ¶?       # print newline
                 .g     # calculate length of stack (this should be .g but I can't test)
                   G«   # length stack times, concatenate items on stack
</code>```

The main strategy is to loop over each possible level of the nested array and print any digits on one row, while keeping the non-digits (lists) in a list one level less nested.

Title: Simplificate an array

Body:
05AB1E, <s>27</s> <s>26</s> <s>25</s> 21 bytes

D˜gFvyydi„ÿ ?}}¶?.gG«

Try it online! (slightly modified as .g isn't on TIO yet)

Explanation

D˜gF                    # flattened input length times do
    vy                  # for each y current level of list
      ydi„ÿ ?}          # if y is a digit, print with space
              }         # end v-loop
               ¶?       # print newline
                 .g     # calculate length of stack (this should be .g but I can't test)
                   G«   # length stack times, concatenate items on stack

The main strategy is to loop over each possible level of the nested array and print any digits on one row, while keeping the non-digits (lists) in a list one level less nested.


问:
Draw an ASCII-O'-Lantern for Halloween
Halloween is almost here, the holiday after which most people need to wean themselves off a hollow diet of sugar.

Write a program that takes in a positive integer. If the integer is less than 31 (1 through 30), output this ASCII-art jack-o'-lantern, looking to the right as if looking forward to Halloween:

```<code> _____I_____
| | | | | | |
| | |^| |^| |
| | | |^| | |
| | |VvVvV| |
|_|_|_|_|_|_|
</code>```

If the input is 31 (the October date Halloween is on), output the same ASCII-o'-lantern, but looking left:

```<code> _____I_____
| | | | | | |
| |^| |^| | |
| | |^| | | |
| |VvVvV| | |
|_|_|_|_|_|_|
</code>```

If the input is greater than 31, output a bloated-looking ASCII-o'-lantern who probably ate too much candy. He can face either left or right since queasyness can be disorientating. So output:

```<code> _____I_____
| | | | | | |
| |o| |o| | |
| | |^| | | |
| |XXXXX| | |
|_|_|_|_|_|_|
</code>```

or

```<code> _____I_____
| | | | | | |
| | |o| |o| |
| | | |^| | |
| | |XXXXX| |
|_|_|_|_|_|_|
</code>```

Whichever you prefer. It may even be different for different numbers above 31.

The shortest code in bytes wins.

答:
Charcoal, 71 bytes

```<code>ＮβＡ‹β³²τＡ§o^τεＡ§XVτφＡ§XvτθＦ³«Ｐ↑⁵|_»↑⁵←I←×_⁵‖Ｏ→↙↙←←ε↙←^↖↓ε↓→φθφθφ¿⁼β³¹‖←
</code>```

Note: This code does not work in the most recent commit as of posting, because string indexing is broken. It should, however, work in this version from October 25. It also runs successfully on the version currently on Try It Online.

Explanation

Charcoal is a language designed for ASCII-art. Output is put onto a canvas, which is printed at the end of the program.

Setup

Get input and calculate face characters:

```<code>Ｎβ        Input number into beta
Ａ‹β³²τ    Assign beta<32 to tau for easy reuse
Ａ§o^τε    Assign appropriate eye character (selected via indexing into "o^") to epsilon
Ａ§XVτφ    Assign outside and middle mouth character to phi
Ａ§Xvτθ    Assign other mouth character to theta
</code>```

Draw the pumpkin

```<code>Ｆ³«  »    Do this three times:
Ｐ↑⁵       Draw a 5-character line upward (using | by default); don't move the cursor
|_         Draw that string, rightward
</code>```

After this loop, we have

```<code>| | |
| | |
| | |
| | |
|_|_|_
</code>```

Next:

```<code>↑⁵         Draw a 5-character line upward
←I         Draw the stem leftward
←×_⁵       Draw 5 underscores leftward
‖Ｏ→       Reflect the canvas rightward, overlapping in the middle
</code>```

Result:

```<code> _____I_____
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
|_|_|_|_|_|_|
</code>```

Draw the face

We will draw the face looking rightward and change it later if necessary.

```<code>↙↙←←ε      Move to the correct spot and draw the right eye (our right, pumpkin's left)
↙←^        Move to the correct spot and draw the nose
↖↓ε        Move to the correct spot and draw the left eye
↓→φθφθφ    Move to the correct spot and draw the mouth with alternating characters
</code>```

Result (for input 31):

```<code> _____I_____
| | | | | | |
| | |^| |^| |
| | | |^| | |
| | |VvVvV| |
|_|_|_|_|_|_|
</code>```

Reflect if it's Halloween:

```<code>¿⁼β³¹      If beta equals 31:
‖←         Reflect canvas leftward
</code>```

Final output:

```<code> _____I_____
| | | | | | |
| |^| |^| | |
| | |^| | | |
| |VvVvV| | |
|_|_|_|_|_|_|
</code>```

Title: Draw an ASCII-O'-Lantern for Halloween

Body:
Charcoal, 71 bytes

ＮβＡ‹β³²τＡ§o^τεＡ§XVτφＡ§XvτθＦ³«Ｐ↑⁵|_»↑⁵←I←×_⁵‖Ｏ→↙↙←←ε↙←^↖↓ε↓→φθφθφ¿⁼β³¹‖←

Note: This code does not work in the most recent commit as of posting, because string indexing is broken. It should, however, work in this version from October 25. It also runs successfully on the version currently on Try It Online.

Explanation

Charcoal is a language designed for ASCII-art. Output is put onto a canvas, which is printed at the end of the program.

Setup

Get input and calculate face characters:

Ｎβ        Input number into beta
Ａ‹β³²τ    Assign beta<32 to tau for easy reuse
Ａ§o^τε    Assign appropriate eye character (selected via indexing into "o^") to epsilon
Ａ§XVτφ    Assign outside and middle mouth character to phi
Ａ§Xvτθ    Assign other mouth character to theta

Draw the pumpkin

Ｆ³«  »    Do this three times:
Ｐ↑⁵       Draw a 5-character line upward (using | by default); don't move the cursor
|_         Draw that string, rightward

After this loop, we have

| | |
| | |
| | |
| | |
|_|_|_

Next:

↑⁵         Draw a 5-character line upward
←I         Draw the stem leftward
←×_⁵       Draw 5 underscores leftward
‖Ｏ→       Reflect the canvas rightward, overlapping in the middle

Result:

 _____I_____
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
|_|_|_|_|_|_|

Draw the face

We will draw the face looking rightward and change it later if necessary.

↙↙←←ε      Move to the correct spot and draw the right eye (our right, pumpkin's left)
↙←^        Move to the correct spot and draw the nose
↖↓ε        Move to the correct spot and draw the left eye
↓→φθφθφ    Move to the correct spot and draw the mouth with alternating characters

Result (for input 31):

 _____I_____
| | | | | | |
| | |^| |^| |
| | | |^| | |
| | |VvVvV| |
|_|_|_|_|_|_|

Reflect if it's Halloween:

¿⁼β³¹      If beta equals 31:
‖←         Reflect canvas leftward

Final output:

 _____I_____
| | | | | | |
| |^| |^| | |
| | |^| | | |
| |VvVvV| | |
|_|_|_|_|_|_|