问:
Shortest Pangrammatic Window
A pangram is a sentence or excerpt which contains all twenty-six letters of the alphabet, as is demonstrated in this code golf challenge. However, a pangrammatic window is a pangram in the form of some segment of text, which may end or begin halfway through a word, found somewhere within a larger work. These naturally occur everywhere, being proper subsets of true pangrams, so just verifying if something contains a pangrammatic window would be boring and also it was previously done.

So, we're interested in finding the smallest one there is in a given piece of text based on its letter length! In the shortest possible code in bytes, of course, to fit the theme.

Rules and Guidelines

Receive a string as the input and return  the string of the smallest pangrammatic window in the input if there is one. If there is not, return either a Boolean False or an empty string.

Whether a string is a pangrammatic window or not is case-insensitive and only depends on the 26 letters, not any punctuation or numbers or other odd symbols.

Similarly, a pangrammatic window's letter length is the total number of how many appearances of letters occur in it alone, and not simply the number of every character. The returned value must be smallest based on this count. We're linguists, after all, not programmers.

An output of a pangrammatic window must, however, must be an exact substring of the input, containing the same capitalization and punctuation, etc.

If there are multiple shortest pangrammatic windows of the same letter length, return any one of them.

Test Cases

```<code>'This isn't a pangram.'
==> False

'Everyone knows about that infamous Quick-Brown-Fox (the one who jumped over some lazy ignoramus of a dog so many years ago).'
==> 'Quick-Brown-Fox (the one who jumped over some lazy ig'

'"The five boxing wizards jump quickly." stated Johnny, before beginning to recite the alphabet with a bunch of semicolons in the middle. "ABCDEFGHI;;;;;;;;;;;;;;;JKLMNOPQRSTUVWXYZ!" he shouted to the heavens.'
==> 'ABCDEFGHI;;;;;;;;;;;;;;;JKLMNOPQRSTUVWXYZ'
</code>```

答:
Oracle SQL 11.2, 461 bytes

WITH s AS (SELECT SUBSTR(:1,LEVEL,1)c,LEVEL p FROM DUAL CONNECT BY LEVEL<=LENGTH(:1)),v(s,f,l)AS(SELECT c,p,p FROM s UNION ALL SELECT s||c,f,p FROM v,s WHERE p=l+1),c AS(SELECT CHR(96+LEVEL)c FROM DUAL CONNECT BY LEVEL<27),a AS(SELECT LISTAGG(c)WITHIN GROUP(ORDER BY 1) a FROM c)SELECT MIN(s)KEEP(DENSE_RANK FIRST ORDER BY LENGTH(s)-NVL(LENGTH(TRANSLATE(LOWER(s),' '||a,' ')),0))FROM(SELECT s,f,SUM(SIGN(INSTR(LOWER(s),c)))x FROM v,c GROUP BY s,f),a WHERE x=26;
```

<p>Un-golfed</p>

<pre class="lang-sql prettyprint-override"><code>WITH s AS (SELECT SUBSTR(:1,LEVEL,1)c,LEVEL p FROM DUAL CONNECT BY LEVEL<=LENGTH(:1))
,v(s,f,l) AS
(
  SELECT c,p,p FROM s
  UNION ALL
  SELECT s||c,f,p FROM v,s WHERE p=l+1
)
,c AS(SELECT CHR(96+LEVEL)c FROM DUAL CONNECT BY LEVEL<27)
,a AS(SELECT LISTAGG(c)WITHIN GROUP(ORDER BY 1) a FROM c)
SELECT MIN(s)KEEP(DENSE_RANK FIRST ORDER BY LENGTH(s)-NVL(LENGTH(TRANSLATE(LOWER(s),' '||a,' ')),0))
FROM(SELECT s,f,SUM(SIGN(INSTR(LOWER(s),c)))x FROM v,c GROUP BY s,f),a
WHERE x=26
</code>```

The s view splits the input in characters and also returns the position of each character.

The recursive view v returns every substring of the input

  s is the substring

  f the position of the first character of the substring

  l the position of the last character added to the current substring

The c view returns the alphabet, one letter at a time

The a view returns the alphabet concatenated as a single string

