答:
Ruby, 53 bytes

f is 0-indexed, u is 1-indexed. Try it online!

```<code>->m,n{m.times{|i|p (1..n).map{|j|"d f#{i}/d u#{j}"}}}
</code>```

Each row occupies one line as an array representation as seen below. If it isn't compliant to spec, please let me know and I will fix it.

```<code>["d f0/d u1", "d f0/d u2", "d f0/d u3"]
["d f1/d u1", "d f1/d u2", "d f1/d u3"]
</code>```

Title: Construct the Jacobian matrix

Body:
Ruby, 53 bytes

f is 0-indexed, u is 1-indexed. Try it online!

->m,n{m.times{|i|p (1..n).map{|j|"d f#{i}/d u#{j}"}}}

Each row occupies one line as an array representation as seen below. If it isn't compliant to spec, please let me know and I will fix it.

["d f0/d u1", "d f0/d u2", "d f0/d u3"]
["d f1/d u1", "d f1/d u2", "d f1/d u3"]


问:
A newly discovered number: bleen!
"The Nobel Prize in mathematics was awarded to a California professor who has discovered a new number! The number is bleen, which he claims belongs between 6 and 7."  --George Carlin

In this challenge, you will print all Integers, inclusive, within the given input range.  Print numbers ascending or descending according to their input order.  That is, for input [n1, n2], print ascending if n1 < n2, descending if n1 > n2.

Since bleen is now an Integer number it may be used as input.  It must also be included in the output, between 6 and 7 where applicable.  Also note that -bleen exists between -7 and -6.

Input

Two Integers [n1, n2] in the range [-10, 10], inclusive, via your programming language's input of choice.

(Input may also contain bleen and -bleen!)

Output

Print all Integers starting at n1 and ending with n2, including the newly discovered bleen between 6 and 7.  Output can be a range of character separated numbers in some form your language supports - that is, comma or space separated.  One trailing space of output is okay.

Examples

```<code>Input:  1 10
Output: 1 2 3 4 5 6 bleen 7 8 9 10

Input:  -9 -4
Output: -9 -8 -7 -bleen -6 -5 -4

Input:  -8 bleen
Output: -8 -7 -bleen -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 bleen

Input:  9 1
Output: 9 8 7 bleen 6 5 4 3 2 1

Input:  2 -bleen
Output: 2 1 0 -1 -2 -3 -4 -5 -6 -bleen

Input:  -bleen 0
Output: -bleen -6 -5 -4 -3 -2 -1 0

Input:  bleen bleen
Output: bleen

Input:  2 2
Output: 2
</code>```

Additional notes

You may write a program or function and use any standard method of receiving input and providing output.

You may use any programming language, but standard loopholes are not allowed.

This is code-golf, so the shortest valid answer – measured in bytes – wins.

答:
Ruby, 141 bytes

->*a{
l="bleen"
s=13
a,b=a.map{|n|2*n rescue s*(n<=>?b)}
b,a,r=a,b,1if b<a
o=(a..b).map{|n|n==s ?l:n==-s ??-+l:n/2}.uniq
puts r ?o.reverse: o}
```

<h2>Ungolfed</h2>

<pre class="lang-ruby prettyprint-override"><code>lambda do |*args|
  bleen = "bleen"
  subst = 13 # This will stand in for "bleen"

  a, b = args.map {|arg|
    begin
      # Double the number
      2 * arg
    rescue
      # It wasn't a number, so it's "bleen" or "-bleen"; replace it with 13 or -13
      subst * (arg <=> "b")
    end
  }

  if b < a
    # If the range isn't ascending, reverse it and remember that we did
    b, a, reverse = a, b, 1
  end

  # Step through the range, replacing 13 and -13 with "bleen" and "-bleen" and
  # halving everything else
  result = (a..b).map {|n|
    if n == subst
      bleen
    elsif n == -subst
      "-" + bleen
    else
      n / 2
    end
  }.uniq # Drop duplicates

  # Reverse the result if the range was descending
  puts reverse ? result.reverse : result
end
</code>```

ContentLicense: CC BY-SA 3.0

Title: A newly discovered number: bleen!

Body:
Ruby, 141 bytes

->*a{
l="bleen"
s=13
a,b=a.map{|n|2*n rescue s*(n<=>?b)}
b,a,r=a,b,1if b<a
o=(a..b).map{|n|n==s ?l:n==-s ??-+l:n/2}.uniq
puts r ?o.reverse: o}

Ungolfed

lambda do |*args|
  bleen = "bleen"
  subst = 13 # This will stand in for "bleen"

  a, b = args.map {|arg|
    begin
      # Double the number
      2 * arg
    rescue
      # It wasn't a number, so it's "bleen" or "-bleen"; replace it with 13 or -13
      subst * (arg <=> "b")
    end
  }

  if b < a
    # If the range isn't ascending, reverse it and remember that we did
    b, a, reverse = a, b, 1
  end

  # Step through the range, replacing 13 and -13 with "bleen" and "-bleen" and
  # halving everything else
  result = (a..b).map {|n|
    if n == subst
      bleen
    elsif n == -subst
      "-" + bleen
    else
      n / 2
    end
  }.uniq # Drop duplicates

  # Reverse the result if the range was descending
  puts reverse ? result.reverse : result
end


答:
Python 3, <s>157</s> <s>145</s> <s>123</s> <s>108</s> <s>115</s> <s>139</s> <s>161</s> <s>158</s> 153 bytes

Saved 22 thanks to Lynn. 17 saved thanks to shooqie. 3 saved thanks to ljeabmreosn. 5 saved thanks to Geoff Reedy.

```<code>a,b=eval(input())
s='-'
c='bleen'
d=a<b
l=list(map(str,range(-10,11)))[::[-1,1][d]]
x=l.insert
y=l.index
x(4,d*s+c)
x(18,(1^d)*s+c)
print(l[y(a):y(b)+1])
</code>```

Input like '-10', '8'. Tips are welcome for a beginner.

Added 7 to account for -bleen. Added 15 to account for reversed input like '8','-10'. Added a large 21 to account for the reversed input signs for bleen vs -bleen.

Title: A newly discovered number: bleen!

Body:
"The Nobel Prize in mathematics was awarded to a California professor who has discovered a new number! The number is bleen, which he claims belongs between 6 and 7."  --George Carlin

In this challenge, you will print all Integers, inclusive, within the given input range.  Print numbers ascending or descending according to their input order.  That is, for input [n1, n2], print ascending if n1 < n2, descending if n1 > n2.

Since bleen is now an Integer number it may be used as input.  It must also be included in the output, between 6 and 7 where applicable.  Also note that -bleen exists between -7 and -6.

Input

Two Integers [n1, n2] in the range [-10, 10], inclusive, via your programming language's input of choice.

(Input may also contain bleen and -bleen!)

Output

Print all Integers starting at n1 and ending with n2, including the newly discovered bleen between 6 and 7.  Output can be a range of character separated numbers in some form your language supports - that is, comma or space separated.  One trailing space of output is okay.

Examples

```<code>Input:  1 10
Output: 1 2 3 4 5 6 bleen 7 8 9 10

Input:  -9 -4
Output: -9 -8 -7 -bleen -6 -5 -4

Input:  -8 bleen
Output: -8 -7 -bleen -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 bleen

Input:  9 1
Output: 9 8 7 bleen 6 5 4 3 2 1

Input:  2 -bleen
Output: 2 1 0 -1 -2 -3 -4 -5 -6 -bleen

Input:  -bleen 0
Output: -bleen -6 -5 -4 -3 -2 -1 0

Input:  bleen bleen
Output: bleen

Input:  2 2
Output: 2
</code>```

Additional notes

You may write a program or function and use any standard method of receiving input and providing output.

You may use any programming language, but standard loopholes are not allowed.

This is code-golf, so the shortest valid answer – measured in bytes – wins.

Body:
Python 3, <s>157</s> <s>145</s> <s>123</s> <s>108</s> <s>115</s> <s>139</s> <s>161</s> <s>158</s> 153 bytes

Saved 22 thanks to Lynn. 17 saved thanks to shooqie. 3 saved thanks to ljeabmreosn. 5 saved thanks to Geoff Reedy.

a,b=eval(input())
s='-'
c='bleen'
d=a<b
l=list(map(str,range(-10,11)))[::[-1,1][d]]
x=l.insert
y=l.index
x(4,d*s+c)
x(18,(1^d)*s+c)
print(l[y(a):y(b)+1])

Input like '-10', '8'. Tips are welcome for a beginner.

Added 7 to account for -bleen. Added 15 to account for reversed input like '8','-10'. Added a large 21 to account for the reversed input signs for bleen vs -bleen.


问:
Alphabet triangle
You are to print this exact text:

```<code>A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
ABCDEFGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYZYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGFEDCBA
ABCDEFEDCBA
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A
</code>```

Specs

Extra trailing newlines are allowed at the end of the output.

Extra trailing spaces (U+0020) are allowed at the end of each line, including the extra trailing newlines.

You can use all lowercase instead of all uppercase, but you cannot print partially lowercase partially uppercase.

You can return the text as a function output instead of printing it in a full program.

Scoring

Since this is a triangle, and a triangle has 3 sides, and 3 is a small number, your code should be small in terms of byte-count.

答:
Python 2.7, 136 bytes

