问:
"99 Bottles of Beer"
Write a program that outputs the lyrics to 99 Bottles of Beer, in as few bytes as possible.

Lyrics:

```<code>99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.

98 bottles of beer on the wall, 98 bottles of beer.
Take one down and pass it around, 97 bottles of beer on the wall.

97 bottles of beer on the wall, 97 bottles of beer.
Take one down and pass it around, 96 bottles of beer on the wall.

96 bottles of beer on the wall, 96 bottles of beer.
Take one down and pass it around, 95 bottles of beer on the wall.

95 bottles of beer on the wall, 95 bottles of beer.
Take one down and pass it around, 94 bottles of beer on the wall.

....

3 bottles of beer on the wall, 3 bottles of beer.
Take one down and pass it around, 2 bottles of beer on the wall.

2 bottles of beer on the wall, 2 bottles of beer.
Take one down and pass it around, 1 bottle of beer on the wall.

1 bottle of beer on the wall, 1 bottle of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.
</code>```

Rules:

Your program must log to STDOUT or an acceptable alternative, or be returned from a function (with or without a trailing newline).

Your program must be a full, runnable program or function.

Languages specifically written to submit a 0-byte answer to this challenge are allowed, just not particularly interesting.

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.

This is different from the output by HQ9+ or 99. Any answers written in these languages will be deleted.

As this is a catalog challenge, this is not about finding the language with the shortest solution for this (there are some where the empty program does the trick) - this is about finding the shortest solution in every language. Therefore, no answer will be marked as accepted.

Catalogue

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

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

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

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

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

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

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

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

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
Ruby, <s>237</s> (thanks primo!) 227 bytes

```<code>99.downto(2){|i|puts "#{i}#{$B=" bottles of beer"}#{$W=" on the wall"}, #{i}#$B,\nTake one down and pass it around, #{i-1}#{i<3?$C=$B.tr('s','') :$B}#$W.\n\n"};puts "1#$C#$W, 1#$C,\nGo to the store and buy some more, 99#$B#$W."
</code>```

Mostly ungolfed: (old, outdated)

```<code>$B="bottles of beer"
$C="bottle of beer"
$W="on the wall"
99.downto(2) { |i|
  puts "#{i} #$B #$W, #{i} #$B,\nTake one down and pass it around, #{i-1} #{i==2 ? $C : $B} #$W.\n\n"}
  puts "1 #$C #$W, 1 #$C,\nGo to the store and buy some more, 99 #$B #$W."
</code>```

Try it online:

http://codepad.org/ozIpcgPI

Title: "99 Bottles of Beer"

Body:
Ruby, <s>237</s> (thanks primo!) 227 bytes

99.downto(2){|i|puts "#{i}#{$B=" bottles of beer"}#{$W=" on the wall"}, #{i}#$B,\nTake one down and pass it around, #{i-1}#{i<3?$C=$B.tr('s','') :$B}#$W.\n\n"};puts "1#$C#$W, 1#$C,\nGo to the store and buy some more, 99#$B#$W."

Mostly ungolfed: (old, outdated)

$B="bottles of beer"
$C="bottle of beer"
$W="on the wall"
99.downto(2) { |i|
  puts "#{i} #$B #$W, #{i} #$B,\nTake one down and pass it around, #{i-1} #{i==2 ? $C : $B} #$W.\n\n"}
  puts "1 #$C #$W, 1 #$C,\nGo to the store and buy some more, 99 #$B #$W."

Try it online:

http://codepad.org/ozIpcgPI


问:
Code golf for the lazy
Your goal in this code golf is to take two strings, language and code (if the golfed code you wrote for this is multiline, then this variable would be multiline.), and one integer, bytes. They represent the variables for a programming language, number of bytes it takes, and the code itself.

After that, you are going to format it like a code golfer does it.

The output variable is a multiline string called answer.

You can use multiline strings on:

C++

Python

Perl

JavaScript

If you search Stack Overflow, you should be able to find more programming languages that support it.

Here is a template of the output markdown. The code variable is in a code block, and there is a second-level header.

```<code>## {language}, {bytes} bytes

     {code}
</code>```

Here is what the output would look like when pasted into a Markdown parser.

{language}, {bytes} bytes

```<code>    {code}
</code>```

Variables are assumed to be filled out already as the language you coded your code golf entry in, the number of bytes it takes, and the actual code for it.

Here is another example of the output as code, this time with variables filled out:

```<code>## JavaScript, 1337 bytes

document.getElementById("foo").innerHTML = bar;
</code>```

Here is the version as a blockquote:

JavaScript, 1337 bytes

```<code>    document.getElementById("foo").innerHTML = bar;
</code>```

Bytes can be taken off from your code if you use a way to set the text of a
 element in HTML by the id result, like the following JavaScript code:

```<code>document.getElementById("result").innerHTML = answer;
</code>```

Make sure to also include the

 in the HTML section of JSFiddle for this to work.

Scoring

Like all code-golf questions, the code that uses the least amount of bytes is the best.

答:
Ruby, 63 bytes

```<code>def f(l,b,c) s="\#\# #{l}, #{b} bytes\n\n    #{c}";return s;end
</code>```

Try it online: http://codepad.org/EIn0Gw9M

ContentLicense: CC BY-SA 3.0

Title: Code golf for the lazy

Body:
Ruby, 63 bytes

def f(l,b,c) s="\#\# #{l}, #{b} bytes\n\n    #{c}";return s;end

Try it online: http://codepad.org/EIn0Gw9M


问:
Duplicate & switch case
The goal is, having taken a string as input, duplicate each latin letter and "toggle" its case (i.e. uppercase becomes lowercase and vice-versa).

Example inputs & outputs:

```<code>Input      Output
bad        bBaAdD
Nice       NniIcCeE
T e S t    Tt eE Ss tT
s E t      sS Ee tT
1!1!1st!   1!1!1sStT!
n00b       nN00bB
(e.g.)     (eE.gG.)
H3l|@!     Hh3lL|@!
</code>```

The input consists of printable ASCII symbols.

You shouldn't duplicate non-latin letters, numbers, special chars.

答:
Erlang, 106 bytes

```<code>f(S)->G=string,lists:flatten([case G:to_upper(C)==G:to_lower(C)of true->C;false->[C,C bxor 32]end||C<-S]).
</code>```

Uses Lynn's XOR trick to toggle the case.

Title: Duplicate & switch case

Body:
Erlang, 106 bytes

f(S)->G=string,lists:flatten([case G:to_upper(C)==G:to_lower(C)of true->C;false->[C,C bxor 32]end||C<-S]).

Uses Lynn's XOR trick to toggle the case.


问:
Code Golf Bingo!
You are given a Bingo board and a list of calls.  You must print BINGO! as soon as your board wins the game.

Bingo boards look like this:

They will be specified like this:

```<code>14 29 38 52 74
4 18 33 46 62
7 16 * 60 71
9 27 44 51 67
12 23 35 47 73
</code>```

Immediately following the board will be calls, like this:

```<code>B7
I29
G60
G51
O71
I23
I16
N38
</code>```

You must echo the calls out to standard output until just after the call that makes you win (get a row, column, or 5-long diagonal all filled), then print BINGO!.

For the above example, print:

```<code>B7
I29
G60
G51
O71
I23
I16
BINGO!
</code>```

Rules

Standard code-golf rules, shortest code wins.

Details

There will always be enough calls to guarantee you a Bingo.  There will be no duplicate numbers on the board, and no duplicate calls.  Boards will always have correctly matched numbers and letters (the B column contains only 1-15, the I column contains only 16-30, and so on), as will calls.  The one and only free space will always be in the middle, marked with * instead of a number.  Consuming and discarding calls from standard input after the winning call is allowed, but not required.

Make your own test cases!

答:
Mathematica 250

Disclosure: I assumed that the input was given in lists which are far more natural to use for Mathematica. So,with b representing the board and c representing the calls,

```<code>b//Grid
c//Column
</code>```

If the input were to be in strings, the code would grow by about 30 characters.  (I'll later include that variation.)

Code

```<code>y = ReplacePart[ConstantArray[0, {5, 5}], {3, 3} -> 1]; d = Diagonal;
t := Tr[BitAnd @@@ Join[y, Transpose@y, {d@y}, {d[Reverse /@ y]}]] > 0;
r@i_ :=(y = ReplacePart[y, Position[x, ToExpression@StringDrop[i, 1]][[1]] -> 1];
Print@If[t, Column[{i, "BINGO!"}], i])
n = 1; While[! t, r@c[[n]]; n++]
</code>```

B7

I29

G60

G51

O71

I23

I16

BINGO!

Title: Code Golf Bingo!

Body:
Mathematica 250

Disclosure: I assumed that the input was given in lists which are far more natural to use for Mathematica. So,with b representing the board and c representing the calls,

b//Grid
c//Column

If the input were to be in strings, the code would grow by about 30 characters.  (I'll later include that variation.)

Code

y = ReplacePart[ConstantArray[0, {5, 5}], {3, 3} -> 1]; d = Diagonal;
t := Tr[BitAnd @@@ Join[y, Transpose@y, {d@y}, {d[Reverse /@ y]}]] > 0;
r@i_ :=(y = ReplacePart[y, Position[x, ToExpression@StringDrop[i, 1]][[1]] -> 1];
Print@If[t, Column[{i, "BINGO!"}], i])
n = 1; While[! t, r@c[[n]]; n++]

B7

I29

G60

G51

O71

I23

I16

BINGO!


答:
MATL, <s>28</s> 27 bytes

1 byte saved thanks to @NinjaBearMoneky's suggestion

```<code>35tOj', 'j' bytes'10t4Z"j&h
</code>```

Try it online!

The code block must be on a single line.

Explanation

```<code>35t           % Push 35 (ASCII for '#') twice
0             % Push 0. When converted to char, it will be displayed as a space
j             % Input string (language name)
', '          % Push this string
j             % Input string (byte count)
' bytes'      % Push this string
10t           % Push 10 (ASCII for linefeed) twice
4Z"           % Push string containing four spaces
j             % Input string (code)
&h            % Concatenate everything into a string. Implicitly display
</code>```

Title: Code golf for the lazy

Body:
Your goal in this code golf is to take two strings, language and code (if the golfed code you wrote for this is multiline, then this variable would be multiline.), and one integer, bytes. They represent the variables for a programming language, number of bytes it takes, and the code itself.

After that, you are going to format it like a code golfer does it.

The output variable is a multiline string called answer.

You can use multiline strings on:

C++

Python

Perl

JavaScript

If you search Stack Overflow, you should be able to find more programming languages that support it.

Here is a template of the output markdown. The code variable is in a code block, and there is a second-level header.

```<code>## {language}, {bytes} bytes

     {code}
</code>```

Here is what the output would look like when pasted into a Markdown parser.

{language}, {bytes} bytes

```<code>    {code}
</code>```

Variables are assumed to be filled out already as the language you coded your code golf entry in, the number of bytes it takes, and the actual code for it.

Here is another example of the output as code, this time with variables filled out:

```<code>## JavaScript, 1337 bytes

document.getElementById("foo").innerHTML = bar;
</code>```

Here is the version as a blockquote:

JavaScript, 1337 bytes

```<code>    document.getElementById("foo").innerHTML = bar;
</code>```

Bytes can be taken off from your code if you use a way to set the text of a
 element in HTML by the id result, like the following JavaScript code:

```<code>document.getElementById("result").innerHTML = answer;
</code>```

Make sure to also include the

 in the HTML section of JSFiddle for this to work.

Scoring

Like all code-golf questions, the code that uses the least amount of bytes is the best.

Body:
MATL, <s>28</s> 27 bytes

1 byte saved thanks to @NinjaBearMoneky's suggestion

35tOj', 'j' bytes'10t4Z"j&h

Try it online!

The code block must be on a single line.

Explanation

35t           % Push 35 (ASCII for '#') twice
0             % Push 0. When converted to char, it will be displayed as a space
j             % Input string (language name)
', '          % Push this string
j             % Input string (byte count)
' bytes'      % Push this string
10t           % Push 10 (ASCII for linefeed) twice
4Z"           % Push string containing four spaces
j             % Input string (code)
&h            % Concatenate everything into a string. Implicitly display


答:
CJam, <s>26</s> 23 bytes

Thanks to @NinjaBearMonkey for removing 3 bytes!

```<code>'#_Sl',Sl" bytes"N_S4*l
</code>```

The code block must be on a single line.

Try it online!

Explanation

```<code>'#_S       e# Push character "#" twice, then a space
l          e# Read line from input
',S        e# Push a comma, then a space
l          e# Read line from input
" bytes"   e# Push this string
N_S4*      e# Push newline twice, then four spaces
l          e# Read line from input. Implicitly display
</code>```

Title: Code golf for the lazy

Body:
CJam, <s>26</s> 23 bytes

Thanks to @NinjaBearMonkey for removing 3 bytes!

'#_Sl',Sl" bytes"N_S4*l

The code block must be on a single line.

Try it online!

Explanation

'#_S       e# Push character "#" twice, then a space
l          e# Read line from input
',S        e# Push a comma, then a space
l          e# Read line from input
" bytes"   e# Push this string
N_S4*      e# Push newline twice, then four spaces
l          e# Read line from input. Implicitly display


答:
hashmap, 29 bytes.

```<code>"## "i", "h" bytes.\n\n    "i
</code>```

(I wrote that post with the program, but I had to escape \n into \\n)

Explanation:

```<code>"## "                         Push string
     i", "                    Push input and string
          h" bytes.\n\n    "i Push input as number and string, then the input.
</code>```

Title: Code golf for the lazy

Body:
hashmap, 29 bytes.

"## "i", "h" bytes.\n\n    "i

(I wrote that post with the program, but I had to escape \n into \\n)

Explanation:

"## "                         Push string
     i", "                    Push input and string
          h" bytes.\n\n    "i Push input as number and string, then the input.


答:
05AB1E, 21 bytes

Code:

```<code>“## ÿ, ÿ¡Ï
“,|v4ð×y«,
</code>```

Uses the CP-1252 encoding. Try it online!.

Title: Code golf for the lazy

Body:
05AB1E, 21 bytes

Code:

“## ÿ, ÿ¡Ï
“,|v4ð×y«,

Uses the CP-1252 encoding. Try it online!.


答:
Pyke, 25 bytes

```<code>"##"Q", "z" bytes"skd4*z+
</code>```

Try it here!

Or

Pyke, 0 bytes

Try it here! - click the copy answer button ;)

EDIT -
It's just a feature of the website, it's cheating (or at least I would consider it so) because it never parses an AST and the web program probably isn't considered part of the language due to it not interacting with the language much (even though it is running the Pyke interpreter)

Title: Code golf for the lazy

Body:
Pyke, 25 bytes

"##"Q", "z" bytes"skd4*z+

Try it here!

Or

Pyke, 0 bytes

Try it here! - click the copy answer button ;)