SELECT s,f,SUM(SIGN(INSTR(LOWER(s),c))

  Returns for each substring the number of distinct letters present in it

  INSTR returns the pos of a letter in the substring, 0 if not present

  SIGN returns 1 if pos > 0, 0 if pos = 0

WHERE x=26

  Filters the substring containing the whole alphabet

TRANSLATE(LOWER(s),' '||a,' ')

  Deletes every letter from the substring

LENGTH(s)-NVL(LENGTH(TRANSLATE(LOWER(s),' '||a,' ')

  Length in letters is the length of the substring minus the length of the subtring without letters

SELECT MIN(s)KEEP(DENSE_RANK FIRST ORDER BY LENGTH(s)-NVL(LENGTH(TRANSLATE(LOWER(s),' '||a,' ')),0))

  Keeps only the substring with the smaller letter count.

  If there is more than one, the first one, sorted as strings ascending, is kept

Title: Shortest Pangrammatic Window

Body:
Oracle SQL 11.2, 461 bytes

WITH s AS (SELECT SUBSTR(:1,LEVEL,1)c,LEVEL p FROM DUAL CONNECT BY LEVEL<=LENGTH(:1)),v(s,f,l)AS(SELECT c,p,p FROM s UNION ALL SELECT s||c,f,p FROM v,s WHERE p=l+1),c AS(SELECT CHR(96+LEVEL)c FROM DUAL CONNECT BY LEVEL<27),a AS(SELECT LISTAGG(c)WITHIN GROUP(ORDER BY 1) a FROM c)SELECT MIN(s)KEEP(DENSE_RANK FIRST ORDER BY LENGTH(s)-NVL(LENGTH(TRANSLATE(LOWER(s),' '||a,' ')),0))FROM(SELECT s,f,SUM(SIGN(INSTR(LOWER(s),c)))x FROM v,c GROUP BY s,f),a WHERE x=26;

Un-golfed

WITH s AS (SELECT SUBSTR(:1,LEVEL,1)c,LEVEL p FROM DUAL CONNECT BY LEVEL<=LENGTH(:1))
,v(s,f,l) AS
(
  SELECT c,p,p FROM s
  UNION ALL
  SELECT s||c,f,p FROM v,s WHERE p=l+1
)
,c AS(SELECT CHR(96+LEVEL)c FROM DUAL CONNECT BY LEVEL<27)
,a AS(SELECT LISTAGG(c)WITHIN GROUP(ORDER BY 1) a FROM c)
SELECT MIN(s)KEEP(DENSE_RANK FIRST ORDER BY LENGTH(s)-NVL(LENGTH(TRANSLATE(LOWER(s),' '||a,' ')),0))
FROM(SELECT s,f,SUM(SIGN(INSTR(LOWER(s),c)))x FROM v,c GROUP BY s,f),a
WHERE x=26

The s view splits the input in characters and also returns the position of each character.

The recursive view v returns every substring of the input

  s is the substring

  f the position of the first character of the substring

  l the position of the last character added to the current substring

The c view returns the alphabet, one letter at a time

The a view returns the alphabet concatenated as a single string

SELECT s,f,SUM(SIGN(INSTR(LOWER(s),c))

  Returns for each substring the number of distinct letters present in it

  INSTR returns the pos of a letter in the substring, 0 if not present

  SIGN returns 1 if pos > 0, 0 if pos = 0

WHERE x=26

  Filters the substring containing the whole alphabet

TRANSLATE(LOWER(s),' '||a,' ')

  Deletes every letter from the substring

LENGTH(s)-NVL(LENGTH(TRANSLATE(LOWER(s),' '||a,' ')

  Length in letters is the length of the substring minus the length of the subtring without letters

SELECT MIN(s)KEEP(DENSE_RANK FIRST ORDER BY LENGTH(s)-NVL(LENGTH(TRANSLATE(LOWER(s),' '||a,' ')),0))

  Keeps only the substring with the smaller letter count.

  If there is more than one, the first one, sorted as strings ascending, is kept


问:
Grow a Treemote!
This is my friend Thomas. He is half tree, half emoticon.

```<code>|    |
| :D |
|    |
</code>```

He is lonely. Let's make him some friends!

Given a text-based emoticon as input (e.g. ಠ_ಠ, :P, >_>, not , , or ), output the corresponding treemote.

A treemote's length is how many characters it is lon (basically most builtin length functions for strings). So ಠ_ಠ has length 3.

The syntax for a treemote of length n is as follows:

```<code>|< 2+n spaces>| * ceil(n/2)
| <emote> | (note the spaces)
|< 2+n spaces>| * ceil(n/2)
</code>```

So any treemote of length 3 would look like:

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

He has ceil(n/2) newline separated trunk segments on either side, each with 2 + n spaces inside.

Challenge: Given the text-based emoticon, output the corresponding treemote.

Other rules:

This is code-golf, which means I want you to write short code.

Standard loopholes disallowed.

You must support non-ascii characters unless your language can't handle them.

Test Cases:

```<code>^_^

|     |
|     |
| ^_^ |
|     |
|     |

\o/

|     |
|     |
| \o/ |
|     |
|     |

(✿◠‿◠)

|        |
|        |
|        |
| (✿◠‿◠) |
|        |
|        |
|        |

D:

|    |
| D: |
|    |

( ͡° ͜ʖ ͡°)

|             |
|             |
|             |
|             |
|             |
|             |
| ( ͡° ͜ʖ ͡°) |
|             |
|             |
|             |
|             |
|             |
|             |
</code>```

答:
Pyth, 30 bytes

I'm surprised that such an easy task isn't implemented in Pyth.

```<code>Ls[K\|dbdK)j++J*/hlQ2]sym;QyQJ
</code>```

Try it online!

ContentLicense: CC BY-SA 3.0

Title: Grow a Treemote!

Body:
Pyth, 30 bytes

I'm surprised that such an easy task isn't implemented in Pyth.

Ls[K\|dbdK)j++J*/hlQ2]sym;QyQJ

Try it online!


问:
Smallest integers after N divisible by 2, 3, and 4
Give credit to whom credit is due.

Objective Given an integer N > 0, out the smallest integers A, B, and C so that:

All of A, B, and C are strictly greater than N;

2 divides A;

3 divides B;

and 4 divides C.

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

Test cases

```<code>N => A, B, C
1 => 2, 3, 4
4 => 6, 6, 8
43 => 44, 45, 44
123 => 124, 126, 124
420 => 422, 423, 424
31415 => 31416, 31416, 31416
1081177 => 1081178, 1081179, 1081180
</code>```

答:
Octave, <s>27</s> <s>22</s> 20 bytes

MATLAB and Octave:

```<code>f=2:4;@(x)f.*ceil((x+1)./f)
</code>```

Better (solutions are equivalent, but one may outperform the other when further golfed), MATLAB and Octave:

```<code>@(x)x-rem(x,2:4)+(2:4)
f=2:4;@(x)x+f-rem(x,f)
</code>```

Only in Octave:

```<code>@(x)x-rem(x,h=2:4)+h
</code>```

Try here.

ContentLicense: CC BY-SA 4.0

Body:
Octave, <s>27</s> <s>22</s> 20 bytes

MATLAB and Octave:

f=2:4;@(x)f.*ceil((x+1)./f)

Better (solutions are equivalent, but one may outperform the other when further golfed), MATLAB and Octave:

@(x)x-rem(x,2:4)+(2:4)
f=2:4;@(x)x+f-rem(x,f)

Only in Octave:

@(x)x-rem(x,h=2:4)+h

Try here.


答:
TSQL, <s>96</s> 88 bytes

```<code>DECLARE @ varchar(100)='^_^'

PRINT STUFF(REPLICATE('|'+SPACE(2+LEN(@))+'|
',LEN(@)*2-1),LEN(@)*(LEN(@)+5)-3,LEN(@),@)
</code>```

Try online!

Title: Grow a Treemote!

Body:
This is my friend Thomas. He is half tree, half emoticon.

```<code>|    |
| :D |
|    |
</code>```

He is lonely. Let's make him some friends!

Given a text-based emoticon as input (e.g. ಠ_ಠ, :P, >_>, not , , or ), output the corresponding treemote.

A treemote's length is how many characters it is lon (basically most builtin length functions for strings). So ಠ_ಠ has length 3.

The syntax for a treemote of length n is as follows:

```<code>|< 2+n spaces>| * ceil(n/2)
| <emote> | (note the spaces)
|< 2+n spaces>| * ceil(n/2)
</code>```

So any treemote of length 3 would look like:

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

He has ceil(n/2) newline separated trunk segments on either side, each with 2 + n spaces inside.

Challenge: Given the text-based emoticon, output the corresponding treemote.

Other rules:

This is code-golf, which means I want you to write short code.

Standard loopholes disallowed.

You must support non-ascii characters unless your language can't handle them.

Test Cases:

```<code>^_^

|     |
|     |
| ^_^ |
|     |
|     |

\o/

|     |
|     |
| \o/ |
|     |
|     |

(✿◠‿◠)

|        |
|        |
|        |
| (✿◠‿◠) |
|        |
|        |
|        |

D:

|    |
| D: |
|    |

( ͡° ͜ʖ ͡°)

|             |
|             |
|             |
|             |
|             |
|             |
| ( ͡° ͜ʖ ͡°) |
|             |
|             |
|             |
|             |
|             |
|             |
</code>```

Body:
TSQL, <s>96</s> 88 bytes

DECLARE @ varchar(100)='^_^'

PRINT STUFF(REPLICATE('|'+SPACE(2+LEN(@))+'|
',LEN(@)*2-1),LEN(@)*(LEN(@)+5)-3,LEN(@),@)

Try online!


问:
Output the Current Time

Challenge

You must output the current time continuously (until cancelled by an interrupt), once every second, by any of the following means:

It must be in 24-hour or AM/PM format.

If it is the former, it must be spaced out with colons (i.e. 15:47:36).

If it is the latter, it must be spaced out with colons and have the AM/PM following (i.e. 3:47:36 PM)

It may be pulled from the internet.

It may be the system time.

It must output any naturally accessible form of output which supports text that you choose.

Output may have extra information aside of the time in it, but you must guarantee one, and only one, output of time per second.

The continuous output must be a second apart - if you choose to wait until the second changes between outputs, that is fine. If you wait a second between each output, that is perfectly acceptable, despite the eventual loss of accuracy.

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

Catalog

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

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

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

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

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

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

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

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

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

var QUESTION_ID=65020,OVERRIDE_USER=44713;function answersUrl(e){return"//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"//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;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

```

答:
Python, 53 bytes

This one prints the date and year as well as the time, so I don't know if it's allowed.

```<code>import time
while 1:print(time.ctime());time.sleep(1)
</code>```

EDIT: J.F.Sebastian made a shorter one.

Title: Output the Current Time

Body:
Python, 53 bytes

This one prints the date and year as well as the time, so I don't know if it's allowed.

import time
while 1:print(time.ctime());time.sleep(1)

EDIT: J.F.Sebastian made a shorter one.


问:
Flatten the Array!
In this challenge, your task is to create a program which takes in a nested array and returns a single-dimensional flattened array. For Example [10,20,[30,[40]],50] should output [10,20,30,40,50].

Input

The input will be a nested array (eg. [10,20,[[[10]]]]). It will contain only Integers (both negative and positive), Strings and Arrays. You can take the input as function argument, STDIN or whatever suits your language. You can assume that the input array won't have an empty array.

Output

The output will be a flatted single-dimensional array with the same elements of same type as in the nested array and in the SAME order.

Test Cases

```<code>[10,20,30] -> [10,20,30]
[[10]] -> [10]
[["Hi"],[[10]]] -> ["Hi",10]
[[[20],["Hi"],"Hi",20]] -> [20,"Hi","Hi",20]
[[["[]"],"[]"]] -> ["[]","[]"]
</code>```

Feel free to ask for any clarification by using comments. This is code-golf, so the shortest code in bytes wins!

Note: If your language contains a built-in for this, then you must NOT use it.

Edit

Please also include a link to a website where your code can be executed.

答:
Python 2, 43 bytes

f=lambda l:[l]*(l*0!=[])or sum(map(f,l),[])
```

On a list, recurses on the elements and concatenates the results. On a string or number, encases in a singleton list.

Unfortunately, Python 2's ordering for types int < list < string sandwiches list between the others, requiring two inequalities to check. So, instead, l*0 is checked against the empty list [], otherwise giving 0 or "".

Title: Flatten the Array!

Body:
Python 2, 43 bytes

f=lambda l:[l]*(l*0!=[])or sum(map(f,l),[])

On a list, recurses on the elements and concatenates the results. On a string or number, encases in a singleton list.

Unfortunately, Python 2's ordering for types int < list < string sandwiches list between the others, requiring two inequalities to check. So, instead, l*0 is checked against the empty list [], otherwise giving 0 or "".


答:
Tellurium, 8 bytes

```<code>[i|t^¨]
</code>```

The code that is after the | and before the ] is run forever (i).

It changes the value of the current cell to the current time (t), outputs the current cell's value using ^, and waits for 1 second (¨) before continuing.

Title: Output the Current Time

Body:
Challenge

You must output the current time continuously (until cancelled by an interrupt), once every second, by any of the following means:

It must be in 24-hour or AM/PM format.

If it is the former, it must be spaced out with colons (i.e. 15:47:36).

If it is the latter, it must be spaced out with colons and have the AM/PM following (i.e. 3:47:36 PM)

It may be pulled from the internet.

It may be the system time.

It must output any naturally accessible form of output which supports text that you choose.

Output may have extra information aside of the time in it, but you must guarantee one, and only one, output of time per second.

The continuous output must be a second apart - if you choose to wait until the second changes between outputs, that is fine. If you wait a second between each output, that is perfectly acceptable, despite the eventual loss of accuracy.

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

Catalog

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

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

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

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

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

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

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

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

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

var QUESTION_ID=65020,OVERRIDE_USER=44713;function answersUrl(e){return"//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"//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;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:
Tellurium, 8 bytes

[i|t^¨]

The code that is after the | and before the ] is run forever (i).

It changes the value of the current cell to the current time (t), outputs the current cell's value using ^, and waits for 1 second (¨) before continuing.


问:
How should you arrange your chairs?
You teach a class of students with interesting preferences for how their chairs are arranged. There are 3 very specific requirements they have for how the chairs are arranged:

They most be arranged in a rectangle, even if it means some chairs go empty.

There must be as few empty chairs as possible.

They must be as "squarey" as possible. Squarey-ness is determined by the distance between the width and the height of the rectangle, lower is better. For example, a rectangle that is 4x7 has a squarey-ness of 3.

To be more specific, the "score" of an arrangement is the distance between the width and height plus the number of chairs that would go empty.

Let's take an example. Let's say you have 13 students. You could arrange the chairs any of these ways:

```<code>1x13
2x7
3x5
4x4
</code>```

1x13 is not very squarey. In fact, 1 and 13 are 12 apart, so we give this arrangement 12 points. It also has 0 empty chairs, so we add 0 points, giving this arrangement a score of 12. Not that great.

2x7 is certainly better. 2 and 7 are only 5 apart, so we give this arrangement 5 points. However, if you actually arranged 2 rows of seven chairs, that would take 14 chairs, meaning one chair would be empty. So we add one point, giving this arrangement a score of 6.

We could also do 3x5. 3 and 5 are 2 apart, so +2 points. It takes 15 chairs, meaning we'd have two extra chairs, so another +2 points, for a score of 4.

Last option, 4x4. 4 and 4 are 0 apart, so we give this +0 points. 4x4 takes 16 chairs, so 3 chairs go empty, for a total score of 3. This is the optimal solution.

In case of a tie, the optimal solution is the one with less empty chairs.

The challenge

You must write a program or function that takes an integer and outputs the optimal arrangement of chairs for that number of students. IO can be in any reasonable format. Here is sample output for any number of students from 1 to 100:

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

As usual, this is code-golf, so standard loopholes apply, and the winner is the shortest answer in bytes.

答:
Python 2, 68 bytes

```<code>lambda n:min((abs(~i-n/~i)+n/~i*~i,i+1,0-n/~i)for i in range(n))[1:]
</code>```

Equivalent to the more “obvious”:

```<code>lambda n:min([(i+1,0-n/~i)for i in range(n)],key=lambda(p,q):abs(p-q)+p*q)
</code>```

Title: How should you arrange your chairs?

Body:
Python 2, 68 bytes

lambda n:min((abs(~i-n/~i)+n/~i*~i,i+1,0-n/~i)for i in range(n))[1:]

Equivalent to the more “obvious”:

lambda n:min([(i+1,0-n/~i)for i in range(n)],key=lambda(p,q):abs(p-q)+p*q)


问:
Monday Mini-Golf #1: Reverse Fibonacci Solver
Monday Mini-Golf: A series of short code-golf challenges, posted (hopefully!) every Monday.

A Fibonacci-like sequence is obtained using the same method as the famous Fibonacci sequence; that is, each number F(n) is found by adding the previous two numbers in the sequence (F(n) = F(n-1) + F(n-2)), or by subtracting the next two numbers (F(n) = F(n+2) - F(n+1)). The main difference is that these sequences can start with any two numbers. The zero-indexing of these sequences is disputable, but for now, we're going to use this rule:

The 0th number in a Fibonacci-like sequence is the last number which is smaller than the preceding number.

As an example, the Fibonacci sequence could be written as 1, 0, 1, 1, 2, 3, 5..., so the 0th number in the sequence is the lone 0.

Challenge

The goal of the challenge is to write a program or function that takes in three integers, in any format:

A and B, the two numbers with which to start generating a sequence.

N, the length of the resulting sequence to output.

And outputs the first N numbers of the sequence, starting at the 0th.

Details

A, B, and N may be taken in any order and format, as long as they are visibly separated. If you use a different order/format, please specify what it is.

You may assume that A, B, and N are always positive integers.

You may assume that N is no more than 100, and the resulting sequence will not contain x >= 2^31.

If A is larger than B, then B is the 0th number in the sequence.

The output must be separated by spaces, commas, and/or newlines.

A trailing space or newline is allowed, but not a trailing comma.

Test-cases

Example 1:

```<code>8 13 10
</code>```

Working backward from 8 13 until we find a number larger than the previous, we get 13 8 5 3 2 1 1 0 1. Thus, 0 is the 0th number in this sequence. Working forward from this, we print out 0 and the next 9 members:

```<code>0 1 1 2 3 5 8 13 21 34
</code>```

Example 2:

```<code>23 37 5
</code>```

Again working backward to find the 0th number, we find 37 23 14 9 5 4 1 3. The 0th number this time is 1, so we print it out, along with the next 4 members:

```<code>1 4 5 9 14
</code>```

Example 3:

```<code>4 3 8
</code>```

With this one, we don't have to work backward to find the 0th number, because 3 is smaller than 4:

```<code>3 7 10 17 27 44 71 115
</code>```

Example 4:

```<code>29 47 11
</code>```

Result:

```<code>1 3 4 7 11 18 29 47 76 123 199
</code>```

Scoring

This is code-golf, so shortest valid code in bytes wins. Tiebreaker goes to earlier posted submission. <s>The winner will be chosen next Monday, Sep 28. Good luck!</s>

Edit: Congrats to your winner, @Jakube, using Pyth for an amazing 23 bytes!

答:
Pyke, 24 bytes

```<code>DA/IDA-],X_r)QVDsRe
R]);
</code>```

Try it here!

Body:
Pyke, 24 bytes

DA/IDA-],X_r)QVDsRe
R]);

Try it here!


答:
Mathcad, [tbd] bytes

function version allows for simple evaluation of different divisor sets.

Mathcad byte equivalence scheme not yet determined.   Keyboard equivalence ~ 16 bytes.

Title: Smallest integers after N divisible by 2, 3, and 4

Body:
Give credit to whom credit is due.

Objective Given an integer N > 0, out the smallest integers A, B, and C so that:

All of A, B, and C are strictly greater than N;

2 divides A;

3 divides B;

and 4 divides C.

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

Test cases

```<code>N => A, B, C
1 => 2, 3, 4
4 => 6, 6, 8
43 => 44, 45, 44
123 => 124, 126, 124
420 => 422, 423, 424
31415 => 31416, 31416, 31416
1081177 => 1081178, 1081179, 1081180
</code>```


答:
Pyke, 11 bytes

```<code>.F~]+=])K~]
</code>```

Try it here!

Explanation:

```<code>.F~]+=])    - Deep for loop
  ~]        -    contents of `]` ([] by default)
    +       -  ^+i
     =]     - `]` = ^
        K~] - Output value
        K   - Remove the output from the for loop
         ~] - Return the contents of `]`
</code>```