x=[chr(y) for y in range(65,91)]
for y in range(25):print ''.join(x[:y]+x[y::-1])
for y in range(25,-1,-1):print ''.join(x[:y]+x[y::-1])
```

Title: Alphabet triangle


答:
Ruby, <s>114</s> <s>100</s> 98 bytes

Input is an array with [n1, n2]. (If it must be two seperate arguments, +1 byte to change the function arg from g to *g. Bleen must be a string, "bleen". Outputs an array of the range. Suggested by @Jordan with his (?) initial version granting -7 bytes, but I also golfed off 7 more after that.

Try it online.

->g{a=*-10..-7,?-+b='bleen',*-6..6,b,*7..10;x,y=g.map{|v|a.index v}
y<x ?a[y..x].reverse: a[x..y]}
```
<p>Original full program version that reads input from <code>ARGV</code>:</p>
<pre class="lang-ruby prettyprint-override"><code>b='bleen'
a=[*-10..-7,?-+b,*-6..6,b,*7..10].map &:to_s
x,y=$*.map{|v|a.index v}
puts y<x ?a[y..x].reverse: a[x..y]
</code>```

Title: A newly discovered number: bleen!

Body:
Ruby, <s>114</s> <s>100</s> 98 bytes

Input is an array with [n1, n2]. (If it must be two seperate arguments, +1 byte to change the function arg from g to *g. Bleen must be a string, "bleen". Outputs an array of the range. Suggested by @Jordan with his (?) initial version granting -7 bytes, but I also golfed off 7 more after that.

Try it online.

->g{a=*-10..-7,?-+b='bleen',*-6..6,b,*7..10;x,y=g.map{|v|a.index v}
y<x ?a[y..x].reverse: a[x..y]}

Original full program version that reads input from ARGV:

b='bleen'
a=[*-10..-7,?-+b,*-6..6,b,*7..10].map &:to_s
x,y=$*.map{|v|a.index v}
puts y<x ?a[y..x].reverse: a[x..y]


问:
Tips for golfing in GolfScript
What, this post doesn't exist yet?

Of course, GolfScript is made for golfing, so you might think that no specific tips are really needed.  But to make full use of GolfScript's features, you need to learn some non-obvious tricks.  This post is for collecting such helpful tips and tricks.

To start with, here are the official GolfScript reference pages.  You should really familiarize yourself with these first:

Tutorial

Syntax

Built-ins

Quick reference

In particular, I would very much suggest reading the pages in this order — the quick reference is of little use until you're already reasonably familiar with the built-ins, and the tutorial includes some important details that are not explained on the other pages.

Ps. For the sake of inspiration and personal interest, here are some questions I'd like to see nice answers to:

How to do limited transliteration in GolfScript?  {FROM?TO=}% works if you can be sure all the inputs are found in FROM (or don't mind them all being mapped to the last element of TO), but all the ways I've seen for leaving unmapped values unchanged have been more or less klugey.

How to best convert a string into an array of ASCII codes and back?  Which operations do this as a side effect?  What's the best way to dump the characters in a string onto the stack (like ~ does for arrays)?

答:
Wrapping the top item of the stack into an array

Is there a nice way to transform ... x into ... [x]?

For full generality, the best option appears to be 4 chars. However, in certain special cases it's possible to reduce this.

1 char

] works in the special case that xis the only thing on the stack.

3 chars

[]+ works in the special case that x is an integer.

.,/ works in the special case that x is a truthy array or string. E.g. "AB".,/ gives ["AB"]; 3,.,/ gives [[0 1 2]]. However, "".,/ and [].,/ both give [].

4 chars

[.;] works unconditionally.

Title: Tips for golfing in GolfScript


答:
Java <s>169</s> 156bytes

```<code>String a="abcdefghijklmnopqrstuvwxyz";
public void alphabetTriangle(){
  for(int i=0;++i<27;){
    System.out.println(a.substring(0,a)+new StringBuilder(a).reverse().substring(1,-i+1));
  }
}
</code>```

Golfed

```<code>String a="abcdefghijklmnopqrstuvwxyz";void l(){for(int i=0;++i<27;){System.out.println(a.substring(0,a)+new StringBuilder(a).reverse().substring(1,-i+1));}}
</code>```

It is actually same as the batch solution with some shortcuts

Thanks to @Value Ink for saving 15 bytes by shortening the method name.

Title: Alphabet triangle

Body:
You are to print this exact text:

```<code>A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
ABCDEFGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYZYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGFEDCBA
ABCDEFEDCBA
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A
</code>```

Specs

Extra trailing newlines are allowed at the end of the output.

Extra trailing spaces (U+0020) are allowed at the end of each line, including the extra trailing newlines.

You can use all lowercase instead of all uppercase, but you cannot print partially lowercase partially uppercase.

You can return the text as a function output instead of printing it in a full program.

Scoring

Since this is a triangle, and a triangle has 3 sides, and 3 is a small number, your code should be small in terms of byte-count.

Body:
Java <s>169</s> 156bytes

String a="abcdefghijklmnopqrstuvwxyz";
public void alphabetTriangle(){
  for(int i=0;++i<27;){
    System.out.println(a.substring(0,a)+new StringBuilder(a).reverse().substring(1,-i+1));
  }
}

Golfed

String a="abcdefghijklmnopqrstuvwxyz";void l(){for(int i=0;++i<27;){System.out.println(a.substring(0,a)+new StringBuilder(a).reverse().substring(1,-i+1));}}

It is actually same as the batch solution with some shortcuts

Thanks to @Value Ink for saving 15 bytes by shortening the method name.


问:
Unfolding the Hexagony source code

Introduction

If you're not familiar with Hexagony, it's an esoteric language created by Martin Büttner. The thing is that this language accepts multiple forms for the program. The following programs are all equivalent:

```<code>abcdefg
</code>```

and

```<code> a b
c d e
 f g
</code>```

So basically, the code has been rolled up into a regular hexagon. But note that adding a new command to the code, which would be abcdefgh would result into the following program:

```<code>  a b c
 d e f g
h . . . .
 . . . .
  . . .