EDIT -
It's just a feature of the website, it's cheating (or at least I would consider it so) because it never parses an AST and the web program probably isn't considered part of the language due to it not interacting with the language much (even though it is running the Pyke interpreter)


问:
Generate a Stack Exchange Favicon
Do you recognize the PPCG logo?
it looks like this, when you do an ascii art of it.

```<code>+---+
|PCG|
+---+
   v
</code>```

Now, In this Code Golf, You will make a code, that makes logos for other sites, similar to the PPCG logo.

What You should do

The "Shortened" string will be the string, with all upper case letters and numbers in the input string.(Which would be PPCG when the input string is Programming Puzzles & Code Golf)

The "Box" (

```<code>+---+
|   |
+---+
   v
</code>```

)
should fit the Shortened string perfectly.(No bigger or smaller)

Also the v part should be exactly 1 down and 1 left to the down right +.

Then output the box which has the shortened string in it.

Example

Stack Overflow:

```<code>+--+
|SO|
+--+
  v
</code>```

Area 51:

```<code>+---+
|A51|
+---+
   v
</code>```

Rules

You may assume that the input contains at least one digit or upper case letter.

Standard code-golf rules apply.

答:
MATL, 34 bytes

```<code>t1Y24Y2hm)T45&Ya'+|+'!wy&h10M~'v'h
</code>```

Try it online!

```<code>t        % Implicit input. Duplicate
1Y2      % Uppercase letters
4Y2      % Digit characters
h        % Concatenate horizontally: string with uppercase letters and digits
m        % True for input chars that are uppercase letters or digits
)        % Keep only those
T45&Ya   % Pad up and down with character 45, which is '-'. Gives three-row char array
'+|+'!   % Push this string and transpose into a column vector
wy       % Swap, duplicate the second array from the top. This places one copy of the
         % column vector below and one above the three-row char array
&h       % Contatenate all stack arrays horizontally. This gives the box with the text
10M      % Retrieve the string with selected letters
~        % Logical negate. Gives zeros, which will be displayes as spaces
'v'      % Push this character
h        % Concatenate horizontally with the zeros.
         % Implicitly display the box with the text followed by the string containing
         % the zero character repeated and the 'v'
</code>```

Title: Generate a Stack Exchange Favicon

Body:
MATL, 34 bytes

t1Y24Y2hm)T45&Ya'+|+'!wy&h10M~'v'h

Try it online!

t        % Implicit input. Duplicate
1Y2      % Uppercase letters
4Y2      % Digit characters
h        % Concatenate horizontally: string with uppercase letters and digits
m        % True for input chars that are uppercase letters or digits
)        % Keep only those
T45&Ya   % Pad up and down with character 45, which is '-'. Gives three-row char array
'+|+'!   % Push this string and transpose into a column vector
wy       % Swap, duplicate the second array from the top. This places one copy of the
         % column vector below and one above the three-row char array
&h       % Contatenate all stack arrays horizontally. This gives the box with the text
10M      % Retrieve the string with selected letters
~        % Logical negate. Gives zeros, which will be displayes as spaces
'v'      % Push this character
h        % Concatenate horizontally with the zeros.
         % Implicitly display the box with the text followed by the string containing
         % the zero character repeated and the 'v'

ContentLicense: CC BY-SA 4.0


问:
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

```

答:
Stack Cats, 8 + 4 = 12 bytes

```<code>]_:]_!<X
</code>```

Run with the -mn flags. Try it online!

Golfing in Stack Cats is highly counterintuitive, so this program above was found with a few days of brute forcing. For comparison, a more intuitive, human-written solution using the *(...)> template is two bytes longer

```<code>*(>-_:[:)>
</code>```

with the -ln flags instead (see the bottom of this post for an explanation).

Explanation

Here's a primer on Stack Cats:

Stack Cats is a reversible esoteric language where the mirror of a snippet undoes the effect of the original snippet. Programs must also be mirror images of itself — necessarily, this means that even-length programs are either no-ops or infinite loops, and all non-trivial terminating programs are of odd length (and are essentially a conjugation of the central operator).

Since half the program is always implied, one half can be left out with the -m or -l flag. Here the -m flag is used, so the half program above actually expands to ]_:]_!<X>!_[:_[.

As its name suggests, Stack Cats is stack-based, with the stacks being bottomless with zeroes (i.e. operations on an otherwise empty stack return 0). Stack Cats actually uses a tape of stacks, e.g. < and > move one stack left and one stack right respectively.

Zeroes at the bottom of the stack are swallowed/removed.

All input is pushed to an initial input stack, with the first input at the top and an extra -1 below the last input. Output is done at the end, using the contents of the current stack (with an optional -1 at the bottom being ignored). -n denotes numeric I/O.

And here's a trace of the expanded full program, ]_:]_!<X>!_[:_[:

```<code>    Initial state (* denotes current stack):
      ... [] [-1 b a]* [] [] ...
]   Move one stack right, taking the top element with you
      ... [] [-1 b] [a]* [] ...
_   Reversible subtraction, performing [x y] -> [x x-y] (uses an implicit zero here)
      ... [] [-1 b] [-a]* [] ...
:   Swap top two
      ... [] [-1 b] [-a 0]* [] ...
]   Move one stack right, taking the top element with you
      ... [] [-1 b] [-a] []* ...
_   Reversible subtraction (0-0, so no-op here)
!   Bit flip top element, x -> -x-1
      ... [] [-1 b] [-a] [-1]* ...
<   Move one stack left
      ... [] [-1 b] [-a]* [-1] ...
X   Swap the stack to the left and right
      ... [] [-1] [-a]* [-1 b] ...
>   Move one stack right
      ... [] [-1] [-a] [-1 b]* ...
!   Bit flip
      ... [] [-1] [-a] [-1 -b-1]* ...
_   Reversible subtraction
      ... [] [-1] [-a] [-1 b]* ...