Or 7 bytes after a bugfix

```<code>M?+]K~]
</code>```

Try it here!

Explanation:

```<code>M?+]    - Deep map
 ?+]    -  `]` = `]`+i
    K~] - Output value
    K   - Remove the output from the for loop
     ~] - Return the contents of `]`
</code>```

Or even 2 bytes if printing to stdout is allowed (This might come under built-ins)

```<code>M
<newline required>
</code>```

Try it here!

This deeply applies the print_newline function to every non-sequence item in the input and recurses for sequence items.

Title: Flatten the Array!

Body:
In this challenge, your task is to create a program which takes in a nested array and returns a single-dimensional flattened array. For Example [10,20,[30,[40]],50] should output [10,20,30,40,50].

Input

The input will be a nested array (eg. [10,20,[[[10]]]]). It will contain only Integers (both negative and positive), Strings and Arrays. You can take the input as function argument, STDIN or whatever suits your language. You can assume that the input array won't have an empty array.

Output

The output will be a flatted single-dimensional array with the same elements of same type as in the nested array and in the SAME order.

Test Cases

```<code>[10,20,30] -> [10,20,30]
[[10]] -> [10]
[["Hi"],[[10]]] -> ["Hi",10]
[[[20],["Hi"],"Hi",20]] -> [20,"Hi","Hi",20]
[[["[]"],"[]"]] -> ["[]","[]"]
</code>```