</code>```

As you can see, the first step is rolling up the code into a hexagon, and after that the hexagon is filled in with no-ops (.) to the next centered hexagonal number.

Your task is simple, when given a string (the source code), output the full hexagon source code.

The rules

You may provide a program or a function.

Leading whitespace is allowed, but only when the hexagon doesn't get out of shape

Trailing whitespace is allowed.

Note that whitespace in the program are ignored. So a b c is equal to abc

Only the printable ASCII characters (32 - 126) are used, so only the regular Space character is ignored.

Assume that the length of the string is greater than 0.

This is code-golf, so the submission with the least amount of bytes wins!

Test cases

```<code>Input: ?({{&2'2':{):!/)'*/

Output:
  ? ( {
 { & 2 '
2 ' : { )
 : ! / )
  ' * /

Input: H;e;l;d;*;r;o;Wl;;o;*433;@.>;23<\4;*/

Output:
   H ; e ;
  l ; d ; *
 ; r ; o ; W
l ; ; o ; * 4
 3 3 ; @ . >
  ; 2 3 < \
   4 ; * /

Input: .?'.) .@@/'/ .!.>   +=(<.!)}    (  $>( <%

Output:
   . ? ' .
  ) . @ @ /
 ' / . ! . >
+ = ( < . ! )
 } ( $ > ( <
  % . . . .
   . . . .
</code>```

答:
Retina, 161 bytes

Thanks to FryAmTheEggman for saving 2 bytes.

This answer is non-competing. Retina has seen a few updates since this challenge, and I'm pretty sure I'm using some of the newer features (although I haven't checked).

Byte count assumes ISO 8859-1 encoding. The first line contains a single space. Note that most of the · are actually centre dots (0xB7).

```<code>

^
$._$*·¶
^·¶
¶
((^·|\2·)*)·\1{5}·+
$2·
^·*
$.&$* ·$&$&$.&$*
M!&m`(?<=(?= *(·)+)^.*)(?<-1>.)+(?(1)!)|^.+$
+m`^( *·+)· *¶(?=\1)
$&
·
 ·
O$`(·)|\S
$1
·
.
G-2`
</code>```

Try it online!

Well...

Explanation

It seems easiest to build the layout first using just a single character (· in this case) and then fill the resulting layout with the input characters. The main reasons for this are that using a single character lets me make use of backreferences and character repetition, where laying out the input directly would require expensive balancing groups.

```<code>

</code>```

Although it doesn't look like much, this first stages removes spaces from the input.

```<code>^
$._$*·¶
</code>```

We start by prepending an additional line which contains M centre dots, where M is the length of the input (after removing spaces).

```<code>^·¶
¶
</code>```

If the input was a single character, we remove that centre dot again. This is an unfortunate special case that isn't covered by the next stage.

```<code>((^·|\2·)*)·\1{5}·+
$2·
</code>```

This computes the required side length N minus 1. Here is how that works: centred hexagonal numbers are of the form 3*N*(N-1) + 1. Since triangular numbers are N*(N-1)/2, that means hexagonal numbers are six times a triangular number plus 1. That's convenient because matching triangular numbers (which are really just 1 + 2 + 3 + ... + N) in a regex is fairly easy with forward references. The (^·|\2·)* matches the largest triangular number it can. As a nice bonus, $2 will then hold the index of this triangular number. To multiply it by 6, we capture it into group 1 and match it another 5 times. We make sure there are at least two more · with the · and the ·+. This way the index of the found triangular number doesn't increase until there's one character more than a centred hexagonal number.

In the end, this match gives us two less than the side-length of the required hexagon in group $2, so we write that back together with one more centre dot to get N-1.

```<code>^·*
$.&$* ·$&$&$.&$*
</code>```

This turns our string of N-1 centre dots into N-1 spaces, 2N-1 centre dots and another N-1 spaces. Note that this is the maximum indentation, followed by the diameter of the hexagon, followed by the indentation again.

```<code>M!&m`(?<=(?= *(·)+)^.*)(?<-1>.)+(?(1)!)|^.+$
</code>```

This is unpleasantly long, but it basically just gives us all overlapping matches, which are either a) 2N-1 characters long and on the first line or b) the second line. This expands the result from the previous stage into the full, but weirdly indented hexagon. E.g. for input 12345678 we'd get:

```<code>  ···
 ····
·····
····
···
12345678
</code>```

This is why we needed to append spaces in the previous stage as well.

```<code>+m`^( *·+)· *¶(?=\1)
$&
</code>```

This fixes the indentation of the lines after the centre, by repeatedly indenting any line that is shorter than the previous (ignoring trailing spaces), so we get this:

```<code>  ···
 ····
·····
 ····
  ···
12345678
</code>```

Now we just insert some spaces with

```<code>

</code>```0

Which gives us:

```<code>

</code>```1

Phew, that's done.

```<code>

</code>```2

Time to fill the input string into the centre dots. This is done with the help of a sort stage. We match all centre dots and each character on the last line, and we sort them by the result of the given substitution. That substitution is empty for the characters on the last line and · for the centre dots, so what happens is that the centre dots are simply sorted to the end (since sorting is stable). This moves the input characters into place:

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

Just two things left now:

```<code>·
.
</code>```

This turns centre dots into regular periods.

```<code>G-2`
</code>```

And this discards the last line.

Title: Unfolding the Hexagony source code

Body:
Retina, 161 bytes

Thanks to FryAmTheEggman for saving 2 bytes.

This answer is non-competing. Retina has seen a few updates since this challenge, and I'm pretty sure I'm using some of the newer features (although I haven't checked).

Byte count assumes ISO 8859-1 encoding. The first line contains a single space. Note that most of the · are actually centre dots (0xB7).

^
$._$*·¶
^·¶
¶
((^·|\2·)*)·\1{5}·+
$2·
^·*
$.&$* ·$&$&$.&$*
M!&m`(?<=(?= *(·)+)^.*)(?<-1>.)+(?(1)!)|^.+$
+m`^( *·+)· *¶(?=\1)
$&
·
 ·
O$`(·)|\S
$1
·
.
G-2`

Try it online!

Well...

Explanation

It seems easiest to build the layout first using just a single character (· in this case) and then fill the resulting layout with the input characters. The main reasons for this are that using a single character lets me make use of backreferences and character repetition, where laying out the input directly would require expensive balancing groups.

Although it doesn't look like much, this first stages removes spaces from the input.

^
$._$*·¶

We start by prepending an additional line which contains M centre dots, where M is the length of the input (after removing spaces).

^·¶
¶

If the input was a single character, we remove that centre dot again. This is an unfortunate special case that isn't covered by the next stage.

((^·|\2·)*)·\1{5}·+
$2·

This computes the required side length N minus 1. Here is how that works: centred hexagonal numbers are of the form 3*N*(N-1) + 1. Since triangular numbers are N*(N-1)/2, that means hexagonal numbers are six times a triangular number plus 1. That's convenient because matching triangular numbers (which are really just 1 + 2 + 3 + ... + N) in a regex is fairly easy with forward references. The (^·|\2·)* matches the largest triangular number it can. As a nice bonus, $2 will then hold the index of this triangular number. To multiply it by 6, we capture it into group 1 and match it another 5 times. We make sure there are at least two more · with the · and the ·+. This way the index of the found triangular number doesn't increase until there's one character more than a centred hexagonal number.

In the end, this match gives us two less than the side-length of the required hexagon in group $2, so we write that back together with one more centre dot to get N-1.

^·*
$.&$* ·$&$&$.&$*

This turns our string of N-1 centre dots into N-1 spaces, 2N-1 centre dots and another N-1 spaces. Note that this is the maximum indentation, followed by the diameter of the hexagon, followed by the indentation again.

M!&m`(?<=(?= *(·)+)^.*)(?<-1>.)+(?(1)!)|^.+$

This is unpleasantly long, but it basically just gives us all overlapping matches, which are either a) 2N-1 characters long and on the first line or b) the second line. This expands the result from the previous stage into the full, but weirdly indented hexagon. E.g. for input 12345678 we'd get:

  ···
 ····
·····
····
···
12345678

This is why we needed to append spaces in the previous stage as well.

+m`^( *·+)· *¶(?=\1)
$&

This fixes the indentation of the lines after the centre, by repeatedly indenting any line that is shorter than the previous (ignoring trailing spaces), so we get this:

  ···
 ····
·····
 ····
  ···
12345678

Now we just insert some spaces with

·
 ·

Which gives us:

   · · ·
  · · · ·
 · · · · ·
  · · · ·
   · · ·
12345678

Phew, that's done.

O$`(·)|\S
$1

Time to fill the input string into the centre dots. This is done with the help of a sort stage. We match all centre dots and each character on the last line, and we sort them by the result of the given substitution. That substitution is empty for the characters on the last line and · for the centre dots, so what happens is that the centre dots are simply sorted to the end (since sorting is stable). This moves the input characters into place:

   1 2 3
  4 5 6 7
 8 · · · ·
  · · · ·
   · · ·
········

Just two things left now:

·
.

This turns centre dots into regular periods.

G-2`

And this discards the last line.


问:
How Many Rectangles in the Grid?

Well, although this challenge turned out to be a huge success, it also turned out to be very trivial to solve. Therefore, for those of looking for more of a challenge, I created a sequel to this challenge in which you must now count the number of unique rectangles. Check it out!

Now, for those of you looking to solve this challenge, here it comes.

Well, we don't really have a challenge like this yet, so here we go.

Consider this 3 x 3 grid of rectangles:

How many rectangles are there? Well, counting visually, we can see that there are actually 36 rectangles, including the entire plane itself, which are all shown in the animated GIF below:

The Task

The counting of rectangles as shown above is the task. In other words, given 2 integers greater than or equal to 0, m and n, where m represents the width and n represents the height, output the total number of rectangles in that m x n grid of rectangles.

Rules

The use of any built-ins that directly solve this problem is explicitly disallowed.

This challenge is not about finding the shortest answer, but finding the shortest answer in every language. Therefore, no answer will be accepted.

Standard loopholes are prohibited.

Test Cases

Presented in the format Array of Integers Input -> Integer Output:

```<code>[0,0] -> 0
[1,1] -> 1
[3,3] -> 36 (Visualized above)
[4,4] -> 100
[6,7] -> 588
</code>```

References

http://oeis.org/A096948

Remember, this is code-golf, so shortest code wins!

Title: How Many Rectangles in the Grid?

Body:
Cheddar, 23 bytes

m->n->m*(m+1)*n*(n+1)/4


答:
Python 2, 98 bytes

This is what I think is a unique approach in that it recursively builds up half a line at a time and calls the alphabet-building function twice to build a full line. Golfing suggestions welcome.

f=lambda a:a and f(a-1)+chr(64+a)or""
for i in range(-26,27):print f(26-abs(i))+f(27-abs(i))[::-1]
```

Title: Alphabet triangle


答:
Batch, <s>239</s> 186 bytes

```<code>@set/ableen=1431655772,a=%1*3,b=%2*3,c=b-a^>^>31^|1
@for /l %%i in (%a%,%c%,%b%)do @((if %%i==20 echo bleen)&(if %%i==-20 echo -bleen)&set/aj=%%i%%3,k=%%i/3&cmd/cif %%j%%==0 echo %%k%%)
</code>```

Works by looping from 3*%1 to 3*%3 and then dividing by three and printing the numbers with no remainder, however setting bleen to that magic number causes integer overflow and the value 20 is used instead. This is then printed out at the appropriate point in the loop.

Title: A newly discovered number: bleen!

Body:
Batch, <s>239</s> 186 bytes

@set/ableen=1431655772,a=%1*3,b=%2*3,c=b-a^>^>31^|1
@for /l %%i in (%a%,%c%,%b%)do @((if %%i==20 echo bleen)&(if %%i==-20 echo -bleen)&set/aj=%%i%%3,k=%%i/3&cmd/cif %%j%%==0 echo %%k%%)

Works by looping from 3*%1 to 3*%3 and then dividing by three and printing the numbers with no remainder, however setting bleen to that magic number causes integer overflow and the value 20 is used instead. This is then printed out at the appropriate point in the loop.


问:
Construct the Jacobian matrix
Take the vector of unknowns , and apply some generic differentiable function . The Jacobian is then given by a matrix  such that:

For example, suppose m=3 and n=2. Then (using 0-based indexing)

The Jacobian of f is then

The goal of this challenge is to print this Jacobian matrix.

Input

Your program/function should take as input two positive integers m and n, which represent the number of components of f and u respectively. The input may come from any source desired (stdio, function parameter, etc.). You may dictate the order in which these are received, and this must be consistent for any input to your answer (please specify in your answer).

Output

Something which represents the Jacobian matrix. This representation must explicitly spell out all elements of the Jacobian matrix, but the exact form of each term is implementation defined so long as is unambiguous what is being differentiated and with respect to what, and every entry is outputted in a logical order. Example acceptable forms for representing a matrix:

A list of lists where each entry of the outer list corresponds to a row of the Jacobian, and each entry of the inner list corresponds to a column of the Jacobian.

A string or textual output where each line is a row of the Jacobian, and each delimiter separated entry in a line corresponds to a column of the jacobian.

Some graphical/visual representation of a matrix. Example: what is shown by Mathematica when using the MatrixForm command

Some other dense matrix object where every entry is already stored in memory and can be queried (i.e. you can't use a generator object). Example  would be how Mathematica internally represents a Matrix object

Example entry formats:

A string of the form d f_i/d u_j, where i and j are integers. Ex: d f_1/d u_2. Note that these spaces between d and f_1 or x_2 are optional. Additionally, the underscores are also optional.

A string of the form d f_i(u_1,...,u_n)/d u_j or d f_i(u)/d u_j. That is, the input parameters of the function component f_i are optional, and can either be explicitly spelled out or left in compact form.

A formatted graphical output. Ex.: what Mathematica prints when you evaluate the expression D[f_1[u_,u_2,...,u_n],u_1]

You may choose what the starting index for u and f are (please specify in your answer). The output may be to any sink desired (stdio, return value, output parameter, etc.).

Test cases

The following test cases use the convention m,n. Indexes are shown 0-based.

```<code>1,1
[[d f0/d u0]]

2,1
[[d f0/d u0],
 [d f1/d u0]]

2 2
[[d f0/d u0, d f0/d u1],
 [d f1/d u0, d f1/d u1]]

1,2
[[d f0/d u0, d f0/d u1]]

3,3
[[d f0/d u0, d f0/d u1, d f0/d u2],
 [d f1/d u0, d f1/d u1, d f1/d u2],
 [d f2/d u0, d f2/d u1, d f2/d u2]]
</code>```

Scoring

This is code golf; shortest code in bytes wins. Standard loopholes are forbidden. You are allowed to use any built-ins desired.

答:
Cheddar, <s>79</s> 49 bytes

```<code>m->n->(|>m).map(i->(|>n).map(j->"df%d/du%d"%i%j))
</code>```

Apparently a fork of this answer.

For 3,2 returns:

```<code>[["df0/du0", "df0/du1", "df0/du2"], ["df1/du0", "df1/du1", "df1/du2"]]
</code>```

Title: Construct the Jacobian matrix

Body:
Cheddar, <s>79</s> 49 bytes

m->n->(|>m).map(i->(|>n).map(j->"df%d/du%d"%i%j))

Apparently a fork of this answer.

For 3,2 returns:

[["df0/du0", "df0/du1", "df0/du2"], ["df1/du0", "df1/du1", "df1/du2"]]


问:
Tips for golfing in Cheddar

Cheddar is a high-level, functional + object-oriented programming language created by our user Downgoat designed to make programming easier, faster, and more intuitive.

What general tips do you have for golfing in Cheddar? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Cheddar (e.g. "Remove unnecessary whitespace." is not an answer).

答:
Curry

No not red curry (what other curry would you be thinking about ¬_¬). I mean this type of curry:

```<code>a->b->
</code>```

If you have a function taking two arguments. It's shorter to curry than to not:

```<code>(a,b)->
a->b->
</code>```

Note: This is only shorter when you have exactly two arguments.

Title: Tips for golfing in Cheddar

Body:
Curry

No not red curry (what other curry would you be thinking about ¬_¬). I mean this type of curry:

a->b->

If you have a function taking two arguments. It's shorter to curry than to not:

(a,b)->
a->b->

Note: This is only shorter when you have exactly two arguments.


答:
Maxima, 68 bytes

It's too bad I don't know Maxima like I know my dear C and Matlab. But I'll try nontheless.

```<code>f(m,n):=(x:makelist(x[i],i,m),g:makelist(g[i](x),i,n),jacobian(g,x))
</code>```

Example session using TeXmacs as a Maxima interpreter, mostly for neat math rendering:

There may very well be better ways doing lists and such in Maxima (I would especially like to make the functions appear without the list markers, []), but I don't know the language well enough.

Title: Construct the Jacobian matrix

Body:
Take the vector of unknowns , and apply some generic differentiable function . The Jacobian is then given by a matrix  such that:

For example, suppose m=3 and n=2. Then (using 0-based indexing)

The Jacobian of f is then

The goal of this challenge is to print this Jacobian matrix.

Input

Your program/function should take as input two positive integers m and n, which represent the number of components of f and u respectively. The input may come from any source desired (stdio, function parameter, etc.). You may dictate the order in which these are received, and this must be consistent for any input to your answer (please specify in your answer).

Output

Something which represents the Jacobian matrix. This representation must explicitly spell out all elements of the Jacobian matrix, but the exact form of each term is implementation defined so long as is unambiguous what is being differentiated and with respect to what, and every entry is outputted in a logical order. Example acceptable forms for representing a matrix:

A list of lists where each entry of the outer list corresponds to a row of the Jacobian, and each entry of the inner list corresponds to a column of the Jacobian.

A string or textual output where each line is a row of the Jacobian, and each delimiter separated entry in a line corresponds to a column of the jacobian.

Some graphical/visual representation of a matrix. Example: what is shown by Mathematica when using the MatrixForm command

Some other dense matrix object where every entry is already stored in memory and can be queried (i.e. you can't use a generator object). Example  would be how Mathematica internally represents a Matrix object

Example entry formats:

A string of the form d f_i/d u_j, where i and j are integers. Ex: d f_1/d u_2. Note that these spaces between d and f_1 or x_2 are optional. Additionally, the underscores are also optional.

A string of the form d f_i(u_1,...,u_n)/d u_j or d f_i(u)/d u_j. That is, the input parameters of the function component f_i are optional, and can either be explicitly spelled out or left in compact form.

A formatted graphical output. Ex.: what Mathematica prints when you evaluate the expression D[f_1[u_,u_2,...,u_n],u_1]

You may choose what the starting index for u and f are (please specify in your answer). The output may be to any sink desired (stdio, return value, output parameter, etc.).

Test cases

The following test cases use the convention m,n. Indexes are shown 0-based.

```<code>1,1
[[d f0/d u0]]

2,1
[[d f0/d u0],
 [d f1/d u0]]

2 2
[[d f0/d u0, d f0/d u1],
 [d f1/d u0, d f1/d u1]]

1,2
[[d f0/d u0, d f0/d u1]]

3,3
[[d f0/d u0, d f0/d u1, d f0/d u2],
 [d f1/d u0, d f1/d u1, d f1/d u2],
 [d f2/d u0, d f2/d u1, d f2/d u2]]
</code>```

Scoring

This is code golf; shortest code in bytes wins. Standard loopholes are forbidden. You are allowed to use any built-ins desired.

Body:
Maxima, 68 bytes

It's too bad I don't know Maxima like I know my dear C and Matlab. But I'll try nontheless.

f(m,n):=(x:makelist(x[i],i,m),g:makelist(g[i](x),i,n),jacobian(g,x))

Example session using TeXmacs as a Maxima interpreter, mostly for neat math rendering:

There may very well be better ways doing lists and such in Maxima (I would especially like to make the functions appear without the list markers, []), but I don't know the language well enough.


问:
Unsorted majorization of two lists

Definition

A vector a containing n elements is said to
majorize or
dominate a vector b with n
elements iff for all values k such that 1 ≤ k ≤ n, the sum of the first
element of a↓ through the kth element of a↓ is
greater than or equal to the sum of the first through kth elements of
b↓, where v↓ represents the vector v sorted in
descending order.

That is,

```<code>                          a_1 >= b_1
                    a_1 + a_2 >= b_1 + b_2
              a_1 + a_2 + a_3 >= b_1 + b_2 + b_3
                              ...
      a_1 + a_2 + ... + a_n-1 >= b_1 + b_2 + ... + b_n-1
a_1 + a_2 + ... + a_n-1 + a_n >= b_1 + b_2 + ... + b_n-1 + b_n
</code>```

where a and b are sorted in descending order.

For the purpose of this challenge, we will be using a slight generalization of
majorization: we will say a list is an unsorted majorization of another if
all of the above inequalities are true without sorting a and b. (This is,
of course, mathematically useless, but makes the challenge more interesting.)

Challenge

Given an input of two distinct lists a and b of integers in the range 0
through 255 (inclusive), both lists of length n ≥ 1, output whether the first
list unsorted-majorizes the second (a > b), the second unsorted-majorizes
the first (b > a), or neither.

You may optionally require the length of the two lists to be provided as input.
The output must always be one of three distinct values, but the values
themselves may be whatever you want (please specify which values represent a
> b, b > a, and neither in your answer).

Test cases for a > b:

```<code>[255] [254]
[3,2,1] [3,1,2]
[6,1,5,2,7] [2,5,4,3,7]
</code>```

Test cases for b > a:

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

Test cases for no majorization:

```<code>[200,100] [150,250]
[3,1,4] [2,3,3]
[9,9,9,9,9,0] [8,8,8,8,8,9]
</code>```

答:
Jelly, <s>10</s> <s>8</s> 6 bytes

2 bytes thanks to @orlp.

2 bytes thanks to @Dennis.

```<code>_+\ṠQS
</code>```

Try it online!

1 for a>b, -1 for a<b, 0 for no majorization.

```<code>_+\ṠQS

_       Difference (vectorized)
 +\     Cumulative sum.
   Ṡ    Sign of every difference
    Q   Deduplicate
     S  Sum
</code>```

If there were both 1 and -1 present (some cumulative sums are bigger, some smaller), then the last step would produce 0.

Title: Unsorted majorization of two lists

Body:
Jelly, <s>10</s> <s>8</s> 6 bytes

2 bytes thanks to @orlp.

2 bytes thanks to @Dennis.

_+\ṠQS

Try it online!

1 for a>b, -1 for a<b, 0 for no majorization.

_+\ṠQS

_       Difference (vectorized)
 +\     Cumulative sum.
   Ṡ    Sign of every difference
    Q   Deduplicate
     S  Sum

If there were both 1 and -1 present (some cumulative sums are bigger, some smaller), then the last step would produce 0.


问:
Smallest sum (and largest difference) of two 3-digit integers
Given six unique non-negative integers, print the two 3-digit integers comprised of those numbers that sum to the smallest amount.

Additionally,

If there is more than one set of numbers that meets the smallest-sum requirement, print the two that have the greatest difference. For example, 269 + 157 = 267 + 159 = 426; however, 269 - 157 > 267 - 159, so the first set should be printed.

Print the numbers on the same line largest -> smallest, separated by a single space.

Zero (0) cannot be used as a leading number.

Inputs will always be digits.

Testcases

```<code>input        | output
2 6 5 1 9 7  | 269 157
1 9 5 0 8 3  | 359 108
1 2 3 4 5 6  | 246 135
</code>```

Scoring

As this is code golf, shortest entry wins.

答:
Pyth, 17 bytes

```<code>_iRTChf*FhTcR2.pS
</code>```

Try it online

How it works

```<code>_iRTChf*FhTcR2.pS

                S   sort input
              .p    permutations in lexicographic order
           cR2      chop each permutation into groups of 2
      f             filter for results T such that:
         hT           the first group
       *F             has a truthy (nonzero) product
     h              first result
    C               transpose
 iRT                convert both rows to base 10
_                   reverse
</code>```

Body:
Pyth, 17 bytes

_iRTChf*FhTcR2.pS

Try it online

How it works

_iRTChf*FhTcR2.pS

                S   sort input
              .p    permutations in lexicographic order
           cR2      chop each permutation into groups of 2
      f             filter for results T such that:
         hT           the first group
       *F             has a truthy (nonzero) product
     h              first result
    C               transpose
 iRT                convert both rows to base 10
_                   reverse


答:
C, 125 bytes:

```<code>main(w,y,b,q){scanf("%d %d",&w,&y);for(b=0;b<w;b++){for(q=0;q<y;q++)printf("d f%d/du u%d%s",b,q,q<y-1?", ":"");printf("\n");}}
</code>```

Takes input as 2 space separated integers, b y, and outputs the Jacobian Matrix as y comma separated strings on b lines.

C It Online! (Ideone) or Test Suite (Ideone)

Title: Construct the Jacobian matrix

Body:
C, 125 bytes:

main(w,y,b,q){scanf("%d %d",&w,&y);for(b=0;b<w;b++){for(q=0;q<y;q++)printf("d f%d/du u%d%s",b,q,q<y-1?", ":"");printf("\n");}}

Takes input as 2 space separated integers, b y, and outputs the Jacobian Matrix as y comma separated strings on b lines.

C It Online! (Ideone) or Test Suite (Ideone)


问:
Count the rectangles in a diagonal grid
As a follow-up to this challenge, we now want to count the number of rectangles in grid with r rows and c columns where there is a line crossing through every diagonal of a square in the grid. Now, we are still counting the the same rectangles as before, but this time we must also include rectangles that are tilted by 45 degrees.

Your goal is to create a function or program that given the number of rows r and columns c outputs the number of rectangles in a diagonal grid with dimensions (r, c).

As a demonstration, this is an animation that iterates through all 37 rectangles formed by a (2 x 3) diagonal grid.

Test Cases

```<code>Each case is [rows, columns] = # of rectangles
[0, 0] = 0
[0, 1] = 0
[1, 0] = 0
[1, 1] = 1
[3, 2] = 37
[2, 3] = 37
[6, 8] = 2183
[7, 11] = 5257
[18, 12] = 40932
[42, 42] = 2889558
[51, 72] = 11708274
</code>```

Rules

This is code-golf so the shortest code wins.

Builtins that solve this are not allowed.

ContentLicense: CC BY-SA 4.0

Title: Count the rectangles in a diagonal grid

Body:
C, 71 64 bytes

f(m,n){return n>m?f(n,m):m*~m*n*~n/4+n*((2*m-n)*(4*n*n-1)-3)/6;}

Try it on Ideone


答:
Perl, <s>88</s> <s>66</s> <s>64</s> <s>66</s> 64 Bytes

```<code>@a[0..2]=@a[1,2,0]if!(@a=sort@ARGV)[0];say@a[1,3,5],$",@a[0,2,4]
</code>```

<s>Prints the two numbers with no space between them :/</s>

Needs -M5.01 flag

Thanks to @msh210 and @Dada for helping to reduce byte count!

Title: Smallest sum (and largest difference) of two 3-digit integers

Body:
Given six unique non-negative integers, print the two 3-digit integers comprised of those numbers that sum to the smallest amount.

Additionally,

If there is more than one set of numbers that meets the smallest-sum requirement, print the two that have the greatest difference. For example, 269 + 157 = 267 + 159 = 426; however, 269 - 157 > 267 - 159, so the first set should be printed.

Print the numbers on the same line largest -> smallest, separated by a single space.

Zero (0) cannot be used as a leading number.

Inputs will always be digits.

Testcases

```<code>input        | output
2 6 5 1 9 7  | 269 157
1 9 5 0 8 3  | 359 108
1 2 3 4 5 6  | 246 135
</code>```

Scoring

As this is code golf, shortest entry wins.

Body:
Perl, <s>88</s> <s>66</s> <s>64</s> <s>66</s> 64 Bytes

@a[0..2]=@a[1,2,0]if!(@a=sort@ARGV)[0];say@a[1,3,5],$",@a[0,2,4]

<s>Prints the two numbers with no space between them :/</s>

Needs -M5.01 flag

Thanks to @msh210 and @Dada for helping to reduce byte count!


答:
JavaScript (ES6), 59 bytes

```<code>a=>a[b=!!+a.sort()[0],2-b]+a[3]+a[5]+' '+a[1-b]+a[b+b]+a[4]
</code>```

Takes input as a character array (e.g. [..."195083"]) and returns two space-separated numbers in a string. 57 bytes if I can return the smaller number first:

```<code>a=>a[b=+!+a.sort()[0]]+a[2-b-b]+a[4]+' '+a[1+b]+a[3]+a[5]
</code>```

Body:
JavaScript (ES6), 59 bytes

a=>a[b=!!+a.sort()[0],2-b]+a[3]+a[5]+' '+a[1-b]+a[b+b]+a[4]

Takes input as a character array (e.g. [..."195083"]) and returns two space-separated numbers in a string. 57 bytes if I can return the smaller number first:

a=>a[b=+!+a.sort()[0]]+a[2-b-b]+a[4]+' '+a[1+b]+a[3]+a[5]


答:
PowerShell v2+, <s>90</s> 68 bytes

```<code>$a,$b=(($n=$args|sort)-ne0)[0,1];"$b{1}{3} $a{0}{2}"-f($n-ne$a-ne$b)
</code>```

Not quite as short as others, but showcases some nifty tricks.

Takes input as command-line arguments $args, sorts them, saves that into $n. That's encapsulated in parens and used as the left-hand argument to -ne0, which pulls out all elements not equal to zero (in PowerShell, array -comparator scalar functions as a filter). That resultant array is re-captured in parens, and the 0th(Hi Dennis) and 1st elements plucked out, and uses multiple-assignment to store them into $a and $b. This ensures that the smallest non-zero element is in $a and the next smallest non-zero element is in $b, and those form the basis for our output string.

The next portion is a string "..." using the -format operator. We specify locations in the string {0} for where that particular item goes. We feed to the -f operator the original (sorted) array $n, except without elements $a and $b, so four elements, which correspond to the 1,3,0,2 of the brackets. That string is left on the pipeline and output is implicit.

For a worked out example, let's assume that the OP meant non-negative input numbers, to match the test case of 1 9 5 0 8 3. This starts by sorting the input array, so we have 0 1 3 5 8 9 and re-saving that into $n. We pluck out the non-zero elements, so 1 3 5 8 9, and choose the [0,1] indices thereof. That means that $a=1 and $b=3, and thus we'll always know a < b and neither a nor b are 0.

Those are replaced in the string, so we have "3{1}{3} 1{0}{2}" to start. The -f operator takes the result of our array operation. Since $n is already still sorted, the pair of -ne operators result in 0 5 8 9 being fed to -f. As we're wanting the smallest sum, we obviously want the smaller elements to be used first. But, as we're wanting the largest difference, we want the larger elements to be associated to b. Hence, the {1}{3}{0}{2} arrangement for the indexing. This results in the string "359 108", the proper answer.

Body:
PowerShell v2+, <s>90</s> 68 bytes

$a,$b=(($n=$args|sort)-ne0)[0,1];"$b{1}{3} $a{0}{2}"-f($n-ne$a-ne$b)

Not quite as short as others, but showcases some nifty tricks.

Takes input as command-line arguments $args, sorts them, saves that into $n. That's encapsulated in parens and used as the left-hand argument to -ne0, which pulls out all elements not equal to zero (in PowerShell, array -comparator scalar functions as a filter). That resultant array is re-captured in parens, and the 0th(Hi Dennis) and 1st elements plucked out, and uses multiple-assignment to store them into $a and $b. This ensures that the smallest non-zero element is in $a and the next smallest non-zero element is in $b, and those form the basis for our output string.

The next portion is a string "..." using the -format operator. We specify locations in the string {0} for where that particular item goes. We feed to the -f operator the original (sorted) array $n, except without elements $a and $b, so four elements, which correspond to the 1,3,0,2 of the brackets. That string is left on the pipeline and output is implicit.

For a worked out example, let's assume that the OP meant non-negative input numbers, to match the test case of 1 9 5 0 8 3. This starts by sorting the input array, so we have 0 1 3 5 8 9 and re-saving that into $n. We pluck out the non-zero elements, so 1 3 5 8 9, and choose the [0,1] indices thereof. That means that $a=1 and $b=3, and thus we'll always know a < b and neither a nor b are 0.

Those are replaced in the string, so we have "3{1}{3} 1{0}{2}" to start. The -f operator takes the result of our array operation. Since $n is already still sorted, the pair of -ne operators result in 0 5 8 9 being fed to -f. As we're wanting the smallest sum, we obviously want the smaller elements to be used first. But, as we're wanting the largest difference, we want the larger elements to be associated to b. Hence, the {1}{3}{0}{2} arrangement for the indexing. This results in the string "359 108", the proper answer.


问:
Power modulo golf.
Write a function f(a,b,c) that calculates a^b (mod c) in less than 10 seconds.

a, b < 10^100

c < 10000.

examples:

```<code>f(10^50, 10^50, 54123) = 46555
f(5^99, 10^99, 777) = 1
</code>```

答:
dc 1 or 5 chars

In GNU dc, there is the operator |, doing exactly this. Quoted from the manual:

| Pops  three  values  and computes a modular exponentiation.  The first value popped is used as the reduction modulus; this  value must be a non-zero number, and should be an integer.  The second popped is used as the exponent; this value must be  a  non-negative  number,  and  any fractional part of this exponent will be ignored.  The third value popped is the base which gets exponentiated,  which should be an integer.  For small integers this is like the sequence Sm^Lm%, but, unlike ^, this command will  work with arbitrarily large exponents.

You may assign it to "function" as following:

```<code>[|]sf
</code>```

(also 5 chars...) This assigns | to f. You may call it like lfx.

ContentLicense: CC BY-SA 2.5

Title: Power modulo golf.

Body:
dc 1 or 5 chars

In GNU dc, there is the operator |, doing exactly this. Quoted from the manual:

| Pops  three  values  and computes a modular exponentiation.  The first value popped is used as the reduction modulus; this  value must be a non-zero number, and should be an integer.  The second popped is used as the exponent; this value must be  a  non-negative  number,  and  any fractional part of this exponent will be ignored.  The third value popped is the base which gets exponentiated,  which should be an integer.  For small integers this is like the sequence Sm^Lm%, but, unlike ^, this command will  work with arbitrarily large exponents.

You may assign it to "function" as following:

[|]sf

(also 5 chars...) This assigns | to f. You may call it like lfx.


问:
Domino Effect Problem
Last week we had a programming contest in my university and I am very curious about one of the problems , one which only one team (but from another city) was able to solve. Maybe its not that hard, but I cant find any solutions that will take less than a second of execution time. The problem is the following:

Problem

You have N domino tiles separated by different amounts (integer values that are given to you) and you know the height H of these tiles (all have the same height). They are all placed standing up so that if you push one it falls in the direction of the next one. This way, if tile I is close enough (H or less) to tile I+1, the first one will push the second one when it is pushed down, producing the domino effect. Suppose that not all the distances that separate the tiles are smaller than H, what's the minimum amount of moves you need to make in order to have all the distances be at most H? You can't move the first nor the last tile. Print a falsey value if it is not possible.

Note: You are only allowed to move integer amounts and only to spots on the line defined by tile i-1 and tile i+1. This means you cant grab one and place it wherever you want.

Here are the input sizes: (3 ≤ N ≤ 1000) (1 ≤ H ≤ 50)  and the distances (1 ≤ Di ≤ 100 for i = 1, 2, ..., N-1). Someone uploaded it to SPOJ recently

Input:

N H

d1 d2 d3 d4 ... d(n-1)

Output:

Minimum amount of moves.

Sample

Input1

8 3

2 4 4 1 4 3 2

Output1

3

Sample2

Input2

10 2

1 2 2 2 2 2 2 2 3

Output2

8

Sample3

Input3

5 2

2 2 2 2

Output3

0

Sample4

Input4

5 3

1 6 2 4

Output4

-1 (NOT POSSIBLE)

I have only found a good solution for two cases (Pseudo-Code):

```<code>D=sum_of_all_distances
MaxPossible=(N-1)*H

if D==MaxPossible and there is no di such that di>H
    Answer=0

else if D>MaxPossible
    Answer=-1
</code>```

答:
I tried in Perl which tries immediate tile distance adjustment and then cascading movements to get required distance

Execution syntax perl programName N H d1 d2 ... dn-1

Test cases sample: perl domino_slider.pl 8 3 2 4 4 1 4 3 2 output :3

```<code>use subs /dominochecker distancechecker subcheckright subcheckleft RigidMode/;

## Receive Input Tile Height D1 D2 ... Dn-1
$Tiles=$ARGV[0];
$Height=$ARGV[1];
$loop_count=0;
for $i (2...$#ARGV){
   $distance[$loop_count]=$ARGV[$i];
   $loop_count++;
}

$loop_count=$move=0;

sub dominochecker {
   $lc=0;$retflag=0;
   while ($lc<$Tiles-1) {
     if ($distance[$lc]>$Height) {
         $retflag=1;
     }
     $lc++;
   }
   return $retflag;
}

sub subcheckleft {
   $lc=0;$retflag=0;$c=$_[0];
   while ($lc<$c) {
     if ($distance[$lc]>$Height) {
         $retflag=1;
     }
     $lc++;
   }
   return $retflag;
}

sub subcheckright {
   $retflag=0;$c=$_[0];
   while ($c<$Tiles-1) {
     if ($distance[$c]>$Height) {
         $retflag=1;
     }
     $c++;
   }
   return $retflag;
}

$loop_count=$move=0;

if (dominochecker==0) { ## if already in Domino Effect
print "\n $move \n";
exit;
}

sub RigidMode{
$loopend=$_[0];
$loop_count_local=0;
while ($loop_count_local<$loopend) {
  if ($distance[$loop_count_local]<=$Height) {
    $loop_count_local++;
  } else {
    if ($distance[$loop_count_local-1]<$Height && $loop_count_local+1 !=1 && defined($distance[$loop_count_local-1]) ) {
       $move++;
       $available=$Height-$distance[$loop_count_local-1];
       $required=$distance[$loop_count_local]-$Height;
       if($available<=$required) {
       $distance[$loop_count_local-1]=$distance[$loop_count_local-1]+$available;
       $distance[$loop_count_local]=$distance[$loop_count_local]-$available;
       }else{
       $distance[$loop_count_local-1]=$distance[$loop_count_local-1]+$required;
       $distance[$loop_count_local]=$distance[$loop_count_local]-$required;
       }
       $loop_count_local=0;
    }elsif($distance[$loop_count_local+1]<$Height && $loop_count_local+2 !=$Tiles && defined($distance[$loop_count_local+1]) ){
       $available=$Height-$distance[$loop_count_local+1];
       $required=$distance[$loop_count_local]-$Height;
       if($available<=$required) {
       $distance[$loop_count_local+1]=$distance[$loop_count_local+1]+$available;
       $distance[$loop_count_local]=$distance[$loop_count_local]-$available;
       }else{
       $distance[$loop_count_local+1]=$distance[$loop_count_local+1]+$required;
       $distance[$loop_count_local]=$distance[$loop_count_local]-$required;
       }
       $move++;
       $loop_count_local=0;
    }
    else{
    $loop_count_local++;
    }
  }
}
}

RigidMode($Tiles-1);

if (dominochecker==0) {
    print "\n $move \n";
    exit;
}else{
    $loop_count=$move=0;
    for $i (2...$#ARGV){
        $distance[$loop_count]=$ARGV[$i];
        $loop_count++;
    }
    $loop_count=$move=0;
    while ($loop_count<$Tiles-1) {
    if ($distance[$loop_count]<$Height) {
       $available=$Height-$distance[$loop_count];
       if (subcheckleft($loop_count)>0){
         $move++ if $distance[$loop_count-1]-$available>0;
         $distance[$loop_count]=$Height if $distance[$loop_count-1]-$available>0 ;
         $distance[$loop_count-1]=$distance[$loop_count-1]-$available if $distance[$loop_count-1]-$available>0;
         RigidMode($loop_count+1);
         $loop_count=0 if $distance[$loop_count-1]-$available>0;
         $loop_count++ if $distance[$loop_count-1]-$available<=0;
       }elsif(subcheckright($loop_count)>0) {
         $move++ if $distance[$loop_count+1]-$available>0;
         $distance[$loop_count]=$Height if $distance[$loop_count+1]-$available>0;
         $distance[$loop_count+1]=$distance[$loop_count+1]-$available if $distance[$loop_count+1]-$available>0;
         RigidMode($loop_count+1);
         $loop_count=0 if $distance[$loop_count+1]-$available>0;
         $loop_count++ if $distance[$loop_count+1]-$available<=0;
       }else{
         $loop_count++;
       }
    }else{
         $loop_count++;
    }
    }
}

if (dominochecker==0) {
    print "\n $move \n";
    exit;
}
else{
    print "\n -1 \n";
    exit;
}
</code>```

Title: Domino Effect Problem

Body:
I tried in Perl which tries immediate tile distance adjustment and then cascading movements to get required distance

Execution syntax perl programName N H d1 d2 ... dn-1

Test cases sample: perl domino_slider.pl 8 3 2 4 4 1 4 3 2 output :3

use subs /dominochecker distancechecker subcheckright subcheckleft RigidMode/;

## Receive Input Tile Height D1 D2 ... Dn-1
$Tiles=$ARGV[0];
$Height=$ARGV[1];
$loop_count=0;
for $i (2...$#ARGV){
   $distance[$loop_count]=$ARGV[$i];
   $loop_count++;
}

$loop_count=$move=0;

sub dominochecker {
   $lc=0;$retflag=0;
   while ($lc<$Tiles-1) {
     if ($distance[$lc]>$Height) {
         $retflag=1;
     }
     $lc++;
   }
   return $retflag;
}

sub subcheckleft {
   $lc=0;$retflag=0;$c=$_[0];
   while ($lc<$c) {
     if ($distance[$lc]>$Height) {
         $retflag=1;
     }
     $lc++;
   }
   return $retflag;
}

sub subcheckright {
   $retflag=0;$c=$_[0];
   while ($c<$Tiles-1) {
     if ($distance[$c]>$Height) {
         $retflag=1;
     }
     $c++;
   }
   return $retflag;
}

$loop_count=$move=0;

if (dominochecker==0) { ## if already in Domino Effect
print "\n $move \n";
exit;
}

sub RigidMode{
$loopend=$_[0];
$loop_count_local=0;
while ($loop_count_local<$loopend) {
  if ($distance[$loop_count_local]<=$Height) {
    $loop_count_local++;
  } else {
    if ($distance[$loop_count_local-1]<$Height && $loop_count_local+1 !=1 && defined($distance[$loop_count_local-1]) ) {
       $move++;
       $available=$Height-$distance[$loop_count_local-1];
       $required=$distance[$loop_count_local]-$Height;
       if($available<=$required) {
       $distance[$loop_count_local-1]=$distance[$loop_count_local-1]+$available;
       $distance[$loop_count_local]=$distance[$loop_count_local]-$available;
       }else{
       $distance[$loop_count_local-1]=$distance[$loop_count_local-1]+$required;
       $distance[$loop_count_local]=$distance[$loop_count_local]-$required;
       }
       $loop_count_local=0;
    }elsif($distance[$loop_count_local+1]<$Height && $loop_count_local+2 !=$Tiles && defined($distance[$loop_count_local+1]) ){
       $available=$Height-$distance[$loop_count_local+1];
       $required=$distance[$loop_count_local]-$Height;
       if($available<=$required) {
       $distance[$loop_count_local+1]=$distance[$loop_count_local+1]+$available;
       $distance[$loop_count_local]=$distance[$loop_count_local]-$available;
       }else{
       $distance[$loop_count_local+1]=$distance[$loop_count_local+1]+$required;
       $distance[$loop_count_local]=$distance[$loop_count_local]-$required;
       }
       $move++;
       $loop_count_local=0;
    }
    else{
    $loop_count_local++;
    }
  }
}
}

RigidMode($Tiles-1);

if (dominochecker==0) {
    print "\n $move \n";
    exit;
}else{
    $loop_count=$move=0;
    for $i (2...$#ARGV){
        $distance[$loop_count]=$ARGV[$i];
        $loop_count++;
    }
    $loop_count=$move=0;
    while ($loop_count<$Tiles-1) {
    if ($distance[$loop_count]<$Height) {
       $available=$Height-$distance[$loop_count];
       if (subcheckleft($loop_count)>0){
         $move++ if $distance[$loop_count-1]-$available>0;
         $distance[$loop_count]=$Height if $distance[$loop_count-1]-$available>0 ;
         $distance[$loop_count-1]=$distance[$loop_count-1]-$available if $distance[$loop_count-1]-$available>0;
         RigidMode($loop_count+1);
         $loop_count=0 if $distance[$loop_count-1]-$available>0;
         $loop_count++ if $distance[$loop_count-1]-$available<=0;
       }elsif(subcheckright($loop_count)>0) {
         $move++ if $distance[$loop_count+1]-$available>0;
         $distance[$loop_count]=$Height if $distance[$loop_count+1]-$available>0;
         $distance[$loop_count+1]=$distance[$loop_count+1]-$available if $distance[$loop_count+1]-$available>0;
         RigidMode($loop_count+1);
         $loop_count=0 if $distance[$loop_count+1]-$available>0;
         $loop_count++ if $distance[$loop_count+1]-$available<=0;
       }else{
         $loop_count++;
       }
    }else{
         $loop_count++;
    }
    }
}

if (dominochecker==0) {
    print "\n $move \n";
    exit;
}
else{
    print "\n -1 \n";
    exit;
}


答:
JavaScript (ES6), 158

Nice challenge, hard to golf. Probably the range methods used in Python and Ruby answers could score better even in JS.

```<code>(a,b)=>(c=x=>x<-6?x-1:x>6?x+1:1/x?x:x<'b'?-7:7,a=c(a),b=c(b),d=b>a?1:-1,a-=d,e=x=>x-7?x-(x>7):'bleen',[...Array(d*(b-a))].map((x=a+=d)=>x<0?'-'+e(-x):e(x)))
</code>```

Less golfed

```<code>(a,b)=>(
  c=x=>x<-6?x-1:x>6?x+1:1/x?x:x<'b'?-7:7,
  a=c(a),b=c(b),
  d=b>a?1:-1,
  a-=d,
  e=x=>x-7?x-(x>7):'bleen',
  [...Array(d*(b-a))].map((x=a+=d)=>x<0?'-'+e(-x):e(x))
)
</code>```

Test

f=(a,b)=>(c=x=>x<-6?x-1:x>6?x+1:1/x?x:x<'b'?-7:7,a=c(a),b=c(b),d=b>a?1:-1,a-=d,e=x=>x-7?x-(x>7):'bleen',[...Array(d*(b-a))].map((x=a+=d)=>x<0?'-'+e(-x):e(x)))

function go(){
  var a=A.value,b=B.value
  // make them numeric if possible
  a=isNaN(a)?a:+a
  b=isNaN(b)?b:+b

  O.textContent=f(a,b)
}
go()```
<pre class="snippet-code-html lang-html prettyprint-override"><code>A <select id=A onchange='go()'>
<option>-10<option>-9<option>-8<option>-7<option>-bleen<option>-6<option>-5<option>-4<option>-3<option>-2<option>-1<option>0
<option>1<option>2<option>3<option>4<option>5<option>6<option>bleen<option>7<option>8<option>9<option>10
</select>
B <select id=B onchange='go()'>
<option>-10<option>-9<option>-8<option>-7<option>-bleen<option>-6<option>-5<option>-4<option>-3<option>-2<option>-1<option>0
<option>1<option>2<option>3<option>4<option>5<option>6<option>bleen<option>7<option>8<option>9<option selected>10
</select>
<pre id=O>``````

Title: A newly discovered number: bleen!

Body:
"The Nobel Prize in mathematics was awarded to a California professor who has discovered a new number! The number is bleen, which he claims belongs between 6 and 7."  --George Carlin

In this challenge, you will print all Integers, inclusive, within the given input range.  Print numbers ascending or descending according to their input order.  That is, for input [n1, n2], print ascending if n1 < n2, descending if n1 > n2.

Since bleen is now an Integer number it may be used as input.  It must also be included in the output, between 6 and 7 where applicable.  Also note that -bleen exists between -7 and -6.

Input

Two Integers [n1, n2] in the range [-10, 10], inclusive, via your programming language's input of choice.

(Input may also contain bleen and -bleen!)

Output

Print all Integers starting at n1 and ending with n2, including the newly discovered bleen between 6 and 7.  Output can be a range of character separated numbers in some form your language supports - that is, comma or space separated.  One trailing space of output is okay.

Examples

```<code>Input:  1 10
Output: 1 2 3 4 5 6 bleen 7 8 9 10

Input:  -9 -4
Output: -9 -8 -7 -bleen -6 -5 -4

Input:  -8 bleen
Output: -8 -7 -bleen -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 bleen

Input:  9 1
Output: 9 8 7 bleen 6 5 4 3 2 1

Input:  2 -bleen
Output: 2 1 0 -1 -2 -3 -4 -5 -6 -bleen

Input:  -bleen 0
Output: -bleen -6 -5 -4 -3 -2 -1 0

Input:  bleen bleen
Output: bleen

Input:  2 2
Output: 2
</code>```

Additional notes

You may write a program or function and use any standard method of receiving input and providing output.

You may use any programming language, but standard loopholes are not allowed.

This is code-golf, so the shortest valid answer – measured in bytes – wins.

Body:
JavaScript (ES6), 158

Nice challenge, hard to golf. Probably the range methods used in Python and Ruby answers could score better even in JS.

(a,b)=>(c=x=>x<-6?x-1:x>6?x+1:1/x?x:x<'b'?-7:7,a=c(a),b=c(b),d=b>a?1:-1,a-=d,e=x=>x-7?x-(x>7):'bleen',[...Array(d*(b-a))].map((x=a+=d)=>x<0?'-'+e(-x):e(x)))

Less golfed

(a,b)=>(
  c=x=>x<-6?x-1:x>6?x+1:1/x?x:x<'b'?-7:7,
  a=c(a),b=c(b),
  d=b>a?1:-1,
  a-=d,
  e=x=>x-7?x-(x>7):'bleen',
  [...Array(d*(b-a))].map((x=a+=d)=>x<0?'-'+e(-x):e(x))
)

Test

f=(a,b)=>(c=x=>x<-6?x-1:x>6?x+1:1/x?x:x<'b'?-7:7,a=c(a),b=c(b),d=b>a?1:-1,a-=d,e=x=>x-7?x-(x>7):'bleen',[...Array(d*(b-a))].map((x=a+=d)=>x<0?'-'+e(-x):e(x)))

function go(){
  var a=A.value,b=B.value
  // make them numeric if possible
  a=isNaN(a)?a:+a
  b=isNaN(b)?b:+b

  O.textContent=f(a,b)
}
go()

A <select id=A onchange='go()'>
<option>-10<option>-9<option>-8<option>-7<option>-bleen<option>-6<option>-5<option>-4<option>-3<option>-2<option>-1<option>0
<option>1<option>2<option>3<option>4<option>5<option>6<option>bleen<option>7<option>8<option>9<option>10
</select>
B <select id=B onchange='go()'>
<option>-10<option>-9<option>-8<option>-7<option>-bleen<option>-6<option>-5<option>-4<option>-3<option>-2<option>-1<option>0
<option>1<option>2<option>3<option>4<option>5<option>6<option>bleen<option>7<option>8<option>9<option selected>10
</select>
<pre id=O></pre>


问:
Sort band names

Challenge description

You have a music library with many tracks recorded by many bands, each of which has a name, like Queen, Aerosmith, Sunny Day Real Estate, The Strokes . When an audio player displays your library alphabetically by band name, it usually skips the The part, as many band names start with The, making it easier to navigate through your media collection. In this challenge, given a list (array) of strings, you need to sort it that way (that is, omitting the The word at the beginning of the name). You can either write a method or a full working program.

Sample inputs / outputs

```<code>[Queen, Aerosmith, Sunny Day Real Estate, The Strokes] -> [Aerosmith, Queen, The Strokes, Sunny Day Real Estate]
[The Ramones, The Cure, The Pixies, The Roots, The Animals, Enrique Iglesias] -> [The Animals, The Cure, Enrique Iglesias, The Pixies, The Ramones, The Roots]
[The The, The They, Thermodynamics] -> [The The, Thermodynamics, The They]
</code>```

Notes / Edge cases

Sorting lexicographically is case insensitive, so The Police, The police and the police are all equivalent,

Your algorithm should only omit the first the word, so bands named The The or The The Band are sorted normally by the second the,

A band named The (a three letter word) is sorted normally (no skipping),

Order of two bands having the same name, one of which starts with the (like The Police and Police) is undefined,

You can assume that if a band's name consists of more than one word, they are separated by a single space character. You don't need to handle leading or trailing whitespaces,

All input strings match [A-Za-z0-9 ]*, that is they will consist only of lower- and uppercase letters of English alphabet, digits and space characters,

Remember that this is a code-golf challenge, so make your code as short as possible!

答:
BASH, 64 Bytes

```<code>sed 's/^the / /;s/^The /    /'|sort -fb|sed 's/^ /the /;s/^ /The /'
</code>```

Input: stdin, one band per line.
Output: stdout

Note: The second replacements (s/^The/  / and s/^   /The /) use the tab character, so they don't always copy/paste correctly.

Title: Sort band names

Body:
BASH, 64 Bytes

sed 's/^the / /;s/^The /    /'|sort -fb|sed 's/^ /the /;s/^ /The /'

Input: stdin, one band per line.
Output: stdout

Note: The second replacements (s/^The/  / and s/^   /The /) use the tab character, so they don't always copy/paste correctly.


答:
Python 3, 132 130 bytes

```<code>r=round
bleen=6.1
m=1.08
a,b=eval(input())
d=1-2*(a>b)
print(*[[r(i/m),"-bleen"[i>0:]][i*i==49]for i in range(r(m*a),d+r(m*b),d)])
</code>```

Takes input in the following example format:

```<code>-8, bleen
</code>```

Title: A newly discovered number: bleen!

Body:
Python 3, 132 130 bytes

r=round
bleen=6.1
m=1.08
a,b=eval(input())
d=1-2*(a>b)
print(*[[r(i/m),"-bleen"[i>0:]][i*i==49]for i in range(r(m*a),d+r(m*b),d)])

Takes input in the following example format:

-8, bleen


答:
Perl 6, 82 bytes

*.permutations.map({my@a=.join.comb(3);@a if @a.all>100}).min({.sum,[R-] |$_}).put
```

<h3>Usage:</h3>

<pre class="lang-perl6 prettyprint-override"><code>my &small = *.permutations.map({my@a=.join.comb(3);@a if @a.all>100}).min({.sum,[R-] |$_}).put;

small [2,6,5,1,9,7]; # 269 157
small [1,9,5,0,8,3]; # 359 108
small [1,2,3,4,5,6]; # 246 135
</code>```

Explanation:

# Whatever lambda with input ｢*｣
*.permutations

  .map({

    # join and split into 3 character chunks
    my @a = $_.join.comb(3);

    # return the values if neither start with ｢0｣
    @a if @a.all > 100

  })

  # find the minimum
  .min({

    # by sum first
    $_.sum,

    # and reversed subtraction second
    # ( biggest difference in reversed order )
    [R-] |$_

  })

  # print it on a line, space separated
  .put
```

Body:
Perl 6, 82 bytes

*.permutations.map({my@a=.join.comb(3);@a if @a.all>100}).min({.sum,[R-] |$_}).put

Usage:

my &small = *.permutations.map({my@a=.join.comb(3);@a if @a.all>100}).min({.sum,[R-] |$_}).put;

small [2,6,5,1,9,7]; # 269 157
small [1,9,5,0,8,3]; # 359 108
small [1,2,3,4,5,6]; # 246 135

Explanation:

# Whatever lambda with input ｢*｣
*.permutations

  .map({

    # join and split into 3 character chunks
    my @a = $_.join.comb(3);

    # return the values if neither start with ｢0｣
    @a if @a.all > 100

  })

  # find the minimum
  .min({

    # by sum first
    $_.sum,

    # and reversed subtraction second
    # ( biggest difference in reversed order )
    [R-] |$_

  })

  # print it on a line, space separated
  .put


答:
Python, <s>73</s> 68 bytes

```<code>x=lambda m,n:m*~m*n*~n/4+n*((2*m-n)*(4*n*n-1)-3)/6if m>n else x(n,m)
</code>```

And while the following version has a higher bytecount (75), it was a nice exercise in finding places to use ~:

```<code>def f(r,c):
 if r<c:r,c=c,r
 x=(4*c**3-c)/3
 return r*c*~r*~c/4+x*r--~x*c/2
</code>```

Title: Count the rectangles in a diagonal grid

Body:
As a follow-up to this challenge, we now want to count the number of rectangles in grid with r rows and c columns where there is a line crossing through every diagonal of a square in the grid. Now, we are still counting the the same rectangles as before, but this time we must also include rectangles that are tilted by 45 degrees.

Your goal is to create a function or program that given the number of rows r and columns c outputs the number of rectangles in a diagonal grid with dimensions (r, c).

As a demonstration, this is an animation that iterates through all 37 rectangles formed by a (2 x 3) diagonal grid.

Test Cases

```<code>Each case is [rows, columns] = # of rectangles
[0, 0] = 0
[0, 1] = 0
[1, 0] = 0
[1, 1] = 1
[3, 2] = 37
[2, 3] = 37
[6, 8] = 2183
[7, 11] = 5257
[18, 12] = 40932
[42, 42] = 2889558
[51, 72] = 11708274
</code>```

Rules

This is code-golf so the shortest code wins.

Builtins that solve this are not allowed.

Body:
Python, <s>73</s> 68 bytes

x=lambda m,n:m*~m*n*~n/4+n*((2*m-n)*(4*n*n-1)-3)/6if m>n else x(n,m)

And while the following version has a higher bytecount (75), it was a nice exercise in finding places to use ~:

def f(r,c):
 if r<c:r,c=c,r
 x=(4*c**3-c)/3
 return r*c*~r*~c/4+x*r--~x*c/2


答:
Convex, <s>37</s> 36 bytes

```<code>__:)+×½½\~æ<{\}&:N\¦\-N¦¦N*(*3-N*6/+
</code>```

Try it online!

Uses betseg's algorithm modified and optimized for a stack-based language. Explanation to come when I have some more free time. I bet this can be shortened but I'm not going to bother at the moment.

Title: Count the rectangles in a diagonal grid

Body:
Convex, <s>37</s> 36 bytes

__:)+×½½\~æ<{\}&:N\¦\-N¦¦N*(*3-N*6/+

Try it online!

Uses betseg's algorithm modified and optimized for a stack-based language. Explanation to come when I have some more free time. I bet this can be shortened but I'm not going to bother at the moment.


问:
Images with all colors
Similar to the images on allrgb.com, make images where each pixel is a unique color (no color is used twice and no color is missing).

Give a program that generates such an image, along with a screenshot or file of the output (upload as PNG).

Create the image purely algorithmically.

Image must be 256×128 (or grid that can be screenshot and saved at 256×128)

Use all 15-bit colors*

No external input allowed (also no web queries, URLs or databases)

No embedded images allowed (source code which is an image is fine, e.g. Piet)

Dithering is allowed

This is not a short code contest, although it might win you votes.

If you're really up for a challenge, do 512×512, 2048×1024 or 4096×4096 (in increments of 3 bits).

Scoring is by vote. Vote for the most beautiful images made by the most elegant code and/or interesting algorithm.

Two-step algorithms, where you first generate a nice image and then fit all pixels to one of the available colors, are of course allowed, but won't win you elegance points.

* 15-bit colors are the 32768 colors that can be made by mixing 32 reds, 32 greens, and 32 blues, all in equidistant steps and equal ranges. Example: in 24 bits images (8 bit per channel), the range per channel is 0..255 (or 0..224), so divide it up into 32 equally spaced shades.

To be very clear, the array of image pixels should be a permutation, because all possible images have the same colors, just at different pixels locations. I'll give a trivial permutation here, which isn't beautiful at all:

Java 7

import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.imageio.ImageIO;

public class FifteenBitColors {
    public static void main(String[] args) {
        BufferedImage img = new BufferedImage(256, 128, BufferedImage.TYPE_INT_RGB);

        // Generate algorithmically.
        for (int i = 0; i < 32768; i++) {
            int x = i & 255;
            int y = i / 256;
            int r = i << 3 & 0xF8;
            int g = i >> 2 & 0xF8;
            int b = i >> 7 & 0xF8;
            img.setRGB(x, y, (r << 8 | g) << 8 | b);
        }

        // Save.
        try (OutputStream out = new BufferedOutputStream(new FileOutputStream("RGB15.png"))) {
            ImageIO.write(img, "png", out);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
```

Winner

Because the 7 days are over, I'm declaring a winner

However, by no means, think this is over. I, and all readers, always welcome more awesome designs. Don't stop creating.

Winner: fejesjoco with 231 votes

答:
C#

So I started working on this just as a fun exercise and ended up with an output that at least to me looks pretty neat. The key difference in my solution to (at least) most others is that I'm generating exactly the number of colors needed to start with and evenly spacing the generation out from pure white to pure black.
I'm also setting colors working in an inward spiral and choosing the next color based on the average of the color diff between all neighbors that have been set.

Here is a small sample output that I've produced so far, I'm working on a 4k render but I expect it to take upwards of a day to finish.

Here is a sample of the spec output at 256x128:

Some larger images with still reasonable render times:

Second run at 360 x 240 produced a much smoother image

After improving performance I was able to run a HD render which took 2 days, I haven't given up on a 4k yet but it could take weeks.

HD Render

```<code>using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;

namespace SandBox
{
    class Program
    {
        private static readonly List<Point> directions = new List<Point>
        {
            new Point(1, 0),
            new Point(0, 1),
            new Point(-1, 0),
            new Point(0, -1)
        };

        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                HelpFile();
                return;
            }
            try
            {
                var config = new ColorGeneratorConfig
                {
                    XLength = int.Parse(args[0]),
                    YLength = int.Parse(args[1])
                };

                Console.WriteLine("Starting image generation with:");
                Console.WriteLine($"\tDimensions:\t\t{config.XLength} X {config.YLength}");
                Console.WriteLine($"\tSteps Per Channel:\t{config.NumOfSteps}");
                Console.WriteLine($"\tStep Size:\t\t{config.ColorStep}");
                Console.WriteLine($"\tSteps to Skip:\t\t{config.StepsToSkip}\n");

                var runner = new TaskRunner();
                var colors = runner.Run(() => GenerateColorList(config), "color selection");
                var pixels = runner.Run(() => BuildPixelArray(colors, config), "pixel array generation");
                runner.Run(() => OutputBitmap(pixels, config), "bitmap creation");
            }
            catch (Exception ex)
            {
               HelpFile("There was an issue in execution");
            }

            Console.ReadLine();
        }

        private static void HelpFile(string errorMessage = "")
        {
            const string Header = "Generates an image with every pixel having a unique color";
            Console.WriteLine(errorMessage == string.Empty ? Header : $"An error has occured: {errorMessage}\n Ensure the Arguments you have provided are valid");
            Console.WriteLine();
            Console.WriteLine($"{AppDomain.CurrentDomain.FriendlyName} X Y");
            Console.WriteLine();
            Console.WriteLine("X\t\tThe Length of the X dimension eg: 256");
            Console.WriteLine("Y\t\tThe Length of the Y dimension eg: 128");
        }

        public static List<Color> GenerateColorList(ColorGeneratorConfig config)
        {

            //Every iteration of our color generation loop will add the iterationfactor to this accumlator which is used to know when to skip
            decimal iterationAccumulator = 0;

            var colors = new List<Color>();
            for (var r = 0; r < config.NumOfSteps; r++)
                for (var g = 0; g < config.NumOfSteps; g++)
                    for (var b = 0; b < config.NumOfSteps; b++)
                    {
                        iterationAccumulator += config.IterationFactor;

                        //If our accumulator has reached 1, then subtract one and skip this iteration
                        if (iterationAccumulator > 1)
                        {
                            iterationAccumulator -= 1;
                            continue;
                        }

                        colors.Add(Color.FromArgb(r*config.ColorStep, g*config.ColorStep,b*config.ColorStep));
                    }
            return colors;
        }

        public static Color?[,] BuildPixelArray(List<Color> colors, ColorGeneratorConfig config)
        {
            //Get a random color to start with.
            var random = new Random(Guid.NewGuid().GetHashCode());
            var nextColor = colors[random.Next(colors.Count)];

            var pixels = new Color?[config.XLength, config.YLength];
            var currPixel = new Point(0, 0);

            var i = 0;

            //Since we've only generated exactly enough colors to fill our image we can remove them from the list as we add them to our image and stop when none are left.
            while (colors.Count > 0)
            {
                i++;

                //Set the current pixel and remove the color from the list.
                pixels[currPixel.X, currPixel.Y] = nextColor;
                colors.RemoveAt(colors.IndexOf(nextColor));

                //Our image generation works in an inward spiral generation GetNext point will retrieve the next pixel given the current top direction.
                var nextPixel = GetNextPoint(currPixel, directions.First());

                //If this next pixel were to be out of bounds (for first circle of spiral) or hit a previously generated pixel (for all other circles)
                //Then we need to cycle the direction and get a new next pixel
                if (nextPixel.X >= config.XLength || nextPixel.Y >= config.YLength || nextPixel.X < 0 || nextPixel.Y < 0 ||
                    pixels[nextPixel.X, nextPixel.Y] != null)
                {
                    var d = directions.First();
                    directions.RemoveAt(0);
                    directions.Add(d);
                    nextPixel = GetNextPoint(currPixel, directions.First());
                }

                //This code sets the pixel to pick a color for and also gets the next color
                //We do this at the end of the loop so that we can also support haveing the first pixel set outside of the loop
                currPixel = nextPixel;

                if (colors.Count == 0) continue;

                var neighbours = GetNeighbours(currPixel, pixels, config);
                nextColor = colors.AsParallel().Aggregate((item1, item2) => GetAvgColorDiff(item1, neighbours) <
                                                                            GetAvgColorDiff(item2, neighbours)
                    ? item1
                    : item2);
            }

            return pixels;
        }

        public static void OutputBitmap(Color?[,] pixels, ColorGeneratorConfig config)
        {
            //Now that we have generated our image in the color array we need to copy it into a bitmap and save it to file.
            var image = new Bitmap(config.XLength, config.YLength);

            for (var x = 0; x < config.XLength; x++)
                for (var y = 0; y < config.YLength; y++)
                    image.SetPixel(x, y, pixels[x, y].Value);

            using (var file = new FileStream($@".\{config.XLength}X{config.YLength}.png", FileMode.Create))
            {
                image.Save(file, ImageFormat.Png);
            }
        }

        static Point GetNextPoint(Point current, Point direction)
        {
            return new Point(current.X + direction.X, current.Y + direction.Y);
        }

        static List<Color> GetNeighbours(Point current, Color?[,] grid, ColorGeneratorConfig config)
        {
            var list = new List<Color>();
            foreach (var direction in directions)
            {
                var xCoord = current.X + direction.X;
                var yCoord = current.Y + direction.Y;
                if (xCoord < 0 || xCoord >= config.XLength|| yCoord < 0 || yCoord >= config.YLength)
                {
                    continue;
                }
                var cell = grid[xCoord, yCoord];
                if (cell.HasValue) list.Add(cell.Value);
            }
            return list;
        }

        static double GetAvgColorDiff(Color source, IList<Color> colors)
        {
            return colors.Average(color => GetColorDiff(source, color));
        }

        static int GetColorDiff(Color color1, Color color2)
        {
            var redDiff = Math.Abs(color1.R - color2.R);
            var greenDiff = Math.Abs(color1.G - color2.G);
            var blueDiff = Math.Abs(color1.B - color2.B);
            return redDiff + greenDiff + blueDiff;
        }
    }

    public class ColorGeneratorConfig
    {
        public int XLength { get; set; }
        public int YLength { get; set; }

        //Get the number of permutations for each color value base on the required number of pixels.
        public int NumOfSteps
            => (int)Math.Ceiling(Math.Pow((ulong)XLength * (ulong)YLength, 1.0 / ColorDimensions));

        //Calculate the increment for each step
        public int ColorStep
            => 255 / (NumOfSteps - 1);

        //Because NumOfSteps will either give the exact number of colors or more (never less) we will sometimes to to skip some
        //this calculation tells how many we need to skip
        public decimal StepsToSkip
            => Convert.ToDecimal(Math.Pow(NumOfSteps, ColorDimensions) - XLength * YLength);

        //This factor will be used to as evenly as possible spread out the colors to be skipped so there are no large gaps in the spectrum
        public decimal IterationFactor => StepsToSkip / Convert.ToDecimal(Math.Pow(NumOfSteps, ColorDimensions));

        private double ColorDimensions => 3.0;
    }

    public class TaskRunner
    {
        private Stopwatch _sw;
        public TaskRunner()
        {
            _sw = new Stopwatch();
        }

        public void Run(Action task, string taskName)
        {
            Console.WriteLine($"Starting {taskName}...");
            _sw.Start();
            task();
            _sw.Stop();
            Console.WriteLine($"Finished {taskName}. Elapsed(ms): {_sw.ElapsedMilliseconds}");
            Console.WriteLine();
            _sw.Reset();
        }

        public T Run<T>(Func<T> task, string taskName)
        {
            Console.WriteLine($"Starting {taskName}...");
            _sw.Start();
            var result = task();
            _sw.Stop();
            Console.WriteLine($"Finished {taskName}. Elapsed(ms): {_sw.ElapsedMilliseconds}");
            Console.WriteLine();
            _sw.Reset();
            return result;
        }
    }
}
</code>```

Title: Images with all colors

Body:
C#

So I started working on this just as a fun exercise and ended up with an output that at least to me looks pretty neat. The key difference in my solution to (at least) most others is that I'm generating exactly the number of colors needed to start with and evenly spacing the generation out from pure white to pure black.
I'm also setting colors working in an inward spiral and choosing the next color based on the average of the color diff between all neighbors that have been set.

Here is a small sample output that I've produced so far, I'm working on a 4k render but I expect it to take upwards of a day to finish.

Here is a sample of the spec output at 256x128:

Some larger images with still reasonable render times:

Second run at 360 x 240 produced a much smoother image

After improving performance I was able to run a HD render which took 2 days, I haven't given up on a 4k yet but it could take weeks.

HD Render

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;

namespace SandBox
{
    class Program
    {
        private static readonly List<Point> directions = new List<Point>
        {
            new Point(1, 0),
            new Point(0, 1),
            new Point(-1, 0),
            new Point(0, -1)
        };

        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                HelpFile();
                return;
            }
            try
            {
                var config = new ColorGeneratorConfig
                {
                    XLength = int.Parse(args[0]),
                    YLength = int.Parse(args[1])
                };

                Console.WriteLine("Starting image generation with:");
                Console.WriteLine($"\tDimensions:\t\t{config.XLength} X {config.YLength}");
                Console.WriteLine($"\tSteps Per Channel:\t{config.NumOfSteps}");
                Console.WriteLine($"\tStep Size:\t\t{config.ColorStep}");
                Console.WriteLine($"\tSteps to Skip:\t\t{config.StepsToSkip}\n");

                var runner = new TaskRunner();
                var colors = runner.Run(() => GenerateColorList(config), "color selection");
                var pixels = runner.Run(() => BuildPixelArray(colors, config), "pixel array generation");
                runner.Run(() => OutputBitmap(pixels, config), "bitmap creation");
            }
            catch (Exception ex)
            {
               HelpFile("There was an issue in execution");
            }

            Console.ReadLine();
        }

        private static void HelpFile(string errorMessage = "")
        {
            const string Header = "Generates an image with every pixel having a unique color";
            Console.WriteLine(errorMessage == string.Empty ? Header : $"An error has occured: {errorMessage}\n Ensure the Arguments you have provided are valid");
            Console.WriteLine();
            Console.WriteLine($"{AppDomain.CurrentDomain.FriendlyName} X Y");
            Console.WriteLine();
            Console.WriteLine("X\t\tThe Length of the X dimension eg: 256");
            Console.WriteLine("Y\t\tThe Length of the Y dimension eg: 128");
        }

        public static List<Color> GenerateColorList(ColorGeneratorConfig config)
        {

            //Every iteration of our color generation loop will add the iterationfactor to this accumlator which is used to know when to skip
            decimal iterationAccumulator = 0;

            var colors = new List<Color>();
            for (var r = 0; r < config.NumOfSteps; r++)
                for (var g = 0; g < config.NumOfSteps; g++)
                    for (var b = 0; b < config.NumOfSteps; b++)
                    {
                        iterationAccumulator += config.IterationFactor;

                        //If our accumulator has reached 1, then subtract one and skip this iteration
                        if (iterationAccumulator > 1)
                        {
                            iterationAccumulator -= 1;
                            continue;
                        }

                        colors.Add(Color.FromArgb(r*config.ColorStep, g*config.ColorStep,b*config.ColorStep));
                    }
            return colors;
        }

        public static Color?[,] BuildPixelArray(List<Color> colors, ColorGeneratorConfig config)
        {
            //Get a random color to start with.
            var random = new Random(Guid.NewGuid().GetHashCode());
            var nextColor = colors[random.Next(colors.Count)];

            var pixels = new Color?[config.XLength, config.YLength];
            var currPixel = new Point(0, 0);

            var i = 0;

            //Since we've only generated exactly enough colors to fill our image we can remove them from the list as we add them to our image and stop when none are left.
            while (colors.Count > 0)
            {
                i++;

                //Set the current pixel and remove the color from the list.
                pixels[currPixel.X, currPixel.Y] = nextColor;
                colors.RemoveAt(colors.IndexOf(nextColor));

                //Our image generation works in an inward spiral generation GetNext point will retrieve the next pixel given the current top direction.
                var nextPixel = GetNextPoint(currPixel, directions.First());

                //If this next pixel were to be out of bounds (for first circle of spiral) or hit a previously generated pixel (for all other circles)
                //Then we need to cycle the direction and get a new next pixel
                if (nextPixel.X >= config.XLength || nextPixel.Y >= config.YLength || nextPixel.X < 0 || nextPixel.Y < 0 ||
                    pixels[nextPixel.X, nextPixel.Y] != null)
                {
                    var d = directions.First();
                    directions.RemoveAt(0);
                    directions.Add(d);
                    nextPixel = GetNextPoint(currPixel, directions.First());
                }

                //This code sets the pixel to pick a color for and also gets the next color
                //We do this at the end of the loop so that we can also support haveing the first pixel set outside of the loop
                currPixel = nextPixel;

                if (colors.Count == 0) continue;

                var neighbours = GetNeighbours(currPixel, pixels, config);
                nextColor = colors.AsParallel().Aggregate((item1, item2) => GetAvgColorDiff(item1, neighbours) <
                                                                            GetAvgColorDiff(item2, neighbours)
                    ? item1
                    : item2);
            }

            return pixels;
        }

        public static void OutputBitmap(Color?[,] pixels, ColorGeneratorConfig config)
        {
            //Now that we have generated our image in the color array we need to copy it into a bitmap and save it to file.
            var image = new Bitmap(config.XLength, config.YLength);

            for (var x = 0; x < config.XLength; x++)
                for (var y = 0; y < config.YLength; y++)
                    image.SetPixel(x, y, pixels[x, y].Value);

            using (var file = new FileStream($@".\{config.XLength}X{config.YLength}.png", FileMode.Create))
            {
                image.Save(file, ImageFormat.Png);
            }
        }

        static Point GetNextPoint(Point current, Point direction)
        {
            return new Point(current.X + direction.X, current.Y + direction.Y);
        }

        static List<Color> GetNeighbours(Point current, Color?[,] grid, ColorGeneratorConfig config)
        {
            var list = new List<Color>();
            foreach (var direction in directions)
            {
                var xCoord = current.X + direction.X;
                var yCoord = current.Y + direction.Y;
                if (xCoord < 0 || xCoord >= config.XLength|| yCoord < 0 || yCoord >= config.YLength)
                {
                    continue;
                }
                var cell = grid[xCoord, yCoord];
                if (cell.HasValue) list.Add(cell.Value);
            }
            return list;
        }

        static double GetAvgColorDiff(Color source, IList<Color> colors)
        {
            return colors.Average(color => GetColorDiff(source, color));
        }

        static int GetColorDiff(Color color1, Color color2)
        {
            var redDiff = Math.Abs(color1.R - color2.R);
            var greenDiff = Math.Abs(color1.G - color2.G);
            var blueDiff = Math.Abs(color1.B - color2.B);
            return redDiff + greenDiff + blueDiff;
        }
    }

    public class ColorGeneratorConfig
    {
        public int XLength { get; set; }
        public int YLength { get; set; }

        //Get the number of permutations for each color value base on the required number of pixels.
        public int NumOfSteps
            => (int)Math.Ceiling(Math.Pow((ulong)XLength * (ulong)YLength, 1.0 / ColorDimensions));

        //Calculate the increment for each step
        public int ColorStep
            => 255 / (NumOfSteps - 1);

        //Because NumOfSteps will either give the exact number of colors or more (never less) we will sometimes to to skip some
        //this calculation tells how many we need to skip
        public decimal StepsToSkip
            => Convert.ToDecimal(Math.Pow(NumOfSteps, ColorDimensions) - XLength * YLength);

        //This factor will be used to as evenly as possible spread out the colors to be skipped so there are no large gaps in the spectrum
        public decimal IterationFactor => StepsToSkip / Convert.ToDecimal(Math.Pow(NumOfSteps, ColorDimensions));

        private double ColorDimensions => 3.0;
    }

    public class TaskRunner
    {
        private Stopwatch _sw;
        public TaskRunner()
        {
            _sw = new Stopwatch();
        }

        public void Run(Action task, string taskName)
        {
            Console.WriteLine($"Starting {taskName}...");
            _sw.Start();
            task();
            _sw.Stop();
            Console.WriteLine($"Finished {taskName}. Elapsed(ms): {_sw.ElapsedMilliseconds}");
            Console.WriteLine();
            _sw.Reset();
        }

        public T Run<T>(Func<T> task, string taskName)
        {
            Console.WriteLine($"Starting {taskName}...");
            _sw.Start();
            var result = task();
            _sw.Stop();
            Console.WriteLine($"Finished {taskName}. Elapsed(ms): {_sw.ElapsedMilliseconds}");
            Console.WriteLine();
            _sw.Reset();
            return result;
        }
    }
}


问:
Print this diamond
This question has been spreading like a virus in my office. There are quite a variety of approaches:

Print the following:

```<code>        1
       121
      12321
     1234321
    123454321
   12345654321
  1234567654321
 123456787654321
12345678987654321
 123456787654321
  1234567654321
   12345654321
    123454321
     1234321
      12321
       121
        1
</code>```

Answers are scored in characters with fewer characters being better.

答:
Javascript, 114

My first entry on Codegolf!

for(l=n=1;l<18;n-=2*(++l>9)-1,console.log(s+z)){for(x=n,s="";x<9;x++)z=s+=" ";for(x=v=1;x<2*n;v-=2*(++x>n)-1)s+=v}```

If this can be shortened any further, please comment :)

Title: Print this diamond

Body:
Javascript, 114

My first entry on Codegolf!

for(l=n=1;l<18;n-=2*(++l>9)-1,console.log(s+z)){for(x=n,s="";x<9;x++)z=s+=" ";for(x=v=1;x<2*n;v-=2*(++x>n)-1)s+=v}

If this can be shortened any further, please comment :)