[   Move one stack left, taking the top element with you
      ... [] [-1] [-a b]* [-1] ...
:   Swap top two
      ... [] [-1] [b -a]* [-1] ...
_   Reversible subtraction
      ... [] [-1] [b a+b]* [-1] ...
[   Move one stack left, taking the top element with you
      ... [] [-1 a+b]* [b] [-1] ...
</code>```

a+b is then outputted, with the base -1 ignored. Note that the trickiest part about this solution is that the output stack must have a -1 at the bottom, otherwise an output stack of just [-1] would ignore the base -1, and an output stack of [0] would cause the base zero to be swallowed (but an output stack of [2], for example, would output 2 just fine).

Just for fun, here's the full list of related solutions of the same length found (list might not be complete):

```<code>]_:]^!<X
]_:]_!<X
]_:]!^<X
]_:!]^<X
[_:[^!>X
[_:[_!>X
[_:[!^>X
[_:![^>X
</code>```

The *(>-_:[:)> solution is longer, but is more intuitive to write since it uses the *(...)> template. This template expands to <(...)*(...)> when used with the -l flag, which means:

```<code><       Move one stack left
(...)   Loop - enter if the top is positive and exit when the top is next positive again
        Since the stack to the left is initially empty, this is a no-op (top is 0)
*       XOR with 1 - top of stack is now 1
(...)   Another loop, this time actually run
>       Move one stack right
</code>```

As such, the *(...)> template means that the first loop is skipped but the second is executed. This allows more straightforward programming to take place, since we don't need to worry about the effects of the loop in the other half of the program.

In this case, the inside of the loop is:

```<code>>       Move one stack right, to the input stack
-       Negate top, [-1 b a] -> [-1 b -a]
_       Reversible subtraction, [-1 b -a] -> [-1 b a+b]
:       Swap top two, [-1 b a+b] -> [-1 a+b b]
[       Move one stack left, taking top of stack with you (removing the top b)
:       Swap top two, putting the 1 on this stack on top again
</code>```

The final > in the template then moves us back to the input stack, where a+b is outputted.

Title: Add two numbers

Body:
Stack Cats, 8 + 4 = 12 bytes

]_:]_!<X

Run with the -mn flags. Try it online!

Golfing in Stack Cats is highly counterintuitive, so this program above was found with a few days of brute forcing. For comparison, a more intuitive, human-written solution using the *(...)> template is two bytes longer

*(>-_:[:)>

with the -ln flags instead (see the bottom of this post for an explanation).

Explanation

Here's a primer on Stack Cats:

Stack Cats is a reversible esoteric language where the mirror of a snippet undoes the effect of the original snippet. Programs must also be mirror images of itself — necessarily, this means that even-length programs are either no-ops or infinite loops, and all non-trivial terminating programs are of odd length (and are essentially a conjugation of the central operator).

Since half the program is always implied, one half can be left out with the -m or -l flag. Here the -m flag is used, so the half program above actually expands to ]_:]_!<X>!_[:_[.

As its name suggests, Stack Cats is stack-based, with the stacks being bottomless with zeroes (i.e. operations on an otherwise empty stack return 0). Stack Cats actually uses a tape of stacks, e.g. < and > move one stack left and one stack right respectively.

Zeroes at the bottom of the stack are swallowed/removed.

All input is pushed to an initial input stack, with the first input at the top and an extra -1 below the last input. Output is done at the end, using the contents of the current stack (with an optional -1 at the bottom being ignored). -n denotes numeric I/O.

And here's a trace of the expanded full program, ]_:]_!<X>!_[:_[:

    Initial state (* denotes current stack):
      ... [] [-1 b a]* [] [] ...
]   Move one stack right, taking the top element with you
      ... [] [-1 b] [a]* [] ...
_   Reversible subtraction, performing [x y] -> [x x-y] (uses an implicit zero here)
      ... [] [-1 b] [-a]* [] ...
:   Swap top two
      ... [] [-1 b] [-a 0]* [] ...
]   Move one stack right, taking the top element with you
      ... [] [-1 b] [-a] []* ...
_   Reversible subtraction (0-0, so no-op here)
!   Bit flip top element, x -> -x-1
      ... [] [-1 b] [-a] [-1]* ...
<   Move one stack left
      ... [] [-1 b] [-a]* [-1] ...
X   Swap the stack to the left and right
      ... [] [-1] [-a]* [-1 b] ...
>   Move one stack right
      ... [] [-1] [-a] [-1 b]* ...
!   Bit flip
      ... [] [-1] [-a] [-1 -b-1]* ...
_   Reversible subtraction
      ... [] [-1] [-a] [-1 b]* ...
[   Move one stack left, taking the top element with you
      ... [] [-1] [-a b]* [-1] ...
:   Swap top two
      ... [] [-1] [b -a]* [-1] ...
_   Reversible subtraction
      ... [] [-1] [b a+b]* [-1] ...
[   Move one stack left, taking the top element with you
      ... [] [-1 a+b]* [b] [-1] ...

a+b is then outputted, with the base -1 ignored. Note that the trickiest part about this solution is that the output stack must have a -1 at the bottom, otherwise an output stack of just [-1] would ignore the base -1, and an output stack of [0] would cause the base zero to be swallowed (but an output stack of [2], for example, would output 2 just fine).

Just for fun, here's the full list of related solutions of the same length found (list might not be complete):

]_:]^!<X
]_:]_!<X
]_:]!^<X
]_:!]^<X
[_:[^!>X
[_:[_!>X
[_:[!^>X
[_:![^>X

The *(>-_:[:)> solution is longer, but is more intuitive to write since it uses the *(...)> template. This template expands to <(...)*(...)> when used with the -l flag, which means:

<       Move one stack left
(...)   Loop - enter if the top is positive and exit when the top is next positive again
        Since the stack to the left is initially empty, this is a no-op (top is 0)
*       XOR with 1 - top of stack is now 1
(...)   Another loop, this time actually run
>       Move one stack right

As such, the *(...)> template means that the first loop is skipped but the second is executed. This allows more straightforward programming to take place, since we don't need to worry about the effects of the loop in the other half of the program.

In this case, the inside of the loop is:

>       Move one stack right, to the input stack
-       Negate top, [-1 b a] -> [-1 b -a]
_       Reversible subtraction, [-1 b -a] -> [-1 b a+b]
:       Swap top two, [-1 b a+b] -> [-1 a+b b]
[       Move one stack left, taking top of stack with you (removing the top b)
:       Swap top two, putting the 1 on this stack on top again

The final > in the template then moves us back to the input stack, where a+b is outputted.


问:
Print a Lego piece
This challenge is a simple ascii-art one. Given two inputs, describing the height and width of a Lego piece, you have print an ASCII art representation of it.

Here is how the Lego pieces are supposed to look:

```<code>(4, 2)

___________
| o o o o |
| o o o o |
-----------

(8, 2)

___________________
| o o o o o o o o |
| o o o o o o o o |
-------------------

(4, 4)

___________
| o o o o |
| o o o o |
| o o o o |
| o o o o |
-----------

(3, 2)

_________
| o o o |
| o o o |
---------

(1, 1)

o
</code>```

If you can't tell from the test-cases, the top and bottom are width*2+3 underscores and dashes, and each row has pipes for the sides, o's for the little things, and everything is separated by spaces.

The only exception for this is (1, 1), which is just a single o.

You will never get 0 for any of the dimensions.

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

var QUESTION_ID=84050,OVERRIDE_USER=31343;function answersUrl(e){return"http://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"http://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

```

答:
JavaScript ECMAScript6 (92 94 91 87 Bytes)

92 Characters

a=(w,h,r='repeat')=>w-h?"__"[r](w)+"__\n"+("|"+" o"[r](w)+" |\n")[r](h)+"--"[r](w)+"---":"o"

Everything below here is Correct

94 Characters

a=(w,h,r='repeat')=>w*h-1?"__"[r](w)+"__\n"+("|"+" o"[r](w)+" |\n")[r](h)+"--"[r](w)+"---":"o"

91 Characters

a=(w,h)=>w*h-1?`${"__"[r='repeat'](w)}__\n`+('|'+" o"[r](w)+' |\n')[r](h)+"-"[r](w*2+3):"o"

87 Characters (Smallest so Far)

```<code>a=(w,h)=>w*h-1?'__'[r='repeat'](w)+`__
`+('|'+' o'[r](w)+` |
`)[r](h)+'-'[r](w*2+3):'o'
</code>```

I took what I learned from the other JavaScript Submissions and made it a lot smaller by writing mine from scratch and then working my way down, turns out you don't need any console.log or alert as by default it will push it to the console when there is an output

I am still working on it to see if I can make it smaller yet

Title: Print a Lego piece

Body:
JavaScript ECMAScript6 (92 94 91 87 Bytes)

92 Characters

a=(w,h,r='repeat')=>w-h?"__"[r](w)+"__\n"+("|"+" o"[r](w)+" |\n")[r](h)+"--"[r](w)+"---":"o"

Everything below here is Correct

94 Characters

a=(w,h,r='repeat')=>w*h-1?"__"[r](w)+"__\n"+("|"+" o"[r](w)+" |\n")[r](h)+"--"[r](w)+"---":"o"

91 Characters

a=(w,h)=>w*h-1?`${"__"[r='repeat'](w)}__\n`+('|'+" o"[r](w)+' |\n')[r](h)+"-"[r](w*2+3):"o"

87 Characters (Smallest so Far)

a=(w,h)=>w*h-1?'__'[r='repeat'](w)+`__
`+('|'+' o'[r](w)+` |
`)[r](h)+'-'[r](w*2+3):'o'

I took what I learned from the other JavaScript Submissions and made it a lot smaller by writing mine from scratch and then working my way down, turns out you don't need any console.log or alert as by default it will push it to the console when there is an output

I am still working on it to see if I can make it smaller yet


问:
Use 16 colors while writing Hey! 4 times
i.e each byte appears in a different ANSI shell colour.

Rules

Resetting the color of the shell after output is not required

Must be output in STDOUT or the primary colour text output of your language.

Must be done programmatically (iterating through each color and letter of the string induvidually) instead of just writing a fixed string to shell like the reference command.

Must output the same as the reference command:
echo -e '\e[30mH\e[31me\e[32my\e[33m!\e[34mH\e[35me\e[36my\e[37m!\e[90mH\e[91me\e[92my\e[93m!\e[94mH\e[95me\e[96my\e[97m!'
on a recent version of bash (I am using 4.3 installed via Homebrew on OS X) i.e like this:

Obviously colours will vary based on terminal colour scheme.

Scoring

This is code-golf, so lowest bytes wins.

答:
J, 59 bytes

```<code>echo,(u:27 91),"1(16$'Hey!'),.~'m',.~,/30 90":@+/i.8
exit''
</code>```

Save it as a script to run using J. It will print the output to stdout with the escaped colors.

Body:
J, 59 bytes

echo,(u:27 91),"1(16$'Hey!'),.~'m',.~,/30 90":@+/i.8
exit''

Save it as a script to run using J. It will print the output to stdout with the escaped colors.


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

-- borrowed from marcog's idea ;)

答:
Use C# lambda. Since PPCG allows lambda for input/output we should use them.

A classic C# methods looks like this:

```<code>bool Has(string s, char c)
{
    return s.Contains(c);
}
</code>```

As a lambda, we will write

```<code>Func<string, char, bool> Has = (s, c) => s.Contains(c);
</code>```

Anonymous lambda are allowed too:

```<code>(s, c) => s.Contains(c)
</code>```

Remove all the noise and focus!

Update:

We can improve one step more with currying as @TheLethalCoder comment:

```<code>s => c => s.Contains(c);
</code>```

Example of curring by @Felix Palmen: How compute WPA key?

It will be helpful when you have exactly 2 parameters, then a empty unused variable _ will be better. See meta post about this. I use this trick here. You will have to change a bit the function. Example: Try it online!

ContentLicense: CC BY-SA 2.5

Title: Tips for code-golfing in C#

Body:
Use C# lambda. Since PPCG allows lambda for input/output we should use them.

A classic C# methods looks like this:

bool Has(string s, char c)
{
    return s.Contains(c);
}

As a lambda, we will write

Func<string, char, bool> Has = (s, c) => s.Contains(c);

Anonymous lambda are allowed too:

(s, c) => s.Contains(c)

Remove all the noise and focus!

Update:

We can improve one step more with currying as @TheLethalCoder comment:

s => c => s.Contains(c);

Example of curring by @Felix Palmen: How compute WPA key?

It will be helpful when you have exactly 2 parameters, then a empty unused variable _ will be better. See meta post about this. I use this trick here. You will have to change a bit the function. Example: Try it online!


答:
Octave, 78 bytes

c=[b=[a="\x1b[30m"' a a a;'Hey!'] b];c(4,:)+=0:7;d=c;d(3,:)+=6;disp([c d](:)')
```
<p>Usage:</p>
<p>If the code is in a file <code>hey.m</code>:</p>
```$ octave hey.m
Hey!Hey!Hey!Hey!
```

Title: Use 16 colors while writing Hey! 4 times

Body:
i.e each byte appears in a different ANSI shell colour.

Rules

Resetting the color of the shell after output is not required

Must be output in STDOUT or the primary colour text output of your language.

Must be done programmatically (iterating through each color and letter of the string induvidually) instead of just writing a fixed string to shell like the reference command.

Must output the same as the reference command:
echo -e '\e[30mH\e[31me\e[32my\e[33m!\e[34mH\e[35me\e[36my\e[37m!\e[90mH\e[91me\e[92my\e[93m!\e[94mH\e[95me\e[96my\e[97m!'
on a recent version of bash (I am using 4.3 installed via Homebrew on OS X) i.e like this:

Obviously colours will vary based on terminal colour scheme.

Scoring

This is code-golf, so lowest bytes wins.

Body:
Octave, 78 bytes

c=[b=[a="\x1b[30m"' a a a;'Hey!'] b];c(4,:)+=0:7;d=c;d(3,:)+=6;disp([c d](:)')

Usage:

If the code is in a file hey.m:

$ octave hey.m
Hey!Hey!Hey!Hey!


答:
Java, 259 bytes

```<code>for (i=0;i<in.length();i++)
{
if(Character.isLowerCase(in.charAt(i))){
o=o+in.charAt(i)+Character.toUpperCase(in.charAt(i));}
else if(Character.isUpperCase(in.charAt(i))){o=o+in.charAt(i)+Character.toLowerCase(in.charAt(i));}
else {o=o+in.charAt(i);}}
</code>```

Title: Duplicate & switch case

Body:
The goal is, having taken a string as input, duplicate each latin letter and "toggle" its case (i.e. uppercase becomes lowercase and vice-versa).

Example inputs & outputs:

```<code>Input      Output
bad        bBaAdD
Nice       NniIcCeE
T e S t    Tt eE Ss tT
s E t      sS Ee tT
1!1!1st!   1!1!1sStT!
n00b       nN00bB
(e.g.)     (eE.gG.)
H3l|@!     Hh3lL|@!
</code>```

The input consists of printable ASCII symbols.

You shouldn't duplicate non-latin letters, numbers, special chars.

Body:
Java, 259 bytes

for (i=0;i<in.length();i++)
{
if(Character.isLowerCase(in.charAt(i))){
o=o+in.charAt(i)+Character.toUpperCase(in.charAt(i));}
else if(Character.isUpperCase(in.charAt(i))){o=o+in.charAt(i)+Character.toLowerCase(in.charAt(i));}
else {o=o+in.charAt(i);}}


问:
Do not repeat yourself
Inspired by this challenge

Given a number m, output a program that prints out the string Do not repeat yourself.

Now for the challenging part: Each program the original code prints out has to have the byte at place m*n be the same as m*n + 1 and the same as m*n + 2 .... all the way down to m*n + m - 1.

(In case you can't tell, that means it has to be blocks of identical bytes m long)

Example (that only demonstrates the repetition rule, not the output):

```<code>2

aassdd

3

mmmyyy   nnnaaammmeee   iiisssfffrrreeeddd

27

111111111111111111111111111
</code>```

##Scoring:

Your program's score is the x / (min(y, 10)^3), where y is the number of correct programs it outputs, and x is the sum of the lengths of all of the correct programs it outputs and y > 1.  Lowest score wins.

##Other notes:

Your code doesn't have to fulfill any such restrictions on letters repeating.

Your programs (that you output) cannot take input of any sort.

The input will always be a positive integer greater than 1.

Your code needs to work for at least one integer greater than 1.

答:
ferNANDo, 8745/103 = 8.745

```<code>7 - - - - D C B A
- - - - E D C B A

T D D
U E E
D T U
T B E
U C C
C T U
T B E
U B T
V E T
B U V

A A
I A A
I I
T I B
U I T
V T B
B U V
J I B
J J
T J C
U J T
V T C
C U V
I J C
I I
T I D
U I T
V T D
D U V

3
5 5
AD D D
AC C C
AB B B
AA A A
AD
AC
AB
AA
0 0 7 5 0 5 5 5
AA AA
AA
AB AB
AB
AC AC
AC
AD AD
AD
3 5
3
5 5

3
5 5
2 5 5
AH D D
AG C C
AF B B
AE A A
AH
AG
AF
AE
0 0 2 2 5 0 7 2
AE AE
AE
AF AF
AF
AG AG
AG
AH AH
AH
3 5
3
5 5

3
5 5
AL D D
AK C C
AJ B B
AI A A
AL
AK
AJ
AI
0 0 7 5 0 5 0 5
AI AI
AI
AJ AJ
AJ
AK AK
AK
AL AL
AL
3 5
3
5 5

3
4 3 3
AP D D
AO C C
AN B B
AM A A
AP
AO
AN
AM
0 0 3 2 4 2 4 0
AM AM
AM
AN AN
AN
AO AO
AO
AP AP
AP
2 2
3 2
3
2 2

3
5 5
AT D D
AS C C
AR B B
AQ A A
AT
AS
AR
AQ
0 0 7 5 0 0 5 5
AQ AQ
AQ
AR AR
AR
AS AS
AS
AT AT
AT
3 5
3
5 5

3
4 3 3
AX D D
AW C C
AV B B
AU A A
AX
AW
AV
AU
0 0 3 2 4 0 4 0
AU AU
AU
AV AV
AV
AW AW
AW
AX AX
AX
2 2
3 2
3
2 2

3
5 5
4 3 3
BB D D
BA C C
AZ B B
AY A A
BB
BA
AZ
AY
0 0 7 5 0 4 5 5
AY AY
AY
AZ AZ
AZ
BA BA
BA
BB BB
BB
3 5
3
5 5

3
BF D D
BE C C
BD B B
BC A A
BF
BE
BD
BC
0 0 7 2 0 0 2 2
BC BC
BC
BD BD
BD
BE BE
BE
BF BF
BF
2 2
3 2
3
2 2

3
5 5
4 3 3
BJ D D
BI C C
BH B B
BG A A
BJ
BI
BH
BG
0 0 7 5 0 1 0 4
BG BG
BG
BH BH
BH
BI BI
BI
BJ BJ
BJ
1 5 5
3 5
3
5 5

3
BN D D
BM C C
BL B B
BK A A
BN
BM
BL
BK
0 0 7 2 0 0 2 0
BK BK
BK
BL BL
BL
BM BM
BM
BN BN
BN
2 2
3 2
3
2 2

3
5 5
4 3 3
2 5 5
BR D D
BQ C C
BP B B
BO A A
BR
BQ
BP
BO
0 0 5 5 2 0 2 4
BO BO
BO
BP BP
BP
BQ BQ
BQ
BR BR
BR
3 5
3
5 5

3
BV D D
BU C C
BT B B
BS A A
BV
BU
BT
BS
0 0 7 2 0 2 2 2
BS BS
BS
BT BT
BT
BU BU
BU
BV BV
BV
2 2
3 2
3
2 2

3
5 5
4 3 3
BZ D D
BY C C
BX B B
BW A A
BZ
BY
BX
BW
0 0 7 5 0 4 4 4
BW BW
BW
BX BX
BX
BY BY
BY
BZ BZ
BZ
3 5
3
5 5

3
CD D D
CC C C
CB B B
CA A A
CD
CC
CB
CA
0 0 7 2 0 2 0 2
CA CA
CA
CB CB
CB
CC CC
CC
CD CD
CD
2 2
3 2
3
2 2

3
5 5
4 3 3
CH D D
CG C C
CF B B
CE A A
CH
CG
CF
CE
0 0 7 5 0 5 4 5
CE CE
CE
CF CF
CF
CG CG
CG
CH CH
CH
3 5
3
5 5

3
5 5
6 5
2 5 5
CL D D
CK C C
CJ B B
CI A A
CL
CK
CJ
CI
0 0 6 2 1 2 3 2
CI CI
CI
CJ CJ
CJ
CK CK
CK
CL CL
CL
1 5 5
3 5
3
5 5

3
5 5
CP D D
CO C C
CN B B
CM A A
CP
CO
CN
CM
0 0 7 5 0 0 1 1
CM CM
CM
CN CN
CN
CO CO
CO
CP CP
CP
1 5 5
3 5
3
5 5

3
CT D D
CS C C
CR B B
CQ A A
CT
CS
CR
CQ
0 0 7 2 0 2 2 2
CQ CQ
CQ
CR CR
CR
CS CS
CS
CT CT
CT
2 2
3 2
3
2 2

3
5 5
4 3 3
CX D D
CW C C
CV B B
CU A A
CX
CW
CV
CU
0 0 7 5 0 0 4 4
CU CU
CU
CV CV
CV
CW CW
CW
CX CX
CX
3 5
3
5 5

3
DB D D
DA C C
CZ B B
CY A A
DB
DA
CZ
CY
0 0 7 2 0 0 0 2
CY CY
CY
CZ CZ
CZ
DA DA
DA
DB DB
DB
2 2
3 2
3
2 2

3
5 5
DF D D
DE C C
DD B B
DC A A
DF
DE
DD
DC
0 0 7 5 0 0 0 1
DC DC
DC
DD DD
DD
DE DE
DE
DF DF
DF
1 5 5
3 5
3
5 5

3
5 5
6 5
4 3 3
2 5 5
DJ D D
DI C C
DH B B
DG A A
DJ
DI
DH
DG
0 0 3 2 4 0 6 2
DG DG
DG
DH DH
DH
DI DI
DI
DJ DJ
DJ
3 5
3
5 5

3
5 5
4 3 3
2 5 5
DN D D
DM C C
DL B B
DK A A
DN
DM
DL
DK
0 0 5 5 2 4 2 4
DK DK
DK
DL DL
DL
DM DM
DM
DN DN
DN
3 5
3
5 5

3
DR D D
DQ C C
DP B B
DO A A
DR
DQ
DP
DO
0 0 7 2 0 2 2 2
DO DO
DO
DP DP
DP
DQ DQ
DQ
DR DR
DR
2 2
3 2
3
2 2

3
5 5
4 3 3
DV D D
DU C C
DT B B
DS A A
DV
DU
DT
DS
0 0 7 5 0 4 4 5
DS DS
DS
DT DT
DT
DU DU
DU
DV DV
DV
3 5
3
5 5

3
DZ D D
DY C C
DX B B
DW A A
DZ
DY
DX
DW
0 0 7 2 0 2 0 0
DW DW
DW
DX DX
DX
DY DY
DY
DZ DZ
DZ
2 2
3 2
3
2 2

3
5 5
4 3 3
ED D D
EC C C
EB B B
EA A A
ED
EC
EB
EA
0 0 7 5 0 1 4 5
EA EA
EA
EB EB
EB
EC EC
EC
ED ED
ED
1 5 5
3 5
3
5 5

3
5 5
6 5
2 5 5
EH D D
EG C C
EF B B
EE A A
EH
EG
EF
EE
0 0 6 2 1 0 3 0
EE EE
EE
EF EF
EF
EG EG
EG
EH EH
EH
1 5 5
3 5
3
5 5

3
5 5
EL D D
EK C C
EJ B B
EI A A
EL
EK
EJ
EI
0 0 7 5 0 1 1 1
EI EI
EI
EJ EJ
EJ
EK EK
EK
EL EL
EL
1 5 5
3 5
3
5 5

3
EP D D
EO C C
EN B B
EM A A
EP
EO
EN
EM
0 0 7 2 0 2 2 2
EM EM
EM
EN EN
EN
EO EO
EO
EP EP
EP
2 2
3 2
3
2 2

3
5 5
4 3 3
ET D D
ES C C
ER B B
EQ A A
ET
ES
ER
EQ
0 0 7 5 0 1 0 4
EQ EQ
EQ
ER ER
ER
ES ES
ES
ET ET
ET
1 5 5
3 5
3
5 5

3
EX D D
EW C C
EV B B
EU A A
EX
EW
EV
EU
0 0 7 2 0 2 0 0
EU EU
EU
EV EV
EV
EW EW
EW
EX EX
EX
2 2
3 2
3
2 2

3
5 5
FB D D
FA C C
EZ B B
EY A A
FB
FA
EZ
EY
0 0 7 5 0 5 1 5
EY EY
EY
EZ EZ
EZ
FA FA
FA
FB FB
FB
1 5 5
3 5
3
5 5

3
4 3 3
FF D D
FE C C
FD B B
FC A A
FF
FE
FD
FC
0 0 3 2 4 0 4 0
FC FC
FC
FD FD
FD
FE FE
FE
FF FF
FF
2 2
3 2
3
2 2

3
5 5
FJ D D
FI C C
FH B B
FG A A
FJ
FI
FH
FG
0 0 7 5 0 5 5 5
FG FG
FG
FH FH
FH
FI FI
FI
FJ FJ
FJ
3 5
3
5 5

3
FN D D
FM C C
FL B B
FK A A
FN
FM
FL
FK
0 0 7 2 0 0 2 2
FK FK
FK
FL FL
FL
FM FM
FM
FN FN
FN
2 2
3 2
3
2 2

3
5 5
FR D D
FQ C C
FP B B
FO A A
FR
FQ
FP
FO
0 0 7 5 0 1 1 1
FO FO
FO
FP FP
FP
FQ FQ
FQ
FR FR
FR
1 5 5
3 5
3
5 5

3
FV D D
FU C C
FT B B
FS A A
FV
FU
FT
FS
0 0 7 2 0 0 0 0
FS FS
FS
FT FT
FT
FU FU
FU
FV FV
FV
2 2
3 2
3
2 2

3
5 5
4 3 3
2 5 5
FZ D D
FY C C
FX B B
FW A A
FZ
FY
FX
FW
0 0 5 5 2 0 2 4
FW FW
FW
FX FX
FX
FY FY
FY
FZ FZ
FZ
3 5
3
5 5

3
GD D D
GC C C
GB B B
GA A A
GD
GC
GB
GA
0 0 7 2 0 0 0 2
GA GA
GA
GB GB
GB
GC GC
GC
GD GD
GD
2 2
3 2
3
2 2

3
5 5
4 3 3
GH D D
GG C C
GF B B
GE A A
GH
GG
GF
GE
0 0 7 5 0 4 4 4
GE GE
GE
GF GF
GF
GG GG
GG
GH GH
GH
3 5
3
5 5

3
GL D D
GK C C
GJ B B
GI A A
GL
GK
GJ
GI
0 0 7 2 0 0 0 2
GI GI
GI
GJ GJ
GJ
GK GK
GK
GL GL
GL
2 2
3 2
3
2 2

3
5 5
4 3 3
GP D D
GO C C
GN B B
GM A A
GP
GO
GN
GM
0 0 7 5 0 0 0 4
GM GM
GM
GN GN
GN
GO GO
GO
GP GP
GP
3 5
3
5 5

3
5 5
6 5
2 5 5
GT D D
GS C C
GR B B
GQ A A
GT
GS
GR
GQ
0 0 6 2 1 0 1 0
GQ GQ
GQ
GR GR
GR
GS GS
GS
GT GT
GT
1 5 5
3 5
3
5 5

3
5 5
GX D D
GW C C
GV B B
GU A A
GX
GW
GV
GU
0 0 7 5 0 1 0 5
GU GU
GU
GV GV
GV
GW GW
GW
GX GX
GX
1 5 5
3 5
3
5 5

3
5 5
6 5
2 5 5
HB D D
HA C C
GZ B B
GY A A
HB
HA
GZ
GY
0 0 6 2 1 2 1 2
GY GY
GY
GZ GZ
GZ
HA HA
HA
HB HB
HB
1 5 5
3 5
3
5 5

3
5 5
HF D D
HE C C
HD B B
HC A A
HF
HE
HD
HC
0 0 7 5 0 0 5 0
HC HC
HC
HD HD
HD
HE HE
HE
HF HF
HF
3 5
3
5 5

3
5 5
2 5 5
HJ D D
HI C C
HH B B
HG A A
HJ
HI
HH
HG
0 0 2 2 5 0 7 2
HG HG
HG
HH HH
HH
HI HI
HI
HJ HJ
HJ
3 5
3
5 5

3
5 5
HN D D
HM C C
HL B B
HK A A
HN
HM
HL
HK
0 0 7 5 0 1 1 1
HK HK
HK
HL HL
HL
HM HM
HM
HN HN
HN
1 5 5
3 5
3
5 5

3
HR D D
HQ C C
HP B B
HO A A
HR
HQ
HP
HO
0 0 7 2 0 2 2 2
HO HO
HO
HP HP
HP
HQ HQ
HQ
HR HR
HR
2 2
3 2
3
2 2

3
5 5
HV D D
HU C C
HT B B
HS A A
HV
HU
HT
HS
0 0 7 5 0 0 0 0
HS HS
HS
HT HT
HT
HU HU
HU
HV HV
HV
3 5
3
5 5

3
HZ D D
HY C C
HX B B
HW A A
HZ
HY
HX
HW
0 0 7 2 0 2 2 2
HW HW
HW
HX HX
HX
HY HY
HY
HZ HZ
HZ
2 2
3 2
3
2 2

3
5 5
4 3 3
ID D D
IC C C
IB B B
IA A A
ID
IC
IB
IA
0 0 7 5 0 4 4 4
IA IA
IA
IB IB
IB
IC IC
IC
ID ID
ID
3 5
3
</code>```

Works for all inputs 1 through 15, 1 through 10 are counted in the score.

Update: reduced the size of the generator from ~16k down to 6.1k.

Sample output for m=3:

```<code>777   777

333

555   555

444   333   333

000   777   333   333   111   444   222   111

000   777   777   000   555   777   555   777

000   333   777   333   000   111   000   111

333   555

000   777   777   111   444   333   555   222

000   777   777   111   444   444   555   777

000   777   777   333   000   777   000   111

000   111   777   000   111   111   000   000

111   555   555

222   222

333

000   777   777   000   000   777   777   000
</code>```

Title: Do not repeat yourself

Body:
ferNANDo, 8745/103 = 8.745

7 - - - - D C B A
- - - - E D C B A

T D D
U E E
D T U
T B E
U C C
C T U
T B E
U B T
V E T
B U V

A A
I A A
I I
T I B
U I T
V T B
B U V
J I B
J J
T J C
U J T
V T C
C U V
I J C
I I
T I D
U I T
V T D
D U V

3
5 5
AD D D
AC C C
AB B B
AA A A
AD
AC
AB
AA
0 0 7 5 0 5 5 5
AA AA
AA
AB AB
AB
AC AC
AC
AD AD
AD
3 5
3
5 5

3
5 5
2 5 5
AH D D
AG C C
AF B B
AE A A
AH
AG
AF
AE
0 0 2 2 5 0 7 2
AE AE
AE
AF AF
AF
AG AG
AG
AH AH
AH
3 5
3
5 5

3
5 5
AL D D
AK C C
AJ B B
AI A A
AL
AK
AJ
AI
0 0 7 5 0 5 0 5
AI AI
AI
AJ AJ
AJ
AK AK
AK
AL AL
AL
3 5
3
5 5

3
4 3 3
AP D D
AO C C
AN B B
AM A A
AP
AO
AN
AM
0 0 3 2 4 2 4 0
AM AM
AM
AN AN
AN
AO AO
AO
AP AP
AP
2 2
3 2
3
2 2

3
5 5
AT D D
AS C C
AR B B
AQ A A
AT
AS
AR
AQ
0 0 7 5 0 0 5 5
AQ AQ
AQ
AR AR
AR
AS AS
AS
AT AT
AT
3 5
3
5 5

3
4 3 3
AX D D
AW C C
AV B B
AU A A
AX
AW
AV
AU
0 0 3 2 4 0 4 0
AU AU
AU
AV AV
AV
AW AW
AW
AX AX
AX
2 2
3 2
3
2 2

3
5 5
4 3 3
BB D D
BA C C
AZ B B
AY A A
BB
BA
AZ
AY
0 0 7 5 0 4 5 5
AY AY
AY
AZ AZ
AZ
BA BA
BA
BB BB
BB
3 5
3
5 5

3
BF D D
BE C C
BD B B
BC A A
BF
BE
BD
BC
0 0 7 2 0 0 2 2
BC BC
BC
BD BD
BD
BE BE
BE
BF BF
BF
2 2
3 2
3
2 2

3
5 5
4 3 3
BJ D D
BI C C
BH B B
BG A A
BJ
BI
BH
BG
0 0 7 5 0 1 0 4
BG BG
BG
BH BH
BH
BI BI
BI
BJ BJ
BJ
1 5 5
3 5
3
5 5

3
BN D D
BM C C
BL B B
BK A A
BN
BM
BL
BK
0 0 7 2 0 0 2 0
BK BK
BK
BL BL
BL
BM BM
BM
BN BN
BN
2 2
3 2
3
2 2

3
5 5
4 3 3
2 5 5
BR D D
BQ C C
BP B B
BO A A
BR
BQ
BP
BO
0 0 5 5 2 0 2 4
BO BO
BO
BP BP
BP
BQ BQ
BQ
BR BR
BR
3 5
3
5 5

3
BV D D
BU C C
BT B B
BS A A
BV
BU
BT
BS
0 0 7 2 0 2 2 2
BS BS
BS
BT BT
BT
BU BU
BU
BV BV
BV
2 2
3 2
3
2 2

3
5 5
4 3 3
BZ D D
BY C C
BX B B
BW A A
BZ
BY
BX
BW
0 0 7 5 0 4 4 4
BW BW
BW
BX BX
BX
BY BY
BY
BZ BZ
BZ
3 5
3
5 5

3
CD D D
CC C C
CB B B
CA A A
CD
CC
CB
CA
0 0 7 2 0 2 0 2
CA CA
CA
CB CB
CB
CC CC
CC
CD CD
CD
2 2
3 2
3
2 2

3
5 5
4 3 3
CH D D
CG C C
CF B B
CE A A
CH
CG
CF
CE
0 0 7 5 0 5 4 5
CE CE
CE
CF CF
CF
CG CG
CG
CH CH
CH
3 5
3
5 5

3
5 5
6 5
2 5 5
CL D D
CK C C
CJ B B
CI A A
CL
CK
CJ
CI
0 0 6 2 1 2 3 2
CI CI
CI
CJ CJ
CJ
CK CK
CK
CL CL
CL
1 5 5
3 5
3
5 5

3
5 5
CP D D
CO C C
CN B B
CM A A
CP
CO
CN
CM
0 0 7 5 0 0 1 1
CM CM
CM
CN CN
CN
CO CO
CO
CP CP
CP
1 5 5
3 5
3
5 5

3
CT D D
CS C C
CR B B
CQ A A
CT
CS
CR
CQ
0 0 7 2 0 2 2 2
CQ CQ
CQ
CR CR
CR
CS CS
CS
CT CT
CT
2 2
3 2
3
2 2

3
5 5
4 3 3
CX D D
CW C C
CV B B
CU A A
CX
CW
CV
CU
0 0 7 5 0 0 4 4
CU CU
CU
CV CV
CV
CW CW
CW
CX CX
CX
3 5
3
5 5

3
DB D D
DA C C
CZ B B
CY A A
DB
DA
CZ
CY
0 0 7 2 0 0 0 2
CY CY
CY
CZ CZ
CZ
DA DA
DA
DB DB
DB
2 2
3 2
3
2 2

3
5 5
DF D D
DE C C
DD B B
DC A A
DF
DE
DD
DC
0 0 7 5 0 0 0 1
DC DC
DC
DD DD
DD
DE DE
DE
DF DF
DF
1 5 5
3 5
3
5 5

3
5 5
6 5
4 3 3
2 5 5
DJ D D
DI C C
DH B B
DG A A
DJ
DI
DH
DG
0 0 3 2 4 0 6 2
DG DG
DG
DH DH
DH
DI DI
DI
DJ DJ
DJ
3 5
3
5 5

3
5 5
4 3 3
2 5 5
DN D D
DM C C
DL B B
DK A A
DN
DM
DL
DK
0 0 5 5 2 4 2 4
DK DK
DK
DL DL
DL
DM DM
DM
DN DN
DN
3 5
3
5 5

3
DR D D
DQ C C
DP B B
DO A A
DR
DQ
DP
DO
0 0 7 2 0 2 2 2
DO DO
DO
DP DP
DP
DQ DQ
DQ
DR DR
DR
2 2
3 2
3
2 2

3
5 5
4 3 3
DV D D
DU C C
DT B B
DS A A
DV
DU
DT
DS
0 0 7 5 0 4 4 5
DS DS
DS
DT DT
DT
DU DU
DU
DV DV
DV
3 5
3
5 5

3
DZ D D
DY C C
DX B B
DW A A
DZ
DY
DX
DW
0 0 7 2 0 2 0 0
DW DW
DW
DX DX
DX
DY DY
DY
DZ DZ
DZ
2 2
3 2
3
2 2

3
5 5
4 3 3
ED D D
EC C C
EB B B
EA A A
ED
EC
EB
EA
0 0 7 5 0 1 4 5
EA EA
EA
EB EB
EB
EC EC
EC
ED ED
ED
1 5 5
3 5
3
5 5

3
5 5
6 5
2 5 5
EH D D
EG C C
EF B B
EE A A
EH
EG
EF
EE
0 0 6 2 1 0 3 0
EE EE
EE
EF EF
EF
EG EG
EG
EH EH
EH
1 5 5
3 5
3
5 5

3
5 5
EL D D
EK C C
EJ B B
EI A A
EL
EK
EJ
EI
0 0 7 5 0 1 1 1
EI EI
EI
EJ EJ
EJ
EK EK
EK
EL EL
EL
1 5 5
3 5
3
5 5

3
EP D D
EO C C
EN B B
EM A A
EP
EO
EN
EM
0 0 7 2 0 2 2 2
EM EM
EM
EN EN
EN
EO EO
EO
EP EP
EP
2 2
3 2
3
2 2

3
5 5
4 3 3
ET D D
ES C C
ER B B
EQ A A
ET
ES
ER
EQ
0 0 7 5 0 1 0 4
EQ EQ
EQ
ER ER
ER
ES ES
ES
ET ET
ET
1 5 5
3 5
3
5 5

3
EX D D
EW C C
EV B B
EU A A
EX
EW
EV
EU
0 0 7 2 0 2 0 0
EU EU
EU
EV EV
EV
EW EW
EW
EX EX
EX
2 2
3 2
3
2 2

3
5 5
FB D D
FA C C
EZ B B
EY A A
FB
FA
EZ
EY
0 0 7 5 0 5 1 5
EY EY
EY
EZ EZ
EZ
FA FA
FA
FB FB
FB
1 5 5
3 5
3
5 5

3
4 3 3
FF D D
FE C C
FD B B
FC A A
FF
FE
FD
FC
0 0 3 2 4 0 4 0
FC FC
FC
FD FD
FD
FE FE
FE
FF FF
FF
2 2
3 2
3
2 2

3
5 5
FJ D D
FI C C
FH B B
FG A A
FJ
FI
FH
FG
0 0 7 5 0 5 5 5
FG FG
FG
FH FH
FH
FI FI
FI
FJ FJ
FJ
3 5
3
5 5

3
FN D D
FM C C
FL B B
FK A A
FN
FM
FL
FK
0 0 7 2 0 0 2 2
FK FK
FK
FL FL
FL
FM FM
FM
FN FN
FN
2 2
3 2
3
2 2

3
5 5
FR D D
FQ C C
FP B B
FO A A
FR
FQ
FP
FO
0 0 7 5 0 1 1 1
FO FO
FO
FP FP
FP
FQ FQ
FQ
FR FR
FR
1 5 5
3 5
3
5 5

3
FV D D
FU C C
FT B B
FS A A
FV
FU
FT
FS
0 0 7 2 0 0 0 0
FS FS
FS
FT FT
FT
FU FU
FU
FV FV
FV
2 2
3 2
3
2 2

3
5 5
4 3 3
2 5 5
FZ D D
FY C C
FX B B
FW A A
FZ
FY
FX
FW
0 0 5 5 2 0 2 4
FW FW
FW
FX FX
FX
FY FY
FY
FZ FZ
FZ
3 5
3
5 5

3
GD D D
GC C C
GB B B
GA A A
GD
GC
GB
GA
0 0 7 2 0 0 0 2
GA GA
GA
GB GB
GB
GC GC
GC
GD GD
GD
2 2
3 2
3
2 2

3
5 5
4 3 3
GH D D
GG C C
GF B B
GE A A
GH
GG
GF
GE
0 0 7 5 0 4 4 4
GE GE
GE
GF GF
GF
GG GG
GG
GH GH
GH
3 5
3
5 5

3
GL D D
GK C C
GJ B B
GI A A
GL
GK
GJ
GI
0 0 7 2 0 0 0 2
GI GI
GI
GJ GJ
GJ
GK GK
GK
GL GL
GL
2 2
3 2
3
2 2

3
5 5
4 3 3
GP D D
GO C C
GN B B
GM A A
GP
GO
GN
GM
0 0 7 5 0 0 0 4
GM GM
GM
GN GN
GN
GO GO
GO
GP GP
GP
3 5
3
5 5

3
5 5
6 5
2 5 5
GT D D
GS C C
GR B B
GQ A A
GT
GS
GR
GQ
0 0 6 2 1 0 1 0
GQ GQ
GQ
GR GR
GR
GS GS
GS
GT GT
GT
1 5 5
3 5
3
5 5

3
5 5
GX D D
GW C C
GV B B
GU A A
GX
GW
GV
GU
0 0 7 5 0 1 0 5
GU GU
GU
GV GV
GV
GW GW
GW
GX GX
GX
1 5 5
3 5
3
5 5

3
5 5
6 5
2 5 5
HB D D
HA C C
GZ B B
GY A A
HB
HA
GZ
GY
0 0 6 2 1 2 1 2
GY GY
GY
GZ GZ
GZ
HA HA
HA
HB HB
HB
1 5 5
3 5
3
5 5

3
5 5
HF D D
HE C C
HD B B
HC A A
HF
HE
HD
HC
0 0 7 5 0 0 5 0
HC HC
HC
HD HD
HD
HE HE
HE
HF HF
HF
3 5
3
5 5

3
5 5
2 5 5
HJ D D
HI C C
HH B B
HG A A
HJ
HI
HH
HG
0 0 2 2 5 0 7 2
HG HG
HG
HH HH
HH
HI HI
HI
HJ HJ
HJ
3 5
3
5 5

3
5 5
HN D D
HM C C
HL B B
HK A A
HN
HM
HL
HK
0 0 7 5 0 1 1 1
HK HK
HK
HL HL
HL
HM HM
HM
HN HN
HN
1 5 5
3 5
3
5 5

3
HR D D
HQ C C
HP B B
HO A A
HR
HQ
HP
HO
0 0 7 2 0 2 2 2
HO HO
HO
HP HP
HP
HQ HQ
HQ
HR HR
HR
2 2
3 2
3
2 2

3
5 5
HV D D
HU C C
HT B B
HS A A
HV
HU
HT
HS
0 0 7 5 0 0 0 0
HS HS
HS
HT HT
HT
HU HU
HU
HV HV
HV
3 5
3
5 5

3
HZ D D
HY C C
HX B B
HW A A
HZ
HY
HX
HW
0 0 7 2 0 2 2 2
HW HW
HW
HX HX
HX
HY HY
HY
HZ HZ
HZ
2 2
3 2
3
2 2

3
5 5
4 3 3
ID D D
IC C C
IB B B
IA A A
ID
IC
IB
IA
0 0 7 5 0 4 4 4
IA IA
IA
IB IB
IB
IC IC
IC
ID ID
ID
3 5
3

Works for all inputs 1 through 15, 1 through 10 are counted in the score.

Update: reduced the size of the generator from ~16k down to 6.1k.

Sample output for m=3:

777   777

333

555   555

444   333   333

000   777   333   333   111   444   222   111

000   777   777   000   555   777   555   777

000   333   777   333   000   111   000   111

333   555

000   777   777   111   444   333   555   222

000   777   777   111   444   444   555   777

000   777   777   333   000   777   000   111

000   111   777   000   111   111   000   000

111   555   555

222   222

333

000   777   777   000   000   777   777   000


答:
Bash, 62

h=y!He
for i in {3,9}{0..7};do printf \\e[${i}m${h:i%4:1};done
```

Must be run from an actual script file.  If you want to try it from the command line, you'll need to escape the !, i.e. h=y\!He

Online.

Body:
Bash, 62

h=y!He
for i in {3,9}{0..7};do printf \\e[${i}m${h:i%4:1};done

Must be run from an actual script file.  If you want to try it from the command line, you'll need to escape the !, i.e. h=y\!He

Online.


答:
APL (Dyalog), <s>38</s> 41 bytes

Now returns right result too!

∊(⍕¨∊29 89∘.+⍳8){'\e[',⍺,'m',⍵}¨16⍴'Hey!'
```

Try it online!

16⍴'Hey!' cyclically reshape the string to length 16

(…){…}¨ apply the below anonymous function to each letter pairing it with the corresponding element for this list as left argument:

 ⍳8 1 through 8

 29 89∘.+ addition table with these numbers vertically and those horizontally

 ∊ ϵnlist (flatten)

 ⍕¨ format (stringify) each

 'm',⍵ prepend an "m"

 ⍺, prepend the left argument

 '\e[', prepend the string

∊ ϵnlist (flatten)

Body:
APL (Dyalog), <s>38</s> 41 bytes

Now returns right result too!

∊(⍕¨∊29 89∘.+⍳8){'\e[',⍺,'m',⍵}¨16⍴'Hey!'

Try it online!

16⍴'Hey!' cyclically reshape the string to length 16

(…){…}¨ apply the below anonymous function to each letter pairing it with the corresponding element for this list as left argument:

 ⍳8 1 through 8

 29 89∘.+ addition table with these numbers vertically and those horizontally

 ∊ ϵnlist (flatten)

 ⍕¨ format (stringify) each

 'm',⍵ prepend an "m"

 ⍺, prepend the left argument

 '\e[', prepend the string

∊ ϵnlist (flatten)


答:
Cheddar, <s>118</s> 104 bytes

```<code>(s)->s.chars.map((i)->{if String.letters has i.lower{if i<"a"{i+i.lower}else{i+i.upper}}else{i}}).join()
</code>```

First real Cheddar answer!!! This is a lot less climactic than I thought it would be... ;_;

Works with release 1.0.0-beta.9, non-competing.

As you can tell I didn't design cheddar to be golfy :/

Ungolfed:

```<code>(str) -> str.chars.map(
    (i) -> {
        if String.letters has i {
            if i < "a" { // Check char code, meaning it's upper case if true
                i+i.lower
            }
            else {
                i+i.upper
            }
        } else {
            i
        }
    }
).join()
</code>```

Usage:

```<code>var doThing = <code here>;
doThing("input...");
</code>```

Update: 7/14/16 I've finished ternaries making this come down to 84 bytes

Cheddar, 84 bytes

```<code>(s)->s.chars.map((i)->String.letters has i.lower?i<"a"?i+i.lower:i+i.upper:i).join()
</code>```

works as of version v1.0.0-beta.14

Title: Duplicate & switch case

Body:
Cheddar, <s>118</s> 104 bytes

(s)->s.chars.map((i)->{if String.letters has i.lower{if i<"a"{i+i.lower}else{i+i.upper}}else{i}}).join()

First real Cheddar answer!!! This is a lot less climactic than I thought it would be... ;_;

Works with release 1.0.0-beta.9, non-competing.

As you can tell I didn't design cheddar to be golfy :/

Ungolfed:

(str) -> str.chars.map(
    (i) -> {
        if String.letters has i {
            if i < "a" { // Check char code, meaning it's upper case if true
                i+i.lower
            }
            else {
                i+i.upper
            }
        } else {
            i
        }
    }
).join()

Usage:

var doThing = <code here>;
doThing("input...");

Update: 7/14/16 I've finished ternaries making this come down to 84 bytes

Cheddar, 84 bytes

(s)->s.chars.map((i)->String.letters has i.lower?i<"a"?i+i.lower:i+i.upper:i).join()

works as of version v1.0.0-beta.14


问:
Illustrate music beats
You know—they look like this:

source

The goal is to draw a music beats illustration like the following:

```<code>=     =      =
=  =  =      =          =
== = ==   =  ==     = ====
== ====  == ===   = = =======
======== == ====  = ========= =
=================================
</code>```

The rules are:

The width of the illustration is 33 symbols, but if you need—any trailing spaces exceeding this width are allowed.

Each column is made of equals signs (=).

Each column has a random height (the height of the next column shouldn’t depend in any way on the height of the previous column), varying from 1 to 6. It’s also fine if it’s at least possible to get some input with no strict math probability (i.e. some inputs could appear more rarely than others).

A column can’t float above the bottom and have gaps in it.

Since every column has the minimal height of 1, the last row can’t have any gaps either—it always consists of 33 equals signs.

Since it’s possible to have no columns with the height of 6 (it’s all random after all): in this case you don’t need to have a top line made of spaces. Applies to any edge cases of this nature: if suddenly your code provided no columns with the height greater than 1, you don’t need to have additional lines made of spaces above the bottom line.

You don’t take any input.

Title: Illustrate music beats

Body:
Dyalog APL, 14 bytes

⊖⍉↑'='⍴¨⍨?33⍴6

Explanation

33⍴6 33 repetitions of 6

? random integer in range [1,n] for each of the 33 6s

'='⍴¨⍨ equality symbol repeated each of those number of times

↑ convert list of lists to table of rows

⍉ transpose rows into columns, columns into rows

⊖ flip upside down

Example runs

Input is indented six spaces:

      ⊖⍉↑'='⍴¨⍨?33⍴6
=          ==        =      ==
= =    =   ==      ====     ==
= = = ===  ==  === ==== =  ===  =
= = ===== ==== === ==== = ====  =
=== ============== ==== ====== ==
=================================
      ⊖⍉↑'='⍴¨⍨?33⍴6
         =  =  =    =    =
  =      =  =  ==  == == =  =
 === == ==  =  === =======  =
==== == ==  ====== ==========   =
==== ============= ========== = =
=================================
      ⊖⍉↑'='⍴¨⍨?33⍴6
             =    =   =  =
         =   =    =   = == =
=      = =   =    ==  = ==== ===
= = =  = =   =    ==  = ==== ====
=====  = == ==  ============ ====
=================================


答:
Python 3, 81 bytes

```<code>print(*['\33[%sm%s'%(i,'Hey!'[i%4-2])for i in range(30,98)if not 37<i<90],sep='')
</code>```

A full program that prints to STDOUT.

How it works

```<code>for i in range(30,98)...       For all possible colour codes i in [30,97]...
...if not 37<i<90              If i is in the desired range [30,37] or [90,97]...
'\33[%sm%s'%(i,'Hey!'[i%4-2])  ...create a string of the form
                               '\033[{colour code}m{current string character}'...
[...]                          ...and store all strings in a list X
print(*...,sep='')             Print all strings in X with no separating space
</code>```

Try it on CodingGround

Body:
Python 3, 81 bytes

print(*['\33[%sm%s'%(i,'Hey!'[i%4-2])for i in range(30,98)if not 37<i<90],sep='')

A full program that prints to STDOUT.

How it works

for i in range(30,98)...       For all possible colour codes i in [30,97]...
...if not 37<i<90              If i is in the desired range [30,37] or [90,97]...
'\33[%sm%s'%(i,'Hey!'[i%4-2])  ...create a string of the form
                               '\033[{colour code}m{current string character}'...
[...]                          ...and store all strings in a list X
print(*...,sep='')             Print all strings in X with no separating space

Try it on CodingGround


问:
Truncate consecutive character runs to n length

The challenge

Given an input string, and an integer n - truncate any runs of consecutive characters to a maximum of n length. The characters can be anything, including special characters. The function should be case sensitive, and n can range from 0 to infinity.

Example inputs/outputs:

```<code>f("aaaaaaabbbccCCCcc", 2) //"aabbccCCcc"
f("aaabbbc", 1) //"abc"
f("abcdefg", 0) //""
f("aaaaaaabccccccccCCCCCC@", 4) //"aaaabccccCCCC@"
</code>```

Scoring

The scoring is based on the number of bytes used.
Thus

```<code>function f(s,n){return s.replace(new RegExp("(.)\\1{"+n+",}","g"),function(x){return x.substr(0, n);});}
</code>```

would be 104 points.

Happy golfing!

Edit: removed language restriction, but I still would love to see javascript answers

答:
Bash 46 bytes

```<code>read c;sed -r ":l;s/(.)(\1{$c})(.*)/\2\3/;t l"
</code>```

Usage: Enter the number of characters to limit, press enter and enter the string. Ctrl + D to exit sed (send EOF).

Body:
Bash 46 bytes

read c;sed -r ":l;s/(.)(\1{$c})(.*)/\2\3/;t l"

Usage: Enter the number of characters to limit, press enter and enter the string. Ctrl + D to exit sed (send EOF).


答:
Pyke, 25 bytes

```<code>"Hey!"4*F\mo8.D6*3+"["s_
</code>```

Try it here!

```<code>                           - o = 0
"Hey!"4*                   -   "Hey!Hey!Hey!Hey!"
        F                  -  for i in ^:
                           -   stack = [i]
         \m                -   stack.append("m")
           o               -    o += 1
            8.D            -   stack.extend(divmod(^, 8))
               6*3+        -   stack[-1] = stack[-1]*6+3
                   "["     -   stack.append("[\x1b")
                        s  -   stack = sum(stack)
                         _ -  stack = reverse(stack)
                           - print "".join(^)
</code>```

Body:
Pyke, 25 bytes

"Hey!"4*F\mo8.D6*3+"["s_

Try it here!

                           - o = 0
"Hey!"4*                   -   "Hey!Hey!Hey!Hey!"
        F                  -  for i in ^:
                           -   stack = [i]
         \m                -   stack.append("m")
           o               -    o += 1
            8.D            -   stack.extend(divmod(^, 8))
               6*3+        -   stack[-1] = stack[-1]*6+3
                   "["     -   stack.append("[\x1b")
                        s  -   stack = sum(stack)
                         _ -  stack = reverse(stack)
                           - print "".join(^)


答:
Jelly, 14 bytes

```<code>6x33X€”=ẋz⁶Ṛj⁷
</code>```

Try it here.

Title: Illustrate music beats

Body:
You know—they look like this:

source

The goal is to draw a music beats illustration like the following:

```<code>=     =      =
=  =  =      =          =
== = ==   =  ==     = ====
== ====  == ===   = = =======
======== == ====  = ========= =
=================================
</code>```

The rules are:

The width of the illustration is 33 symbols, but if you need—any trailing spaces exceeding this width are allowed.

Each column is made of equals signs (=).

Each column has a random height (the height of the next column shouldn’t depend in any way on the height of the previous column), varying from 1 to 6. It’s also fine if it’s at least possible to get some input with no strict math probability (i.e. some inputs could appear more rarely than others).

A column can’t float above the bottom and have gaps in it.

Since every column has the minimal height of 1, the last row can’t have any gaps either—it always consists of 33 equals signs.

Since it’s possible to have no columns with the height of 6 (it’s all random after all): in this case you don’t need to have a top line made of spaces. Applies to any edge cases of this nature: if suddenly your code provided no columns with the height greater than 1, you don’t need to have additional lines made of spaces above the bottom line.

You don’t take any input.

Body:
Jelly, 14 bytes

6x33X€”=ẋz⁶Ṛj⁷

Try it here.


答:
CJam, 19 bytes

```<code>{5mrS*6'=e]}33*]zN*
</code>```

Try it online!

Explanation

```<code>{       e# 33 times...
  5mr   e#   Push a random number in [0 1 2 3 4 5].
  S*    e#   Create a string with that many spaces.
  6'=e] e#   Pad to length 6 with =.
}33*
]       e# Wrap all 33 strings in a list.
z       e# Transpose that list.
N*      e# Join the lines with linefeeds.
</code>```

Title: Illustrate music beats

Body:
CJam, 19 bytes

{5mrS*6'=e]}33*]zN*

Try it online!

Explanation

{       e# 33 times...
  5mr   e#   Push a random number in [0 1 2 3 4 5].
  S*    e#   Create a string with that many spaces.
  6'=e] e#   Pad to length 6 with =.
}33*
]       e# Wrap all 33 strings in a list.
z       e# Transpose that list.
N*      e# Join the lines with linefeeds.


问:
m3ph1st0s's programming puzzle 1 (C++)
This is the first of a series of C++ puzzles for you. Hope you will enjoy.

So, puzzle no.1:

Given the following program:

```<code>#include <iostream>
int main()
{
   const int a=1;
   const int b=2;
   const float c=0.5;
   std::cout << a/b-a*c;
}
</code>```

Insert some code on a single new line anywhere inside the program so that the output will be 0. The new line will contain AT MOST 18 characters (including spaces), and the rest of the lines will remain unmodified.
 To be clear, here is an example of a valid new code:

```<code>#include <iostream>
int main()
{
   const int a=1;
   const int b=2;
   int* p = NULL;
   const float c=0.5;
   std::cout << a/b-a*c;
}
</code>```

A new line with 15 characters was inserted so it's ok. However it does not solve the problem.

If this is too simple for you, don't worry, more is coming!!

答:
```<code>#include <iostream>
main()
{
   const int a=1;
#define a 0
   const int b=2;
   const float c=0.5;
   std::cout << a/b-a*c;
}
</code>```

1 new line, 12 new chars

Title: m3ph1st0s's programming puzzle 1 (C++)

Body:
#include <iostream>
main()
{
   const int a=1;
#define a 0
   const int b=2;
   const float c=0.5;
   std::cout << a/b-a*c;
}

1 new line, 12 new chars


答:
Pyth, 13 bytes

And I outgolfed Jelly.

```<code>j_.tm*hO6\=33
</code>```

Try it online!

```<code>j_.tm*hO6\=33
    m      33  for 33 times:
       O6          yield a random number in [0,1,2,3,4,5].
      h            add one.
     *   \=        repeat "=" that number of times.
  .t           transpose, filling with whitespace
 _             reverse
j              join by newlines.
</code>```

Title: Illustrate music beats

Body:
Pyth, 13 bytes

And I outgolfed Jelly.

j_.tm*hO6\=33

Try it online!

j_.tm*hO6\=33
    m      33  for 33 times:
       O6          yield a random number in [0,1,2,3,4,5].
      h            add one.
     *   \=        repeat "=" that number of times.
  .t           transpose, filling with whitespace
 _             reverse
j              join by newlines.


问:
Golf a Sentence
Everybody loves golfing code. Code is written in English (eh...). Therefore, everybody loves golfing English!

Your task is to write a program or function that takes a string as input, and then returns or prints the golfed version. There will be no newlines or tabs in the input.

This is how you golf a string. The order matters!

Remove spaces directly before and after punctuation: "Hey there", he said   ; he ' s a cat. -> "Hey there",he said;he's a cat. The following count as punctuation: .,?!"':;()

Replace he/she/it is, case insensitive, with he's/she's/it's: It is unfortunate that she is not coming ever. -> It's unfortunate that she's not coming ever.

Words that start with capital letters in a sentence can be moved against the preceding word (omitting the space): The farmer told Fred that he should leave. -> The farmer toldFred that he should leave.

Trailing and leading spaces should be removed: [      ]It's raining.[     ]-> It's raining. Ignore the brackets (annoying auto-formatting).

Remove repeated punctuation that is the same: ""Here''s the cake",, said Fred..! -> "Here's the cake",saidFred.!

If we were to golf the first paragraph of this challenge, the output would be:

Everybody loves golfing code.Code is written inEnglish(eh.).Therefore,everybody loves golfingEnglish!

This is code golf––or rather English golf––so shortest code in bytes wins!

Here is one all encompassing test case:

Input: "    You are crazy"",, , , she said. It is unfortunate that Margaret had to say that... she is a Martian!.

Output: "You are crazy",she said.It's unfortunate thatMargaret had to say that.she's aMartian!.

答:
<s>Bash 74</s> Sed 65 + 4 bytes

65 bytes for the script and 4 for the r and f flags.

<s>sed -r "s/\s*([.,?\!\"\':;\(\)A-Z])(\1|\s)*/\1/g;s/(he|she|it) is/\1\'s/i"</s>
s/\s*([,.?\!\"\':;\(\)A-Z])(\1|\s)*/\1/g;s/(he|she|it) is/\1\'s/i

Usage: Enter text, press enter and then Ctrl + D (send EOF).

Title: Golf a Sentence


问:
A Peak Experience: Quickly Visit All the Peaks
I am standing at point (0,0) in a H x W map where the altitude is represented by digits, for example:

```<code>1132
2221
1230    # H = 3, W = 4
</code>```

I'd like to experience the views from every peak, which in this case are the areas with altitude 3. However, climbing up hills is not an easy task, and I am also running out of time.

Challenge

The challenge is to find the quickest path to visit all the peaks and come back.

Shortest program wins.

Input

H, W - height and width of the map (Integers) (optional, may be a list/tuple or two separate integer inputs)

The map, given as H sets of W digits (0-9), in any convenient format (2D list, string separated by newlines, etc.)

Output

Shortest time taken to visit every peak and come back to your starting point (Integer)

Conditions

The altitude of a given area is represented by a digit from 0 to 9.

The "peak" is defined by the area with the highest altitude.

The path must both begin and end at the top-left (0,0) area.

You can only move to areas adjacent to your current area, and you may not move diagonally.

It takes 3 minutes to move from one area to another if there is no change in altitude.

It takes 11 minutes to climb up; that is, moving from one area to another area that is exactly 1 unit higher.

It takes 2 minutes to climb down; that is, moving from one area to another area that is exactly 1 unit lower.

You cannot move to areas that are more than 1 unit higher or lower than where you are. (You cannot go from an area with altitude 1 to an adjacent area with altitude, say, 3)

A path to all the peaks is guaranteed

Maximum number of peaks is 15.

Samples

Input

```<code>4 5
32445
33434
21153
12343
</code>```

Output

```<code>96
</code>```

Explanation

You start at the top-left 3. You have to visit the two 5s that are located at (0,4) and (3,3) and come back to the 3 at (0,0) in the shortest time possible.

```<code>3  2  4->4->5
V     ^
3->3->4  3  4

2  1  1  5  3

1  2  3  4  3    # 3 + 3 + 11 + 3 + 3 + 11 = 34 minutes to visit 1st peak

3  2  4  4  5
            V
3  3  4  3  4
            V
2  1  1  5  3
         ^  V
1  2  3  4<-3    # 2 + 2 + 3 + 11 + 11 = 29 minutes to visit 2nd

3  2  4  4  5
^
3  3  4  3  4
^
2  1  1  5  3
^        V
1<-2<-3<-4  3    # 2 + 2 + 2 + 2 + 11 + 11 + 3 = 33 minutes to come back

# 34 + 29 + 33 = 96 minutes total is the answer
</code>```

Input

```<code>2 7
6787778
5777679
</code>```

Output

```<code>75
</code>```

答:
Mathematica <s>745</s> 681 bytes

The basic idea is to make a weighted graph of possible moves. Weights are the time it takes to move from one place to the next.  The path with the least weight will be the quickest.

The input digits are placed in an r by c (rows by columns) rectangular array and then three distinct representations come into play: (1) an r by c grid graph, where each vertex corresponds to a cell in the array, (2) (rc) by (rc) weighted adjacency matrix that holds weights corresponding to the time it takes (2, 3, or 11 minutes) to move from one location (in the grid graph) to another, and (3) a directed, weighted adjacency graph constructed from the matrix.

The grid graph helps determine which cells (i.e. which vertices) are possibly reachable from each vertex--"possibly reachable" because a neighboring cell must not only be right, left, above or below a given cell.  It's value must also be within 1 unit of distance from the neighbor (e.g., a 3 does not connect to a  neighboring 5 or a 1).  If vertex a is not connected to vertex b then the adjacency matrix cells {a,b} and {b,a} will have a value of ∞.  Accordingly, the weighted adjacency graph will not have an edge from a to b, nor from b to a.

The weighted adjacency graph serves to determine the minimum distance (GraphDistance) and shortest route between any vertices.  The optimal path must begin with 1, touch each of the peaks, and return to 1.  In this case, "shortest route" is not necessarily the one with the fewest moves.  It is the one with the shortest overall time, measured in edge weights.

Golfed

```<code>o=Sequence;v[a_<->b_,z_]:=(m_~u~q_:={Quotient[m-1,q[[2]]]+1,1+Mod[m-1, q[[2]]]};j=z[[o@@u[a,i=Dimensions@z]]];k=z[[o@@u[b,i]]];Which[j==k,{{a,b}->3,{b,a}->3},j==k-1,{{a,b}->11,{b,a}->2},j==k+1,{{a,b}->2,{b,a}->11},2<4,{{a,b}->∞, {b, a}->∞}]);w@e_:=Module[{d,x,l,y},x=Map[ToExpression,Characters/@Drop[StringSplit@e,2],{2}];d_~l~c_:=d[[2]](c[[1]]-1)+c[[2]];g_~y~p_:=(Min[Plus@@(GraphDistance[g,#,#2]&@@@#)&/@(Partition[#,2,1]&/@({1,o@@#,1}&/@Permutations@p))]);y[WeightedAdjacencyGraph[ReplacePart[ConstantArray[∞,{t=Times@@(d=Dimensions@x),t}],Flatten[#~v~x &/@Union@Flatten[EdgeList[GridGraph@Reverse@d,#<->_]&/@Range@(Times@@d),1],1]]], l[Dimensions@x, #] & /@ Position[x, Max@x]]
</code>```

Longer, more readable form

```<code>(*determines a weight (number of minutes) to go from vertex a to b and from b to a*)
weight[a_ <-> b_, dat_]:=
  Module[{cellA,cellB,dim,valA,valB,vertexToCell},

  (*Convert graph vertex index to cell location*)
  vertexToCell[m_,dimen_]:={Quotient[m-1,dim[[2]]]+1,1+Mod[m-1,dimen[[2]]]};
     dim=Dimensions[dat];
     cellA = vertexToCell[a,dim];
     cellB = vertexToCell[b,dim];
     valA=dat[[Sequence@@cellA]];
     valB=dat[[Sequence@@cellB]];
     Which[
       valA==valB,{{a,b}-> 3,{b,a}-> 3},
       valA==valB-1,{{a,b}-> 11,{b,a}-> 2},
       valA==valB+1,{{a,b}-> 2,{b,a}-> 11},
       2<4,{{a,b}->∞,{b,a}->∞}]];

(* weights[] determines the edge weights (times to get from one position to the next), makes a graph and infers the shortest distance
from vertex 1 to each peak and back.  It tries out all permutations of peaks and
selects the shortest one. Finally, it returns the length (in minutes) of the shortest trip. *)

weights[str_]:=
  Module[{d,dat,neighbors,cellToVertex,peaks,z,gd},
  dat=Map[ToExpression,Characters/@Drop[StringSplit[str],2],{2}];
  cellToVertex[dim_,cell_]:=dim[[2]] (cell[[1]]-1)+cell[[2]];
  peaks[dat_]:= cellToVertex[Dimensions[dat],#]&/@Position[dat,peak =Max[dat]];

     (* to which cells should each cell be compared? neighbors[] is a function defined within weights[]. It returns a graph, g, from which graph distances will be derived in the function gd[] *)
  neighbors[dim_]:=
  Union@Flatten[EdgeList[GridGraph[Reverse@dim],#<->_]&/@Range@(Times@@dim),1];
    d=Dimensions[dat];
    m=ReplacePart[ConstantArray[∞,{t=Times@@d,t}],
     (*substitutions=*)
    Flatten[weight[#,dat]&/@neighbors[d],1]];
    g=WeightedAdjacencyGraph[m,VertexLabels->"Name",ImageSize->Full,GraphLayout->"SpringEmbedding"];

    (* finds shortest path.  gd[] is also defined within weights[] *)
  gd[g3_,ps_]:=
    Module[{lists,pairs},
    pairs=Partition[#,2,1]&/@({1,Sequence@@#,1}&/@Permutations@ps);
    Min[Plus@@(GraphDistance[g3,#,#2]&@@@#)&/@pairs]];

  gd[g,peaks[dat]]]
</code>```

Tests

```<code>weights["4 5
 32445
 33434
 21153
 12343"]
</code>```

96.

```<code>weights@"2 7
 6787778
 5777679"
</code>```

75.

```<code>weights@"3 4
 1132
 2221
 1230"
</code>```

51.

Explanation

Think of lines 2-5 of the  following input

```<code>"4 5
 32445
 33434
 21153
 12343"
</code>```

as representing an array with 4 rows and 5 columns:

where each vertex corresponds to a digit from the input array: 3 is at vertex 1, 2 is at vertex 2, 4 is at vertex 3, another 4 at vertex 4, 5 at vertex 5, etc. The grid graph is only a rough approximation of the graph we are aiming for. It is undirected. Furthermore, some of the edges will be unavailable. (Remember: we cannot move from a position to another that is more than 1 height unit above or below the current one.)  But the grid graph let's us easily find those vertices that are next to any chosen vertex.  This reduces the number of edges we need to consider, in the first example (a 4 by 5 grid), from 400 (20 * 20) to 62 (31 *2 is the number of edges in the grid graph).  In the same example, only 48 of the edges are operative;  14 are not.

The following 20 by 20 weighted adjacency matrix represents the distance between all pairs of vertices from the grid graph.

The key code which decides on which number to assign is below.

```<code>Which[
      valA==valB,{{a,b}-> 3,{b,a}-> 3},
      valA==valB-1,{{a,b}-> 11,{b,a}-> 2},
      valA==valB+1,{{a,b}-> 2,{b,a}-> 11},
      2<4,{{a,b}->∞,{b,a}->∞}]
</code>```

Cell {1,2}--in one-indexing-- contains the value 2 because the move from vertex 1 to vertex 2 is downhill.
Cell {2,1} contains 11 because the move from vertex 2 to vertex 1 is uphill.
The 3's in cells {1,6} and {6,1} signify that the movement is neither up nor down.
Cell {1,1} contains ∞ because it is not connected to itself.

The following graph shows the structure underlying the above input.  The colored arrows show the optimal path from vertex 1 to the peaks (at 5 and 14) and back to 1.  Blue arrows correspond to moves at the same level (3 min); red arrows mean ascent (11 min.) and green arrows indicate descent (2 min).

The path from vertex 1 (cell {1,1} to the two peaks and back to vertex 1:

```<code>3 + 3 + 11 + 3 + 3 + 11 + 2 + 2 + 3 + 11 + 11 + 2 + 2 + 2 + 2 + 11 + 11 + 3
</code>```

96

Body:
Mathematica <s>745</s> 681 bytes

The basic idea is to make a weighted graph of possible moves. Weights are the time it takes to move from one place to the next.  The path with the least weight will be the quickest.

The input digits are placed in an r by c (rows by columns) rectangular array and then three distinct representations come into play: (1) an r by c grid graph, where each vertex corresponds to a cell in the array, (2) (rc) by (rc) weighted adjacency matrix that holds weights corresponding to the time it takes (2, 3, or 11 minutes) to move from one location (in the grid graph) to another, and (3) a directed, weighted adjacency graph constructed from the matrix.

The grid graph helps determine which cells (i.e. which vertices) are possibly reachable from each vertex--"possibly reachable" because a neighboring cell must not only be right, left, above or below a given cell.  It's value must also be within 1 unit of distance from the neighbor (e.g., a 3 does not connect to a  neighboring 5 or a 1).  If vertex a is not connected to vertex b then the adjacency matrix cells {a,b} and {b,a} will have a value of ∞.  Accordingly, the weighted adjacency graph will not have an edge from a to b, nor from b to a.

The weighted adjacency graph serves to determine the minimum distance (GraphDistance) and shortest route between any vertices.  The optimal path must begin with 1, touch each of the peaks, and return to 1.  In this case, "shortest route" is not necessarily the one with the fewest moves.  It is the one with the shortest overall time, measured in edge weights.

Golfed

o=Sequence;v[a_<->b_,z_]:=(m_~u~q_:={Quotient[m-1,q[[2]]]+1,1+Mod[m-1, q[[2]]]};j=z[[o@@u[a,i=Dimensions@z]]];k=z[[o@@u[b,i]]];Which[j==k,{{a,b}->3,{b,a}->3},j==k-1,{{a,b}->11,{b,a}->2},j==k+1,{{a,b}->2,{b,a}->11},2<4,{{a,b}->∞, {b, a}->∞}]);w@e_:=Module[{d,x,l,y},x=Map[ToExpression,Characters/@Drop[StringSplit@e,2],{2}];d_~l~c_:=d[[2]](c[[1]]-1)+c[[2]];g_~y~p_:=(Min[Plus@@(GraphDistance[g,#,#2]&@@@#)&/@(Partition[#,2,1]&/@({1,o@@#,1}&/@Permutations@p))]);y[WeightedAdjacencyGraph[ReplacePart[ConstantArray[∞,{t=Times@@(d=Dimensions@x),t}],Flatten[#~v~x &/@Union@Flatten[EdgeList[GridGraph@Reverse@d,#<->_]&/@Range@(Times@@d),1],1]]], l[Dimensions@x, #] & /@ Position[x, Max@x]]

Longer, more readable form

(*determines a weight (number of minutes) to go from vertex a to b and from b to a*)
weight[a_ <-> b_, dat_]:=
  Module[{cellA,cellB,dim,valA,valB,vertexToCell},

  (*Convert graph vertex index to cell location*)
  vertexToCell[m_,dimen_]:={Quotient[m-1,dim[[2]]]+1,1+Mod[m-1,dimen[[2]]]};
     dim=Dimensions[dat];
     cellA = vertexToCell[a,dim];
     cellB = vertexToCell[b,dim];
     valA=dat[[Sequence@@cellA]];
     valB=dat[[Sequence@@cellB]];
     Which[
       valA==valB,{{a,b}-> 3,{b,a}-> 3},
       valA==valB-1,{{a,b}-> 11,{b,a}-> 2},
       valA==valB+1,{{a,b}-> 2,{b,a}-> 11},
       2<4,{{a,b}->∞,{b,a}->∞}]];

(* weights[] determines the edge weights (times to get from one position to the next), makes a graph and infers the shortest distance
from vertex 1 to each peak and back.  It tries out all permutations of peaks and
selects the shortest one. Finally, it returns the length (in minutes) of the shortest trip. *)

weights[str_]:=
  Module[{d,dat,neighbors,cellToVertex,peaks,z,gd},
  dat=Map[ToExpression,Characters/@Drop[StringSplit[str],2],{2}];
  cellToVertex[dim_,cell_]:=dim[[2]] (cell[[1]]-1)+cell[[2]];
  peaks[dat_]:= cellToVertex[Dimensions[dat],#]&/@Position[dat,peak =Max[dat]];

     (* to which cells should each cell be compared? neighbors[] is a function defined within weights[]. It returns a graph, g, from which graph distances will be derived in the function gd[] *)
  neighbors[dim_]:=
  Union@Flatten[EdgeList[GridGraph[Reverse@dim],#<->_]&/@Range@(Times@@dim),1];
    d=Dimensions[dat];
    m=ReplacePart[ConstantArray[∞,{t=Times@@d,t}],
     (*substitutions=*)
    Flatten[weight[#,dat]&/@neighbors[d],1]];
    g=WeightedAdjacencyGraph[m,VertexLabels->"Name",ImageSize->Full,GraphLayout->"SpringEmbedding"];

    (* finds shortest path.  gd[] is also defined within weights[] *)
  gd[g3_,ps_]:=
    Module[{lists,pairs},
    pairs=Partition[#,2,1]&/@({1,Sequence@@#,1}&/@Permutations@ps);
    Min[Plus@@(GraphDistance[g3,#,#2]&@@@#)&/@pairs]];

  gd[g,peaks[dat]]]

Tests

weights["4 5
 32445
 33434
 21153
 12343"]

96.

weights@"2 7
 6787778
 5777679"

75.

weights@"3 4
 1132
 2221
 1230"

51.

Explanation

Think of lines 2-5 of the  following input

"4 5
 32445
 33434
 21153
 12343"

as representing an array with 4 rows and 5 columns:

where each vertex corresponds to a digit from the input array: 3 is at vertex 1, 2 is at vertex 2, 4 is at vertex 3, another 4 at vertex 4, 5 at vertex 5, etc. The grid graph is only a rough approximation of the graph we are aiming for. It is undirected. Furthermore, some of the edges will be unavailable. (Remember: we cannot move from a position to another that is more than 1 height unit above or below the current one.)  But the grid graph let's us easily find those vertices that are next to any chosen vertex.  This reduces the number of edges we need to consider, in the first example (a 4 by 5 grid), from 400 (20 * 20) to 62 (31 *2 is the number of edges in the grid graph).  In the same example, only 48 of the edges are operative;  14 are not.

The following 20 by 20 weighted adjacency matrix represents the distance between all pairs of vertices from the grid graph.

The key code which decides on which number to assign is below.

Which[
      valA==valB,{{a,b}-> 3,{b,a}-> 3},
      valA==valB-1,{{a,b}-> 11,{b,a}-> 2},
      valA==valB+1,{{a,b}-> 2,{b,a}-> 11},
      2<4,{{a,b}->∞,{b,a}->∞}]

Cell {1,2}--in one-indexing-- contains the value 2 because the move from vertex 1 to vertex 2 is downhill.
Cell {2,1} contains 11 because the move from vertex 2 to vertex 1 is uphill.
The 3's in cells {1,6} and {6,1} signify that the movement is neither up nor down.
Cell {1,1} contains ∞ because it is not connected to itself.

The following graph shows the structure underlying the above input.  The colored arrows show the optimal path from vertex 1 to the peaks (at 5 and 14) and back to 1.  Blue arrows correspond to moves at the same level (3 min); red arrows mean ascent (11 min.) and green arrows indicate descent (2 min).

The path from vertex 1 (cell {1,1} to the two peaks and back to vertex 1:

3 + 3 + 11 + 3 + 3 + 11 + 2 + 2 + 3 + 11 + 11 + 2 + 2 + 2 + 2 + 11 + 11 + 3

96


答:
K4, 18 bytes

Essentially a port of the APL solution (unsurprisingly).

```<code>+-6$(33?1+!6)#'"="
</code>```

Title: Illustrate music beats

Body:
K4, 18 bytes

Essentially a port of the APL solution (unsurprisingly).

+-6$(33?1+!6)#'"="


答:
05AB1E, 22 bytes

No auto joining, no automatic filling while transposing, osabie is doomed on this one. Code:

```<code>33F6ð×6L.R'=×ðñ})ø€J¶ý
</code>```

Uses the CP-1252 encoding. Try it online!.

Title: Illustrate music beats

Body:
05AB1E, 22 bytes

No auto joining, no automatic filling while transposing, osabie is doomed on this one. Code:

33F6ð×6L.R'=×ðñ})ø€J¶ý

Uses the CP-1252 encoding. Try it online!.


答:
MATL, <s>20</s> <s>19</s> <s>18</s> 17 bytes

1 byte saved thanks to @Luis

```<code>33l2$r6*6:>!~61*c
</code>```

Try it Online

Title: Illustrate music beats

Body:
MATL, <s>20</s> <s>19</s> <s>18</s> 17 bytes

1 byte saved thanks to @Luis

33l2$r6*6:>!~61*c

Try it Online


答:
Python 2, 95 bytes

```<code>from random import*
x=map(randrange,[6]*33)
for y in range(6):print''.join('= '[z>y]for z in x)
</code>```

Title: Illustrate music beats

Body:
Python 2, 95 bytes

from random import*
x=map(randrange,[6]*33)
for y in range(6):print''.join('= '[z>y]for z in x)


答:
Python 3, 115 bytes

Python never even had a chance...

```<code>from random import*
for k in zip(*[[' ']*(6-len(j))+j for j in[randint(1,6)*['=']for i in[0]*33]]):print(*k,sep='')
</code>```

How it works

```<code>from random import*    Import everything in the random module
randint(1,6)*['=']     Create a list containing a random number in [1,6] of '='...
...for i in[0]*33      ...33 times...
[...]                  ...and store in a list X
for j in...            For all lists j in X...
[' ']*(6-len(j))+j     ...create a list containing j padded with the correct number of
                       spaces to give a height of 6...
[...]                  ...and store in a list Y

Y now contains a list for each output line, but transposed.

for k in zip(*...):...  For all lists k in the transpose of Y...
print(*k,sep='')        Print all elements in k with no separating space
</code>```

Try it on Ideone

Title: Illustrate music beats

Body:
Python 3, 115 bytes

Python never even had a chance...

from random import*
for k in zip(*[[' ']*(6-len(j))+j for j in[randint(1,6)*['=']for i in[0]*33]]):print(*k,sep='')

How it works

from random import*    Import everything in the random module
randint(1,6)*['=']     Create a list containing a random number in [1,6] of '='...
...for i in[0]*33      ...33 times...
[...]                  ...and store in a list X
for j in...            For all lists j in X...
[' ']*(6-len(j))+j     ...create a list containing j padded with the correct number of
                       spaces to give a height of 6...
[...]                  ...and store in a list Y

Y now contains a list for each output line, but transposed.

for k in zip(*...):...  For all lists k in the transpose of Y...
print(*k,sep='')        Print all elements in k with no separating space

Try it on Ideone


答:
C, 87 bytes

```<code>f(x,y){for(y=6;y--;){srand(time(0));for(x=33;x--;)putchar("= "[rand()%6<y]);puts("");}}
</code>```

Call as f();. This answer relies on the fact that six consecutive calls to time(0) return the same result (in seconds). This is virtually always true, but probably worth mentioning.

Title: Illustrate music beats

Body:
C, 87 bytes

f(x,y){for(y=6;y--;){srand(time(0));for(x=33;x--;)putchar("= "[rand()%6<y]);puts("");}}

Call as f();. This answer relies on the fact that six consecutive calls to time(0) return the same result (in seconds). This is virtually always true, but probably worth mentioning.


答:
18, including newline</p>

```<code>#define float int
</code>```

Title: m3ph1st0s's programming puzzle 1 (C++)

Body:
This is the first of a series of C++ puzzles for you. Hope you will enjoy.

So, puzzle no.1:

Given the following program:

```<code>#include <iostream>
int main()
{
   const int a=1;
   const int b=2;
   const float c=0.5;
   std::cout << a/b-a*c;
}
</code>```

Insert some code on a single new line anywhere inside the program so that the output will be 0. The new line will contain AT MOST 18 characters (including spaces), and the rest of the lines will remain unmodified.
 To be clear, here is an example of a valid new code:

```<code>#include <iostream>
int main()
{
   const int a=1;
   const int b=2;
   int* p = NULL;
   const float c=0.5;
   std::cout << a/b-a*c;
}
</code>```

A new line with 15 characters was inserted so it's ok. However it does not solve the problem.

If this is too simple for you, don't worry, more is coming!!

Body:
18, including newline

#define float int


答:
Mathematica, 78 bytes

```<code>StringRiffle[(PadLeft[Array["="&,#+1],6," "]&/@5~RandomInteger~33),"
",""]&
</code>```

Anonymous function. Takes no input and returns a string as output. The Unicode character is U+F3C7, representing \[Transpose].

Title: Illustrate music beats

Body:
Mathematica, 78 bytes

StringRiffle[(PadLeft[Array["="&,#+1],6," "]&/@5~RandomInteger~33),"
",""]&

Anonymous function. Takes no input and returns a string as output. The Unicode character is U+F3C7, representing \[Transpose].


问:
Is it a max-heap?
A heap, also known as a priority-queue, is an abstract data type. Conceptually, it's a binary tree where the children of every node are smaller than or equal to the node itself. (Assuming it's a max-heap.) When an element is pushed or popped, the heap rearranges itself so the the biggest element is the next to be popped. It can easily be implemented as a tree or as an array.

Your challenge, should you choose to accept it, is to determine if an array is a valid heap. An array is in heap form if every element's children are smaller than or equal to the element itself. Take the following array as an example:

```<code>[90, 15, 10, 7, 12, 2]
</code>```

Really, this is a binary tree arranged in the form of an array. This is because every element has children. 90 has two children, 15 and 10.

```<code>       15, 10,
[(90),         7, 12, 2]
</code>```

15 also has children, 7 and 12:

```<code>               7, 12,
[90, (15), 10,        2]
</code>```

10 has children:

```<code>                      2
[90, 15, (10), 7, 12,  ]
</code>```

and the next element would also be a child of 10, except that there isn't room. 7, 12 and 2 would all also have children if the array was long enough. Here is another example of a heap:

```<code>[16, 14, 10, 8, 7, 9, 3, 2, 4, 1]
</code>```

And here is a visualization of the tree the previous array makes:

Just in case this isn't clear enough, here is the explicit formula to get the children of the i'th element

```<code>//0-indexing:
child1 = (i * 2) + 1
child2 = (i * 2) + 2

//1-indexing:
child1 = (i * 2)
child2 = (i * 2) + 1
</code>```

You must take an non-empty array as input and output a truthy value if the array is in heap order, and a falsy value otherwise. This can be a 0-indexed heap, or a 1-indexed heap as long as you specify which format your program/function expects. You may assume that all arrays will only contain positive integers. You may not use any heap-builtins. This includes, but is not limited to

Functions that determine if an array is in heap-form

Functions that convert an array into a heap or into heap-form

Functions that take an array as input and return a heap data-structure

You can use this python script to verify if an array is in heap-form or not (0 indexed):

```<code>def is_heap(l):
    for head in range(0, len(l)):
        c1, c2 = head * 2 + 1, head * 2 + 2
        if c1 < len(l) and l[head] < l[c1]:
            return False
        if c2 < len(l) and l[head] < l[c2]:
            return False

    return True
</code>```

Test IO:

All of these inputs should return True:

```<code>[90, 15, 10, 7, 12, 2]
[93, 15, 87, 7, 15, 5]
[16, 14, 10, 8, 7, 9, 3, 2, 4, 1]
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
[100, 19, 36, 17, 3, 25, 1, 2, 7]
[5, 5, 5, 5, 5, 5, 5, 5]
</code>```

And all of these inputs should return False:

```<code>[4, 5, 5, 5, 5, 5, 5, 5]
[90, 15, 10, 7, 12, 11]
[1, 2, 3, 4, 5]
[4, 8, 15, 16, 23, 42]
[2, 1, 3]
</code>```

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

答:
JavaScript (ES6), <s>34</s> 30 bytes

```<code>a=>!a.some((e,i)=>e>a[i-1>>1])
</code>```

Edit: Fixing my code for the spec clarification cost 1 byte, so thanks to @edc65 for saving 4 bytes.

Title: Is it a max-heap?

Body:
JavaScript (ES6), <s>34</s> 30 bytes

a=>!a.some((e,i)=>e>a[i-1>>1])

Edit: Fixing my code for the spec clarification cost 1 byte, so thanks to @edc65 for saving 4 bytes.