Feel free to ask for any clarification by using comments. This is code-golf, so the shortest code in bytes wins!

Note: If your language contains a built-in for this, then you must NOT use it.

Edit

Please also include a link to a website where your code can be executed.

Body:
Pyke, 11 bytes

.F~]+=])K~]

Try it here!

Explanation:

.F~]+=])    - Deep for loop
  ~]        -    contents of `]` ([] by default)
    +       -  ^+i
     =]     - `]` = ^
        K~] - Output value
        K   - Remove the output from the for loop
         ~] - Return the contents of `]`

Or 7 bytes after a bugfix

M?+]K~]

Try it here!

Explanation:

M?+]    - Deep map
 ?+]    -  `]` = `]`+i
    K~] - Output value
    K   - Remove the output from the for loop
     ~] - Return the contents of `]`

Or even 2 bytes if printing to stdout is allowed (This might come under built-ins)

M
<newline required>

Try it here!

This deeply applies the print_newline function to every non-sequence item in the input and recurses for sequence items.


答:
><>, 103 bytes

```<code>i:0(?\
}$&1[\~rl:::2%+*:2,
1-:?!\" "$
]{\  \~
?!\$}1-:
~&\
?!\l$:@-[l2)
~]\
}}\" || "
?!\ol
8.>]l?!;ao2
</code>```

Try it online!

This solution is based on the observation that each line consists of | <x> |, where <x> is the pattern in the middle line, and the same number of spaces in the other lines.

After reading the input (length n) from STDIN, the program pushes n*(n+(n%2)) spaces. The stack is then rolled half as many times. Next, all but n characters are pulled to a new stack, leaving a stack of stacks consisting of either n spaces or the pattern itself (in the middle stack only). In the output step, the contents of the current stack are printed, surrounded by |  and  |.

Title: Grow a Treemote!

Body:
><>, 103 bytes

i:0(?\
}$&1[\~rl:::2%+*:2,
1-:?!\" "$
]{\  \~
?!\$}1-:
~&\
?!\l$:@-[l2)
~]\
}}\" || "
?!\ol
8.>]l?!;ao2

Try it online!

This solution is based on the observation that each line consists of | <x> |, where <x> is the pattern in the middle line, and the same number of spaces in the other lines.

After reading the input (length n) from STDIN, the program pushes n*(n+(n%2)) spaces. The stack is then rolled half as many times. Next, all but n characters are pulled to a new stack, leaving a stack of stacks consisting of either n spaces or the pattern itself (in the middle stack only). In the output step, the contents of the current stack are printed, surrounded by |  and  |.


答:
Pyth, <s>7</s> <s>6</s> 5 bytes

```<code>us+]Y
</code>```

Try it online: Demonstration or Test Suite

But of course, there is also a build-in function, that handles the task in just 2 bytes: .n (Test Suite)

Title: Flatten the Array!

Body:
Pyth, <s>7</s> <s>6</s> 5 bytes

us+]Y

Try it online: Demonstration or Test Suite

But of course, there is also a build-in function, that handles the task in just 2 bytes: .n (Test Suite)


答:
C, 89 bytes

```<code>f;main(int c,char**a){for(c=strlen(*++a)+1;f<(c|1);)printf("|%*s |\n",c,f++==c/2?*a:"");}
</code>```

Not sure if it will handle non-ascii emoticon though....

Title: Grow a Treemote!

Body:
C, 89 bytes

f;main(int c,char**a){for(c=strlen(*++a)+1;f<(c|1);)printf("|%*s |\n",c,f++==c/2?*a:"");}

Not sure if it will handle non-ascii emoticon though....


答:
Perl, <s>34</s> 29 bytes

Functions.

If needs to flatten to list like my @a = f(@a), 29 bytes:

```<code>sub f{map{ref()?f(@$_):$_}@_}
</code>```

Test it on Ideone

If needs to flatten to array ref like my $a = f($a), 34 bytes:

```<code>sub f{[map{ref()?@{f(@$_)}:$_}@_]}
</code>```

Test it on Ideone.

Perl 5.22.0+, 27 bytes

Thanks to hobbs.

If needs to flatten to list like my @a = f(@a), 27 bytes:

```<code>sub f{map{ref?f(@$_):$_}@_}
</code>```

Test it on JDoodle

If needs to flatten to array ref like my $a = f($a), 32 bytes:

```<code>sub f{[map{ref?@{f(@$_)}:$_}@_]}
</code>```

Test it on JDoodle.

Title: Flatten the Array!

Body:
Perl, <s>34</s> 29 bytes

Functions.

If needs to flatten to list like my @a = f(@a), 29 bytes:

sub f{map{ref()?f(@$_):$_}@_}

Test it on Ideone

If needs to flatten to array ref like my $a = f($a), 34 bytes:

sub f{[map{ref()?@{f(@$_)}:$_}@_]}

Test it on Ideone.

Perl 5.22.0+, 27 bytes

Thanks to hobbs.

If needs to flatten to list like my @a = f(@a), 27 bytes:

sub f{map{ref?f(@$_):$_}@_}

Test it on JDoodle

If needs to flatten to array ref like my $a = f($a), 32 bytes:

sub f{[map{ref?@{f(@$_)}:$_}@_]}

Test it on JDoodle.


问:
Palindrome Hello, World
Your task is to create a program that prints "Greetings, Planet!" exactly to the console. Seems simple enough, right? Well, here's the trick. The code must be a palindrome, meaning it reads from right to left the same as in left to right.
Standard loopholes are NOT allowed.

答:
Self-modifying Brainfuck, 47 bytes

```<code>Greetings, Planet!<[.<]<.[<!tenalP ,sgniteerG
</code>```

The code contains two null-bytes, shown here as 0:

```<code>Greetings, Planet0!<[.<]<.[<!0tenalP ,sgniteerG
</code>```

Try it online!

Explanation

Like the other SMBF answers, this includes the required string in the source code, along with a null-byte as an end-of-string marker. Note that SMBF is like regular BF, except that the source is copied to the front of the tape and the tape head starts at the cell just after the source code.

We can save some bytes over the other answers by putting the actual string at the end, so that we don't have to skip past the actual source code. Finally, we can save one more byte by putting the ! on the other side of the null-byte which conveniently lets us reuse the <. in the mirror image to print the last character (otherwise we'd have to double the ] to avoid that <. is executed). Here is the code:

```<code>,     Read a character, which is a no-op with no input.
<     Move tape head onto the 'G'.
[.<]  In a loop, print character, move tape head left. This prints the desired
      string except for the '!'. The loop terminates when the tape head reaches
      the null byte.
<     Move the tape head left another cell onto the '!'.
.     Print it.
[     Unmatched square bracket, terminates the program.
</code>```

Title: Palindrome Hello, World

Body:
Self-modifying Brainfuck, 47 bytes

Greetings, Planet!<[.<]<.[<!tenalP ,sgniteerG

The code contains two null-bytes, shown here as 0:

Greetings, Planet0!<[.<]<.[<!0tenalP ,sgniteerG

Try it online!

Explanation

Like the other SMBF answers, this includes the required string in the source code, along with a null-byte as an end-of-string marker. Note that SMBF is like regular BF, except that the source is copied to the front of the tape and the tape head starts at the cell just after the source code.

We can save some bytes over the other answers by putting the actual string at the end, so that we don't have to skip past the actual source code. Finally, we can save one more byte by putting the ! on the other side of the null-byte which conveniently lets us reuse the <. in the mirror image to print the last character (otherwise we'd have to double the ] to avoid that <. is executed). Here is the code:

,     Read a character, which is a no-op with no input.
<     Move tape head onto the 'G'.
[.<]  In a loop, print character, move tape head left. This prints the desired
      string except for the '!'. The loop terminates when the tape head reaches
      the null byte.
<     Move the tape head left another cell onto the '!'.
.     Print it.
[     Unmatched square bracket, terminates the program.


问:
Compress your code in an image
This is a quine variation.

Introduction

We all write short code, because some obscure reasons, but whatever we do, the'll take up at least 144 pixels/byte (with a 12px font). But what would happen, if we would encode our code in images? This is your task today.

Challenge

You task is to read in your own source code (non-proper quines are allowed, e.g. literally reading the source file), and create an image out of it, by setting the red, green and blue components of a pixel based on the ASCII value of the character.

Example:

We have the string "Hello world!"

```<code>Hello world!
</code>```

Let's convert this to ASCII values:

```<code>72 101 108 108 111 32 119 111 114 108 100 33
</code>```

Map the RGB values to it (If the source code's length is not divisible by 3, use 0s as the remaining characters):

```<code> __________________________________________________
| R | G | B || R | G | B || R | G | B || R | G | B |
----------------------------------------------------
|72 |101|108||108|111|32 ||119|111|114||108|100|33 |
----------------------------------------------------
</code>```

We then create the image with the smallest area out of it. We have 4 sets of RGB values, so the smallest image will be a 2*2 image, going from the top left pixel to the right:

And we get this awfully colored image (resized, so it's at least visible, also proves the fact how small it can get)

Rules/Additional information

There's no input

The output should be as a separate file, or in a separate window.

For multibyte characters, split the character in 2 bytes.

The source code must be at least 1 byte long

The image should be the one from the possible sizes, wich has the closest width/height ratio to 1

The pixel count on the image should exactly be ceil(byte count / 3), no extra pixels should be added

Scoring

This is a code-golf, so the smallest answer in bytes wins.

答:
Python, 81 bytes

```<code>q=open(__file__).read()
print'P3\n9 3 256 '+' '.join(map(lambda x:str(ord(x)),q))
</code>```

Output is in PPM format.

This is what the image looks like:

Scaled up:

Title: Compress your code in an image

Body:
Python, 81 bytes

q=open(__file__).read()
print'P3\n9 3 256 '+' '.join(map(lambda x:str(ord(x)),q))

Output is in PPM format.

This is what the image looks like:

Scaled up:


答:
PowerShell v3+, 72 bytes

```<code>param($a)$b=("| "+(" "*($l=$a.length))+" |`n")*($l+1-shr1);"$b| $a |";$b
</code>```

Takes input string $a. Constructs $b as (the empty pipe-ended string (with $a.length spaces in the middle) and a trailing newline) repeated (length+1 shifted right one bit, i.e., divided by two and ceiling'd) times. Then outputs the copies of $b, the input string with its own pipes, and finally the copies of $b again.

Requires v3+ for the bit-shift -shr operator.

Examples

```<code>PS C:\Tools\Scripts\golfing> .\grow-a-treemote.ps1 '>:-|'
|      |
|      |
| >:-| |
|      |
|      |

PS C:\Tools\Scripts\golfing> .\grow-a-treemote.ps1 '>:`-('
|       |
|       |
|       |
| >:`-( |
|       |
|       |
|       |
</code>```

Title: Grow a Treemote!

Body:
This is my friend Thomas. He is half tree, half emoticon.

```<code>|    |
| :D |
|    |
</code>```

He is lonely. Let's make him some friends!

Given a text-based emoticon as input (e.g. ಠ_ಠ, :P, >_>, not , , or ), output the corresponding treemote.

A treemote's length is how many characters it is lon (basically most builtin length functions for strings). So ಠ_ಠ has length 3.

The syntax for a treemote of length n is as follows:

```<code>|< 2+n spaces>| * ceil(n/2)
| <emote> | (note the spaces)
|< 2+n spaces>| * ceil(n/2)
</code>```

So any treemote of length 3 would look like:

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

He has ceil(n/2) newline separated trunk segments on either side, each with 2 + n spaces inside.

Challenge: Given the text-based emoticon, output the corresponding treemote.

Other rules:

This is code-golf, which means I want you to write short code.

Standard loopholes disallowed.

You must support non-ascii characters unless your language can't handle them.

Test Cases:

```<code>^_^

|     |
|     |
| ^_^ |
|     |
|     |

\o/

|     |
|     |
| \o/ |
|     |
|     |

(✿◠‿◠)

|        |
|        |
|        |
| (✿◠‿◠) |
|        |
|        |
|        |

D:

|    |
| D: |
|    |

( ͡° ͜ʖ ͡°)

|             |
|             |
|             |
|             |
|             |
|             |
| ( ͡° ͜ʖ ͡°) |
|             |
|             |
|             |
|             |
|             |
|             |
</code>```

Body:
PowerShell v3+, 72 bytes

param($a)$b=("| "+(" "*($l=$a.length))+" |`n")*($l+1-shr1);"$b| $a |";$b

Takes input string $a. Constructs $b as (the empty pipe-ended string (with $a.length spaces in the middle) and a trailing newline) repeated (length+1 shifted right one bit, i.e., divided by two and ceiling'd) times. Then outputs the copies of $b, the input string with its own pipes, and finally the copies of $b again.

Requires v3+ for the bit-shift -shr operator.

Examples

PS C:\Tools\Scripts\golfing> .\grow-a-treemote.ps1 '>:-|'
|      |
|      |
| >:-| |
|      |
|      |

PS C:\Tools\Scripts\golfing> .\grow-a-treemote.ps1 '>:`-('
|       |
|       |
|       |
| >:`-( |
|       |
|       |
|       |


答:
Julia, 29 bytes

```<code>f(x,y=vcat(x...))=x==y?x:f(y)
</code>```

This is recursive splatting into a concatenate function until a reaching a fix point. Example

```<code>julia> f([1,[2,[3,[4,[5,[6]]]]]])
6-element Array{Int64,1}:
 1
 2
 3
 4
 5
 6
</code>```

Title: Flatten the Array!

Body:
Julia, 29 bytes

f(x,y=vcat(x...))=x==y?x:f(y)

This is recursive splatting into a concatenate function until a reaching a fix point. Example

julia> f([1,[2,[3,[4,[5,[6]]]]]])
6-element Array{Int64,1}:
 1
 2
 3
 4
 5
 6


答:
MATL, 18 bytes

```<code>:Gy/Xkvtd|yp+&X<Z)
</code>```

Try it online!

Explanation

```<code>:      % Implicit input number N. Range [1 2 ... N]
G      % Push N again
y      % Duplicate second-from-top: push [1 2 ... N] again
/Xk    % Divide and round up
v      % Vertically concatenate. Gives 2×N array of rectangle sizes
td|    % Duplicate. Absolute difference of each column
y      % Duplicate second-from-top: push 2×N array again
p      % Product of each column
+      % Sum absolute differences and products
&X<    % Arg min
Z)     % Use as column index into the 2×N array. Implicitly display
</code>```

Title: How should you arrange your chairs?

Body:
You teach a class of students with interesting preferences for how their chairs are arranged. There are 3 very specific requirements they have for how the chairs are arranged:

They most be arranged in a rectangle, even if it means some chairs go empty.

There must be as few empty chairs as possible.

They must be as "squarey" as possible. Squarey-ness is determined by the distance between the width and the height of the rectangle, lower is better. For example, a rectangle that is 4x7 has a squarey-ness of 3.

To be more specific, the "score" of an arrangement is the distance between the width and height plus the number of chairs that would go empty.

Let's take an example. Let's say you have 13 students. You could arrange the chairs any of these ways:

```<code>1x13
2x7
3x5
4x4
</code>```

1x13 is not very squarey. In fact, 1 and 13 are 12 apart, so we give this arrangement 12 points. It also has 0 empty chairs, so we add 0 points, giving this arrangement a score of 12. Not that great.

2x7 is certainly better. 2 and 7 are only 5 apart, so we give this arrangement 5 points. However, if you actually arranged 2 rows of seven chairs, that would take 14 chairs, meaning one chair would be empty. So we add one point, giving this arrangement a score of 6.

We could also do 3x5. 3 and 5 are 2 apart, so +2 points. It takes 15 chairs, meaning we'd have two extra chairs, so another +2 points, for a score of 4.

Last option, 4x4. 4 and 4 are 0 apart, so we give this +0 points. 4x4 takes 16 chairs, so 3 chairs go empty, for a total score of 3. This is the optimal solution.

In case of a tie, the optimal solution is the one with less empty chairs.

The challenge

You must write a program or function that takes an integer and outputs the optimal arrangement of chairs for that number of students. IO can be in any reasonable format. Here is sample output for any number of students from 1 to 100:

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

As usual, this is code-golf, so standard loopholes apply, and the winner is the shortest answer in bytes.

Body:
MATL, 18 bytes

:Gy/Xkvtd|yp+&X<Z)

Try it online!

Explanation

:      % Implicit input number N. Range [1 2 ... N]
G      % Push N again
y      % Duplicate second-from-top: push [1 2 ... N] again
/Xk    % Divide and round up
v      % Vertically concatenate. Gives 2×N array of rectangle sizes
td|    % Duplicate. Absolute difference of each column
y      % Duplicate second-from-top: push 2×N array again
p      % Product of each column
+      % Sum absolute differences and products
&X<    % Arg min
Z)     % Use as column index into the 2×N array. Implicitly display


答:
Node.js, 63 bytes

(F=x=>require('fs').writeFile('P6','P6 7 3 255 (F='+F+')()'))()
```

Outputs image into a file named P6 which is in the PPM (P6) format.

Here's a PNG rendition (7x3 pixels):

Title: Compress your code in an image

Body:
This is a quine variation.

Introduction

We all write short code, because some obscure reasons, but whatever we do, the'll take up at least 144 pixels/byte (with a 12px font). But what would happen, if we would encode our code in images? This is your task today.

Challenge

You task is to read in your own source code (non-proper quines are allowed, e.g. literally reading the source file), and create an image out of it, by setting the red, green and blue components of a pixel based on the ASCII value of the character.

Example:

We have the string "Hello world!"

```<code>Hello world!
</code>```

Let's convert this to ASCII values:

```<code>72 101 108 108 111 32 119 111 114 108 100 33
</code>```

Map the RGB values to it (If the source code's length is not divisible by 3, use 0s as the remaining characters):

```<code> __________________________________________________
| R | G | B || R | G | B || R | G | B || R | G | B |
----------------------------------------------------
|72 |101|108||108|111|32 ||119|111|114||108|100|33 |
----------------------------------------------------
</code>```

We then create the image with the smallest area out of it. We have 4 sets of RGB values, so the smallest image will be a 2*2 image, going from the top left pixel to the right:

And we get this awfully colored image (resized, so it's at least visible, also proves the fact how small it can get)

Rules/Additional information

There's no input

The output should be as a separate file, or in a separate window.

For multibyte characters, split the character in 2 bytes.

The source code must be at least 1 byte long

The image should be the one from the possible sizes, wich has the closest width/height ratio to 1

The pixel count on the image should exactly be ceil(byte count / 3), no extra pixels should be added

Scoring

This is a code-golf, so the smallest answer in bytes wins.

Body:
Node.js, 63 bytes

(F=x=>require('fs').writeFile('P6','P6 7 3 255 (F='+F+')()'))()

Outputs image into a file named P6 which is in the PPM (P6) format.

Here's a PNG rendition (7x3 pixels):


答:
Ruby, 64 bytes

```<code>->n{(1..n).map{|w|h=(n+w-1)/w;[(h-w).abs+h*w,w*h,w,h]}.min[2,3]}
</code>```

A lambada that takes the number of people as an argument and returns an array with width and height of the optimal solution.

Title: How should you arrange your chairs?

Body:
Ruby, 64 bytes

->n{(1..n).map{|w|h=(n+w-1)/w;[(h-w).abs+h*w,w*h,w,h]}.min[2,3]}

A lambada that takes the number of people as an argument and returns an array with width and height of the optimal solution.


答:
Haskell, 43 bytes

```<code>data D a=L a|N[D a]
f(L x)=[x]
f(N l)=f=<<l
</code>```

Haskell has neither nested lists with different depths of the sublists nor mixed types for the list elements. For nesting I define a custom data type D which is either a leaf L that holds some element or a node N which is a list of Ds. For the mixed elements I use the predefined data type Either which combines two types into one, here Either String Integer. The new type D and the flatten function f are fully polymorphic in the type of the leaf elements, so I don't have to take extra care of anything regarding Either.

Usage example: f (N[N[L(Right 20)], N[L(Left "Hi")], L(Left "Hi") , L(Right 20)]) -> [Right 20,Left "Hi",Left "Hi",Right 20].

Title: Flatten the Array!

Body:
Haskell, 43 bytes

data D a=L a|N[D a]
f(L x)=[x]
f(N l)=f=<<l

Haskell has neither nested lists with different depths of the sublists nor mixed types for the list elements. For nesting I define a custom data type D which is either a leaf L that holds some element or a node N which is a list of Ds. For the mixed elements I use the predefined data type Either which combines two types into one, here Either String Integer. The new type D and the flatten function f are fully polymorphic in the type of the leaf elements, so I don't have to take extra care of anything regarding Either.

Usage example: f (N[N[L(Right 20)], N[L(Left "Hi")], L(Left "Hi") , L(Right 20)]) -> [Right 20,Left "Hi",Left "Hi",Right 20].


问:
Tips for golfing in JavaScript
What general tips do you have for golfing in JavaScript? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to JavaScript (e.g. "remove comments" is not an answer).

Note: Also see Tips for Golfing in ECMAScript 6 and above

答:
Use with to import methods and properties from objects into the local scope.

It becomes more apparent with longer class names or repeated use of the same one:

a=Math.max(1,2),b=Math.min(2,7),c=Math.sqrt(100)
with(Math)a=max(1,2),b=min(2,7),c=sqrt(100)
```

Title: Tips for golfing in JavaScript