答:
Javascript ES6, 314 bytes

Contains unprintable bytes. Uses some black JS magic to run.
If console.log() is needed for this answer to be valid, the byte count will be 327.

```<code>[...`Ãm°Ûm¶Ûm¶Ûm¶Û\`��m¶Ûm¶Ûm¶Ûm�ç�±Çm¶Ûm¶Ûm¶Ûh���¶Ûm°Ûm¶Ûm�<â�8à�À�°�l6Ãm��m��\`�Äl����Ç��§��Ça�ØfqÇ��À�����»
°Ú¬� ó�Øé¦8ã�8ã� ã±Ä�&�â�Ç�4Y�vØnAÛ�X$�HG��\`lv �� ���0��
�Ø�öÛm¶Ûb�Ø�¶���`].map(a=>'0'.repeat(8-(z=a.charCodeAt().toString(2)).length)+z).join``.replace(/.{1,3}/g,a=>`_|/\\()
`[parseInt(a,2)]).slice(0,-2)
</code>```

This was a huge pain to get right, and I couldn't manage to get rid of the .slice(0,-2) :(

Will edit in an explanation tomorrow when I'm less tired.

Replaced every single byte with the corresponding hex value in order for the code snippet to be able to run

f=_=>
[...`\xc3\x6d\xb0\xdb\x6d\xb6\xdb\x6d\xb6\xdb\x6d\xb6\xdb\x60\x00\x00\x6d\xb6\xdb\x6d\xb6\xdb\x6d\xb6\xdb\x6d\x86\xe7\x1d\xb1\xc7\x6d\xb6\xdb\x6d\xb6\xdb\x6d\xb6\xdb\x68\x00\x00\x0b\xb6\xdb\x6d\xb0\xdb\x6d\xb6\xdb\x6d\x8e\x3c\xe2\x06\x38\xe0\x00\xc0\x01\xb0\x00\x6c\x36\xc3\x6d\x80\x00\x6d\x80\x03\x60\x01\xc4\x6c\x00\x1b\x00\x01\xc7\x9d\x80\xa7\x15\x86\xc7\x61\x99\xd8\x66\x71\xc7\x1d\x8e\xc0\x0b\x96\x1b\x14\x00\xbb\x0a\xb0\xda\xac\x00\xa0\xf3\x8e\xd8\xe9\xa6\x38\xe3\x8e\x38\xe3\x8e\x20\xe3\xb1\xc4\x00\x26\x98\xe2\x00\xc7\x11\x34\x59\x1c\x76\xd8\x6e\x41\xdb\x10\x58\x24\x1c\x48\x47\x12\x16\x60\x6c\x76\x20\x00\x00\xa0\x91\x00\x0b\x30\x05\x00\x0a\x0e\xd8\x83\xf6\xdb\x6d\xb6\xdb\x62\x0e\xd8\x83\xb6\x80\x00\x80`].map(a=>'0'.repeat(8-(z=a.charCodeAt().toString(2)).length)+z).join``.replace(/.{1,3}/g,a=>`_|/\\()
`[parseInt(a,2)]).slice(0,-2)

a.innerHTML=f()```
<pre class="snippet-code-html lang-html prettyprint-override"><code><pre id=a></code>```

Title: Display "Happy Easter!"

Body:
Javascript ES6, 314 bytes

Contains unprintable bytes. Uses some black JS magic to run.
If console.log() is needed for this answer to be valid, the byte count will be 327.

[...`Ãm°Ûm¶Ûm¶Ûm¶Û\`��m¶Ûm¶Ûm¶Ûm�ç�±Çm¶Ûm¶Ûm¶Ûh���¶Ûm°Ûm¶Ûm�<â�8à�À�°�l6Ãm��m��\`�Äl����Ç��§��Ça�ØfqÇ��À�����»
°Ú¬� ó�Øé¦8ã�8ã� ã±Ä�&�â�Ç�4Y�vØnAÛ�X$�HG��\`lv �� ���0��
�Ø�öÛm¶Ûb�Ø�¶���`].map(a=>'0'.repeat(8-(z=a.charCodeAt().toString(2)).length)+z).join``.replace(/.{1,3}/g,a=>`_|/\\()
`[parseInt(a,2)]).slice(0,-2)

This was a huge pain to get right, and I couldn't manage to get rid of the .slice(0,-2) :(

Will edit in an explanation tomorrow when I'm less tired.

Replaced every single byte with the corresponding hex value in order for the code snippet to be able to run

f=_=>
[...`\xc3\x6d\xb0\xdb\x6d\xb6\xdb\x6d\xb6\xdb\x6d\xb6\xdb\x60\x00\x00\x6d\xb6\xdb\x6d\xb6\xdb\x6d\xb6\xdb\x6d\x86\xe7\x1d\xb1\xc7\x6d\xb6\xdb\x6d\xb6\xdb\x6d\xb6\xdb\x68\x00\x00\x0b\xb6\xdb\x6d\xb0\xdb\x6d\xb6\xdb\x6d\x8e\x3c\xe2\x06\x38\xe0\x00\xc0\x01\xb0\x00\x6c\x36\xc3\x6d\x80\x00\x6d\x80\x03\x60\x01\xc4\x6c\x00\x1b\x00\x01\xc7\x9d\x80\xa7\x15\x86\xc7\x61\x99\xd8\x66\x71\xc7\x1d\x8e\xc0\x0b\x96\x1b\x14\x00\xbb\x0a\xb0\xda\xac\x00\xa0\xf3\x8e\xd8\xe9\xa6\x38\xe3\x8e\x38\xe3\x8e\x20\xe3\xb1\xc4\x00\x26\x98\xe2\x00\xc7\x11\x34\x59\x1c\x76\xd8\x6e\x41\xdb\x10\x58\x24\x1c\x48\x47\x12\x16\x60\x6c\x76\x20\x00\x00\xa0\x91\x00\x0b\x30\x05\x00\x0a\x0e\xd8\x83\xf6\xdb\x6d\xb6\xdb\x62\x0e\xd8\x83\xb6\x80\x00\x80`].map(a=>'0'.repeat(8-(z=a.charCodeAt().toString(2)).length)+z).join``.replace(/.{1,3}/g,a=>`_|/\\()
`[parseInt(a,2)]).slice(0,-2)

a.innerHTML=f()

<pre id=a>


问:
Find a function with cycles of every length
A function is said to have a cycle of length n if there exists an x in its domain such that fn(x) = x and fm(x) ≠ x for 0 < m < n, where the superscript n denotes n-fold application of f. Note that a cycle of length 1 is a fixed point f(x) = x.

Your task is to implement a bijective function from the integers to themselves, which has exactly one cycle of every positive length n. A bijective function is a one-to-one correspondence, i.e. every integer mapped to exactly once. Having exactly one cycle of length n means that there are exactly n distinct numbers x for which fn(x) = x and fm(x) ≠ x for 0 < m < n.

Here is an example of what such a function might look like around x = 0:

```<code>x     ... -7 -6 -5 -4 -3 -2 -1  0  1  2  3  4  5  6  7 ...
f(x)  ...  2  4  6 -3 -1  1 -4  0 -2  5  7 -7 -6  3 -5 ...
</code>```

This excerpt contains cycles of length 1 to 5:

```<code>n   cycle
1    0
2   -2  1
3   -4 -3 -1
4   -5  6  3  7
5   -7  2  5 -6  4
...
</code>```

Note that above I'm using "function" only in the mathematical sense. You may write either a function or a full program in your language of choice, as long as it takes a single (signed) integer as input and returns a single (signed) integer. As usual you may take input via STDIN, command-line argument, function argument etc. and output via STDOUT, function return value or function (out) argument etc.

Of course, many languages don't (easily) support arbitrary-precision integers. It's fine if your implementation only works on the range of your language's native integer type, as long as that covers at least the range [-127, 127] and that it would work for arbitrary integers if the language's integer type was replaced with arbitrary-precision integers.

Standard code-golf rules apply.

答:
Pyth, <s>27</s> 18 bytes

```<code>_h?gQ0^2Q*.5@,Q-xh
</code>```

Explanation (Pyth initializes Q to the input integer):

```<code>_                       negative of (
                          (
  ?gQ0                      if Q >= 0:
      ^2Q                     2**Q
                            else:
         *.5                  half of
            @        Q          element Q (modulo list length) in
             ,                    the two element list [
              Q                     Q,
                 hQ                 ((Q plus 1)
                x  Q                 XOR Q)
               -    Q               minus Q
                                  ]
 h                        ) plus 1
                        )
</code>```

This has cycles

(−1)

(0, −2)

(1, −3, −4)

(2, −5, −7, −6)

(3, −9, −13, −11, −8)

(4, −17, −25, −21, −15, −10)

(5, −33, −49, −41, −29, −19, −12)

(6, −65, −97, −81, −57, −37, −23, −14)

(7, −129, −193, −161, −113, −73, −45, −27, −16)

(8, −257, −385, −321, −225, −145, −89, −53, −31, −18)

(9, −513, −769, −641, −449, −289, −177, −105, −61, −35, −20)

⋮

The cycle of length n is given by

(n − 2,

−2^(n − 2)⋅1 − 1,

−2^(n − 3)⋅3 − 1,

−2^(n − 4)⋅5 − 1,

…,

−2^2⋅(2·n − 7) − 1,

−2^1⋅(2·n − 5) − 1,

−2^0⋅(2·n − 3) − 1).

Each integer k ≥ −1 appears as the first element of the (k + 2)-cycle.  For each integer k < −1, we can uniquely write 1 − k = 2^i ⋅ (2⋅j + 1) for some i, j ≥ 0; then k appears as the (j + 2)th element of the (i + j + 2)−cycle.

ContentLicense: CC BY-SA 3.0

Body:
Pyth, <s>27</s> 18 bytes

_h?gQ0^2Q*.5@,Q-xh

Explanation (Pyth initializes Q to the input integer):

_                       negative of (
                          (
  ?gQ0                      if Q >= 0:
      ^2Q                     2**Q
                            else:
         *.5                  half of
            @        Q          element Q (modulo list length) in
             ,                    the two element list [
              Q                     Q,
                 hQ                 ((Q plus 1)
                x  Q                 XOR Q)
               -    Q               minus Q
                                  ]
 h                        ) plus 1
                        )

This has cycles

(−1)

(0, −2)

(1, −3, −4)

(2, −5, −7, −6)

(3, −9, −13, −11, −8)

(4, −17, −25, −21, −15, −10)

(5, −33, −49, −41, −29, −19, −12)

(6, −65, −97, −81, −57, −37, −23, −14)

(7, −129, −193, −161, −113, −73, −45, −27, −16)

(8, −257, −385, −321, −225, −145, −89, −53, −31, −18)

(9, −513, −769, −641, −449, −289, −177, −105, −61, −35, −20)

⋮

The cycle of length n is given by

(n − 2,

−2^(n − 2)⋅1 − 1,

−2^(n − 3)⋅3 − 1,

−2^(n − 4)⋅5 − 1,

…,

−2^2⋅(2·n − 7) − 1,

−2^1⋅(2·n − 5) − 1,

−2^0⋅(2·n − 3) − 1).

Each integer k ≥ −1 appears as the first element of the (k + 2)-cycle.  For each integer k < −1, we can uniquely write 1 − k = 2^i ⋅ (2⋅j + 1) for some i, j ≥ 0; then k appears as the (j + 2)th element of the (i + j + 2)−cycle.


问:
Find all unambiguous prefixes of a set of strings
For this challenge, you must implement Ruby's Abbrev module in as little code as possible.

Challenge

The input will be whatever your language has as an array (array, list, sequence, etc.) of strings. You may write a function, or you may accept comma-separated words on STDIN.

You must then calculate the set of unambiguous prefixes for those strings. This means you must return a hash (or map, object, etc.) of abbreviations to their original strings.

A "prefix" is a substring of the original string starting at the beginning of the string. For example, "pref" is an prefix of the word "prefix."

An unambiguous prefix is one that can only mean one word. For example, if your input is car,cat, then ca is not an unambiguous prefix because it could mean either "car" or "cat."

The exception to this rule is that a word is always a prefix of itself. For example, if you have input such as car,carpet, car:car must be in your output.

You can then return the hash/map/object/etc. from your function (or do the equivalent in your language), or print it out to STDOUT in key:value pairs in the form of f:foo,fo:foo,.... (The key-value pairs may also be separated by whitespace if it makes your code shorter.)

Test cases

```<code>Input  code,golf,going
Output c:code,co:code,cod:code,code:code,gol:golf,golf:golf,goi:going,goin:going,going:going

Input  pie
Output p:pie,pi:pie,pie:pie

Input  pie,pier,pierre
Output pie:pie,pier:pier,pierr:pierre,pierre:pierre

Input  a,dog
Output a:a,d:dog,do:dog,dog:dog
</code>```

Rules

The input will not contain duplicate elements.

Your output may be in any order; you don't have to sort it.

You may not use a built-in Abbrev module/function/thing like Ruby's.

This is code-golf, so the shortest code in bytes will win!

答:
Q: 44 Bytes

```<code>{x!p@'(?0,&:)'p in\:&1=#:'=,/p:`$(-1_)\'$x}
</code>```

NOTES

Q language has an inner core named internally K4 (used in this answer and another previously answer to this question)

To test code, download interpreter (kx.com, free for non-commertial
use, support for Windows, Linux, Mac)

Interpreter admits two syntaxes:

verbose (more readable names, distinct names for moands and diads, more libraries, ...). Load source file with q extension, or interactive interpreter

compact (functional inner core, one letter operators, same letter for both uses monad/diad, ...). Load source file with k extension, or interactive interpreter in k mode (write \ at prompt). Code must be tested in this mode

The code defines a lambda (anonymous function). To give name to the function we need prefix name: (ex f:{..}), so requires 46 Bytes

TEST

(assumming named function: otherwise substitute f for the code)

```<code>f `code`golf`going

`code`golf`going!(`code`cod`co`c;`golf`gol;`going`goin`goi)
</code>```

returns a dictionary (syntax keys!values). Keys are a list of symbols (`symb`symb..), and values a list of list of symbols. If we execute the sentente at the interactive interpreter, we have a more convenient presentation (each key and associate values at a different line)

```<code>code | `code`cod`co`c
golf | `golf`gol
going| `going`goin`goi
</code>```

EXPLANATION

x is the implicit argument to the lambda

$x convert symbol list to string list

(-1_)\   iterates over each elem of the symbol list

(reads as for each string calculates prefixes (at eat iteration drops last char  of the string (-1_), until empty string)

$       transforms to a symbol list again (list of all prefixes)

p:       and assigns to p

,/       raze all (concatenates and creates a one-level structure)

=        classify -> for each unique prefix, associates the corresponding words

#:'      calculates length (number of words associated to each prefix)

1=       true if length=1 (unambiguous), false otherwise

&        where -> index of true elements

p in\:   determines for all prefix if they are in unambiguous prefix

(..)' applies (..) to each value at right (unambiguous prefix)

?0,&:  -> distinct 0 concatenated where (to cope words as prefix of itself)

p@       transform indexes to symbols

x!..     construct a dictionary with x (words) as keys, and .. as values

Read as:

Construct and returns a dictionary with the words as keys, and values
..

... values of indexes at distinct positions 0 (all word) and where
unambiguous prefix

... unambiguous calculated as prefixes that appear only at one word
(wordlist associates to each symbols has length one)

... lists resulting of classifying all unique symbols with corresponding
words

... prefixes calculated by repeating drop last char of each word

Body:
Q: 44 Bytes

{x!p@'(?0,&:)'p in\:&1=#:'=,/p:`$(-1_)\'$x}

NOTES

Q language has an inner core named internally K4 (used in this answer and another previously answer to this question)

To test code, download interpreter (kx.com, free for non-commertial
use, support for Windows, Linux, Mac)

Interpreter admits two syntaxes:

verbose (more readable names, distinct names for moands and diads, more libraries, ...). Load source file with q extension, or interactive interpreter

compact (functional inner core, one letter operators, same letter for both uses monad/diad, ...). Load source file with k extension, or interactive interpreter in k mode (write \ at prompt). Code must be tested in this mode

The code defines a lambda (anonymous function). To give name to the function we need prefix name: (ex f:{..}), so requires 46 Bytes

TEST

(assumming named function: otherwise substitute f for the code)

f `code`golf`going

`code`golf`going!(`code`cod`co`c;`golf`gol;`going`goin`goi)

returns a dictionary (syntax keys!values). Keys are a list of symbols (`symb`symb..), and values a list of list of symbols. If we execute the sentente at the interactive interpreter, we have a more convenient presentation (each key and associate values at a different line)

code | `code`cod`co`c
golf | `golf`gol
going| `going`goin`goi

EXPLANATION

x is the implicit argument to the lambda

$x convert symbol list to string list

(-1_)\   iterates over each elem of the symbol list

(reads as for each string calculates prefixes (at eat iteration drops last char  of the string (-1_), until empty string)

$       transforms to a symbol list again (list of all prefixes)

p:       and assigns to p

,/       raze all (concatenates and creates a one-level structure)

=        classify -> for each unique prefix, associates the corresponding words

#:'      calculates length (number of words associated to each prefix)

1=       true if length=1 (unambiguous), false otherwise

&        where -> index of true elements

p in\:   determines for all prefix if they are in unambiguous prefix

(..)' applies (..) to each value at right (unambiguous prefix)

?0,&:  -> distinct 0 concatenated where (to cope words as prefix of itself)

p@       transform indexes to symbols

x!..     construct a dictionary with x (words) as keys, and .. as values

Read as:

Construct and returns a dictionary with the words as keys, and values
..

... values of indexes at distinct positions 0 (all word) and where
unambiguous prefix

... unambiguous calculated as prefixes that appear only at one word
(wordlist associates to each symbols has length one)

... lists resulting of classifying all unique symbols with corresponding
words

... prefixes calculated by repeating drop last char of each word


问:
Visualize Church numerals

Background

Visualizing λ-calculus terms

Famous lambda-juggler (and code golfer) John Tromp devised an interesting visualization of terms in the λ-calculus. In his words:

abstractions (lambdas) are represented by horizontal lines, variables by vertical lines emanating down from their binding lambda, and applications by horizontal links connecting the leftmost variables.

For example, the lambda term λf.λx.f (f (f (f x))) corresponds to the visualization:

```<code>-------------------
 |   |   |   |
-------------------
 |   |   |   |   |
 |   |   |   |----
 |   |   |----
 |   |----
 |----
 |
</code>```

Read it from top to bottom:

The first horizontal line represents the first λ.

The four lines descending from it represent the fs in the body.

Similarly, the second horizontal line represents the second λ, and the single new line descending from it represents the x in the body.

The rightmost f line and the x line are connected by a horizontal line representing an application (f x).

The next application is (f (f x)), et cetera.

Church numerals

The Church numerals are a specific sequence of terms in the λ-calculus, taking on the following pattern:

```<code>0 = λf. λx. x
1 = λf. λx. f x
2 = λf. λx. f (f x)
3 = λf. λx. f (f (f x))
...
</code>```

Task

Given an input number n, print some ASCII art that visualizes the nth Church numeral. For instance, the example above is your target output when given n = 4. For n = 0, print:

```<code>---

---
 |
 |
</code>```

Test cases

Your answer must output exactly the same text (modulo trailing newlines) as this stack snippet for all integer inputs n ≥ 0:

function visualize() {
  var vin = document.getElementById('visualize-in');
  var vout = document.getElementById('visualize-out');
  var n = Number(vin.value);
  if (n < 0) n = 0;
  var line = '-'.repeat(4 * n + 3);
  var bars = function(k) { return '   |'.repeat(k).substr(2); };
  var img = [line, bars(n), line, bars(n + 1)];
  for (var i = n; i > 0; --i) img.push(bars(i) + '----');
  vout.innerHTML = img.join('\n') + '\n |';
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><label for="visualize-in">n <input style="width:50px;" type="number" id="visualize-in" name="visualize-in" onchange="visualize()"/></label>
<pre style="background-color: #eff0f1" id="visualize-out">``````

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

答:
JavaScript (ES6), 112 bytes

f=
n=>`${d=`-`.repeat(n*4+3)}
${(b=` |  `.repeat(n)).slice(0,-2)}
${d}
${b} |
${b.replace(/ \|  /g,`$' |----
`)} |`
;```
<pre class="snippet-code-html lang-html prettyprint-override"><code><input id=i type=number min=0 oninput=o.textContent=f(this.value)>
<pre id=o>``````

Title: Visualize Church numerals

Body:
JavaScript (ES6), 112 bytes

f=
n=>`${d=`-`.repeat(n*4+3)}
${(b=` |  `.repeat(n)).slice(0,-2)}
${d}
${b} |
${b.replace(/ \|  /g,`$' |----
`)} |`
;

<input id=i type=number min=0 oninput=o.textContent=f(this.value)>
<pre id=o></pre>


问:
The lost pawn problem

The lost pawn problem

After the chess game ended, a surviving pawn was left behind enemy lines. let's help him find the shortest way back home.

The original problem describes a nXn "chess" board, and a function f: {1,..,n-1}X{1,..,n}X{-1,0,1} => R+ of weights. the goal is to find the best path from some square in the buttom line, to some other square in the top line, where the possible moves are: left-up,up,right-up, and you may not exit the board.

The problem is relatively easy to solve in O(n^2) using dynamic programming, but this is codegolf, and we don't care about useless stuff like running time complexity...

The Problem

input: a 3-dimentional array (or some other collection of your choice, received through stdin, or as a function argument), corresponding to a regular chess board, exactly in size: 7X8X3 (#linePasses X #rowSize X #movesPerPass) containing non-negative integers.
the moves cost from some position (i,j) where i is the row index, and j is the column index, are:

a[i][j][0] for the cost to travel up-left to square (i+1,j-1), or graphically: \.

a[i][j][1] for the cost to travel up to square (i+1,j), or graphically: |.

a[i][j][2] for the cost to travel up-right to square (i+1,j+1), or graphically: /.

you may assume it will not contain a path that sums greater than MAX_INT.

output: an 8X8 ascii output showing the best (shortest, i.e. minimum sum of weights) path (if there is more than 1 optimal result, you may show an arbitrary path of your choice). the path is drawn bottom to top, where in each line, the character corresponding to the pawn's position in the path, is the one it about to make. e.g. if the pawn is about to move up-left from column 3 (to column 2), the you should draw:

```<code>#?######
##\#####
</code>```

where ? should be replaced with the next move. final position needs to be drawn as X.

Examples

input:

```<code>[
  [[1,1,1],[1,1,1],[0,1,1],[1,1,1],[1,1,1],[1,1,1],[1,1,1],[1,1,1]],
  [[1,1,1],[1,0,1],[1,1,1],[1,1,1],[1,1,1],[1,1,1],[1,1,1],[1,1,1]],
  [[1,1,1],[1,1,0],[1,1,1],[1,1,1],[1,1,1],[1,1,1],[1,1,1],[1,1,1]],
  [[1,1,1],[1,1,1],[1,1,0],[1,1,1],[1,1,1],[1,1,1],[1,1,1],[1,1,1]],
  [[1,1,1],[1,1,1],[1,1,1],[1,0,1],[1,1,1],[1,1,1],[1,1,1],[1,1,1]],
  [[1,1,1],[1,1,1],[1,1,1],[1,0,1],[1,1,1],[1,1,1],[1,1,1],[1,1,1]],
  [[1,1,1],[1,1,1],[1,1,1],[0,1,1],[1,1,1],[1,1,1],[1,1,1],[1,1,1]]
]
</code>```

output:

```<code>##X#####
###\####
###|####
###|####
##/#####
#/######
#|######
##\#####
</code>```

input:

```<code>[
  [[41,27,38],[12,83,32],[50,53,35],[46,32,26],[55,89,82],[75,30,87],[2,11,64],[8,55,22]],
  [[56,21,0],[83,25,38],[43,75,63],[56,60,77],[68,55,89],[99,48,67],[94,30,9],[62,62,58]],
  [[23,18,40],[24,47,61],[96,45,72],[71,6,48],[75,63,98],[93,56,51],[23,31,30],[49,34,99]],
  [[20,47,42],[62,79,72],[32,28,44],[68,61,55],[62,39,57],[4,17,49],[97,85,6],[91,18,12]],
  [[51,50,11],[32,39,56],[12,82,23],[33,88,87],[60,55,22],[29,78,14],[70,11,42],[63,94,67]],
  [[75,64,60],[27,79,86],[70,72,56],[55,45,32],[95,67,12],[87,93,98],[81,36,53],[38,22,93]],
  [[31,80,50],[77,71,22],[59,46,86],[64,71,53],[41,19,95],[62,71,22],[92,80,41],[26,74,29]]
]
</code>```

output:

```<code>######X#
#####/##
####/###
#####\##
#####|##
######\#
######|#
#######\
</code>```

this is code-golf, so shortest code wins.

play fair. no loopholes...

EDIT:

Iv'e written an un-golfed straight forward solution in scala you can look at. There's also a site you can play with scala code on-line: scalafiddle (just copy&paste the gist to scalafiddle, and hit the play button)

ContentLicense: CC BY-SA 4.0

Title: The lost pawn problem

Body:
Q: 199 Bytes

f:{m::x;n::{@/[+/-1 0 1_\:/:(x;m[y;;|!3]);0 2;(0W,),{x,0W}]};i:*<*|r:{&/n[x;y]}\[8#0;!7];  s:{-1+{*<x}'+n[y;z]}\[();(,8#0),-1_r;!7];j:i,{x+y x}\[i;|s];-1(@[8#"#";;:;]'[j;"X","/|\\"1+s'[|!7;-1_j]]);}

NOTES

Q interpreter (kx.com) free for non-commertial use (versions for
Windows, Linux, Mac)

This solution uses inner core of Q (internally named k4), so we need
a scripting file with k extension, or interactive interpreter in k
mode (\ command at first prompt). By contrast, 'verbose' (legible)
version of the language requires script with q extension, and is the
default mode at interactive interpreter.

TEST

f ((1 1 1; 1 1 1; 0 1 1; 1 1 1; 1 1 1; 1 1 1; 1 1 1; 1 1 1)
   (1 1 1; 1 0 1; 1 1 1; 1 1 1; 1 1 1; 1 1 1; 1 1 1; 1 1 1)
   (1 1 1; 1 1 0; 1 1 1; 1 1 1; 1 1 1; 1 1 1; 1 1 1; 1 1 1)
   (1 1 1; 1 1 1; 1 1 0; 1 1 1; 1 1 1; 1 1 1; 1 1 1; 1 1 1)
   (1 1 1; 1 1 1; 1 1 1; 1 0 1; 1 1 1; 1 1 1; 1 1 1; 1 1 1)
   (1 1 1; 1 1 1; 1 1 1; 1 0 1; 1 1 1; 1 1 1; 1 1 1; 1 1 1)
   (1 1 1; 1 1 1; 1 1 1; 0 1 1; 1 1 1; 1 1 1; 1 1 1; 1 1 1))

##X#####
###\####
###|####
###|####
##/#####
#/######
#|######
##\#####

f ((41 27 38; 12 83 32; 50 53 35; 46 32 26; 55 89 82; 75 30 87;  2 11 64;  8 55 22)
   (56 21  0; 83 25 38; 43 75 63; 56 60 77; 68 55 89; 99 48 67; 94 30  9; 62 62 58)
   (23 18 40; 24 47 61; 96 45 72; 71  6 48; 75 63 98; 93 56 51; 23 31 30; 49 34 99)
   (20 47 42; 62 79 72; 32 28 44; 68 61 55; 62 39 57;  4 17 49; 97 85  6; 91 18 12)
   (51 50 11; 32 39 56; 12 82 23; 33 88 87; 60 55 22; 29 78 14; 70 11 42; 63 94 67)
   (75 64 60; 27 79 86; 70 72 56; 55 45 32; 95 67 12; 87 93 98; 81 36 53; 38 22 93)
   (31 80 50; 77 71 22; 59 46 86; 64 71 53; 41 19 95; 62 71 22; 92 80 41; 26 74 29))

######X#
#####/##
####/###
#####\##
######\#
######|#
######|#
#######\

EXPLANATION

For ilustration purpose, we assume second test (matrix ((41 27 38; 12 83 32; ....)

We transform original matrix (m at code level): instead of orginimal matriz with a triplet for each coordinate, we define matrix for left, up, and right displacements. Left matrix contains 7x7 values (we drop first column), Up matrix 7x8, and right matrix 7x7 (we frop last column).

left                           up                         right
12 50 46 55 75 2  8       27 83 53 32 89 30 11 55     38 32 35 26 82 87 64
83 43 56 68 99 94 62      21 25 75 60 55 48 30 62     0  38 63 77 89 67 9
24 96 71 75 93 23 49      18 47 45 6  63 56 31 34     40 61 72 48 98 51 30
62 32 68 62 4  97 91      47 79 28 61 39 17 85 18     42 72 44 55 57 49 6
32 12 33 60 29 70 63      50 39 82 88 55 78 11 94     11 56 23 87 22 14 42
27 70 55 95 87 81 38      64 79 72 45 67 93 36 22     60 86 56 32 12 98 53
77 59 64 41 62 92 26      80 71 46 71 19 71 80 74     50 22 86 53 95 22 41

To calculate final position we need to evaluate minimum-cost path. We assume initial cost 0 0 0 0 0 0 0 0 (cost to arrive at each column of first row), and iterates with each next row. At each column i, we calculate three values:

cost of previous i+1 value plus left[i+1]. We drop first component of cost (shifts and alineates columns to add) and sum component to component

cost of previous i   value plus up[i]. We sum component to component

cost of previous i-1 value plus right[i-1]. We drop last component of cost (shifts and alineates columns to add) and sum component to component

To calculate minimum we complete left cost prepending infinite and right cost appending infinite: with 3 vectors of eight components, calculate minimum component to component. Resulting value is the base cost for new iteration

For first iteration we obtain values (0W is infinite in Q)

0W 12 50 46 55 75 2  8
27 83 53 32 89 30 11 55
38 32 35 26 82 87 64 0W

and calculates minimum of each column

27 12 35 26 55 30 2 8

After all iterations, we have the minimum cost to arrive to each square (assuming row 0 at top, 7 at bottom). We are only interested in last column, but i draw all intermediate results for ilustrative purposes

0   0   0   0   0   0   0   0
27  12  35  26  55  30  2   8
27  37  78  82  110 78  11  70
45  61  123 88  173 129 34  104
87  123 151 143 212 133 40  122
98  155 163 176 234 147 51  185
158 182 219 208 246 234 87  207
208 204 265 261 265 256 128 233

Now we found minimum value at last row (128, at column 6). That's the end of the path (X character in ouput).

We repeat cost calculation again, but now we annotate the direction from we obtain each minimum (wich of the 3 values used to calculate minimum is the selected value).

\|/|\///
\\\\\/|/
\\\|//|/
\\|\//|/
\\|//|\/
\\//|\|/
\|/|/|\/

We reverse rows, put 'X' at pos 6, and preserves only path that ends at column 6 (the others are substituted by #)

######X#
#####/##
####/###
#####\##
######\#
######|#
######|#
#######\


问:
Illiteral Prime numbers
Your challenge is to write a program (full program, not a function), that will take an integer and output all prime numbers up to (including) the given integer. Output is any readable list containing all integer primes (array, string, 1 prime per line, whatever you want) and must run to stdout or equivalent.

Simple? Here's the twist:

You may not use literals in your program. These include:

Literal numbers (0 through 9)

Literal strings (in quotes)

You may not use built in prime checks

EDIT: A prime check is a built in function that

Returns if a number is a prime number

Returns a prime number

Returns a list of prime numbers

You may code your own functions that do the above

Prime factorisation functions are allowed

As this is code-golf, shortest answer in bytes wins

答:
05AB1E, 2 bytes

```<code>!f
</code>```

Allowing prime factorization makes this a bit too easy...

Try it online!

How it works

```<code>!   Compute the factorial of the input.
 f  Find its prime factors.
</code>```

Title: Illiteral Prime numbers

Body:
05AB1E, 2 bytes

!f

Allowing prime factorization makes this a bit too easy...

Try it online!

How it works

!   Compute the factorial of the input.
 f  Find its prime factors.


问:
Alternating Sign Sequence

Introduction

The sign of a number is either a +, or a - for every non-zero integer. Zero itself is signless (+0 is the same as -0). In the following sequence, we are going to alternate between the positive sign, the zero and the negative sign. The sequence starts with 1, so we write 1 with a positive sign, with zero (this one is weird, but we just multiply the number by 0) and the negative sign:

```<code>1, 0, -1
</code>```

The next number is 2, and we do the same thing again:

```<code>2, 0, -2
</code>```

The sequence eventually is:

```<code>1, 0, -1, 2, 0, -2, 3, 0, -3, 4, 0, -4, 5, 0, -5, 6, 0, -6, 7, 0, -7, ...
</code>```

Or a more readable form:

```<code>a(0) = 1
a(1) = 0
a(2) = -1
a(3) = 2
a(4) = 0
a(5) = -2
a(6) = 3
a(7) = 0
a(8) = -3
a(9) = 4
...
</code>```

The Task

Given a non-negative integer n, output the nth term of the above sequence. You can choose if you use the zero-indexed or one-indexed version.

Test cases:

Zero-indexed:

```<code>a(0) = 1
a(11) = -4
a(76) = 0
a(134) = -45
a(296) = -99
</code>```

Or if you prefer one-indexed:

```<code>a(1) = 1
a(12) = -4
a(77) = 0
a(135) = -45
a(297) = -99
</code>```

This is code-golf, so the submission with the smallest number of bytes wins!

答:
Haskell, 27 bytes

```<code>f x=div(x+3)3*(1-mod(x+3)3)
</code>```

Slightly more interesting 28 byte solution:

```<code>(((\i->[i,0,-i])=<<[1..])!!)
</code>```

(Both are 0-indexed)

Title: Alternating Sign Sequence

Body:
Haskell, 27 bytes

f x=div(x+3)3*(1-mod(x+3)3)

Slightly more interesting 28 byte solution:

(((\i->[i,0,-i])=<<[1..])!!)

(Both are 0-indexed)


答:
Perl 5, 37 bytes

36, plus 1 for -nE instead of -e

```<code>{/^.?$|^(..+?)\1+$/||say;s/.//;redo}
</code>```

Input and output are in unary.

Title: Illiteral Prime numbers

Body:
Your challenge is to write a program (full program, not a function), that will take an integer and output all prime numbers up to (including) the given integer. Output is any readable list containing all integer primes (array, string, 1 prime per line, whatever you want) and must run to stdout or equivalent.

Simple? Here's the twist:

You may not use literals in your program. These include:

Literal numbers (0 through 9)

Literal strings (in quotes)

You may not use built in prime checks

EDIT: A prime check is a built in function that

Returns if a number is a prime number

Returns a prime number

Returns a list of prime numbers

You may code your own functions that do the above

Prime factorisation functions are allowed

As this is code-golf, shortest answer in bytes wins

Body:
Perl 5, 37 bytes

36, plus 1 for -nE instead of -e

{/^.?$|^(..+?)\1+$/||say;s/.//;redo}

Input and output are in unary.


问:
Fix my Basic Orthography

Fix my Basic Orthography

While I am excellent at following the English capitalisation rules when writing, when I am typing I have a habit a capitalising almost everything (as you will see from the titles of my challenges). I need a program to fix that, but because I use so many capitals, and capitals are big letters, your program must be as short as possible.

Requirements

Your program should take each word, and if it is the first alphanumeric set of characters after a full stop or the beginning of the input, capitalize the first letter. All the rest of the letters until the next full stop will be lowercase.  At the full stop, capitalize the first letter and continue.

Punctuation must be preserved.

In a sentence without a full stop at the end, that should be added.

Spaces, where missing, should be inserted. A space is 'missing' if there is nothing between a full stop and the character following it.

(Note for americanish speakers: full stop = period = .)

Test Cases

```<code>tHIS SenteNce HAS veRy bAd GrammAr. ==> This sentence has very bad grammar.

-----

PuncTuation must-be PReserved. ==> Punctuation must-be preserved.

-----

full StOps ShoulD Be inserted ==> Full stops should be inserted.

-----

MultiPLe sEntEnceS Are possible. thEY Are, yoU KNOW. ==> Multiple sentences are possible. They are, you know.

-----

spaces. are.inserted. ==> Spaces. Are. Inserted.
</code>```

Rules

Your program should take input as an argument or from STDIN (or the closest alternative in your language).

Standard loopholes are forbidden.

Scoring

When code-golf is the tag, it's the least bytes to win!

Submissions

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

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

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

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

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

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

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

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

Leaderboard

/* Configuration */

var QUESTION_ID = 79842; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 53406; // This should be the user ID of the challenge author.

/* App */

var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;

function answersUrl(index) {
  return "https://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}

function commentUrl(index, answers) {
  return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}

function getAnswers() {
  jQuery.ajax({
    url: answersUrl(answer_page++),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      answers.push.apply(answers, data.items);
      answers_hash = [];
      answer_ids = [];
      data.items.forEach(function(a) {
        a.comments = [];
        var id = +a.share_link.match(/\d+/);
        answer_ids.push(id);
        answers_hash[id] = a;
      });
      if (!data.has_more) more_answers = false;
      comment_page = 1;
      getComments();
    }
  });
}

function getComments() {
  jQuery.ajax({
    url: commentUrl(comment_page++, answer_ids),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      data.items.forEach(function(c) {
        if (c.owner.user_id === OVERRIDE_USER)
          answers_hash[c.post_id].comments.push©;
      });
      if (data.has_more) getComments();
      else if (more_answers) getAnswers();
      else process();
    }
  });
}

getAnswers();

var SCORE_REG = /<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;

var OVERRIDE_REG = /^Override\s*header:\s*/i;

function getAuthorName(a) {
  return a.owner.display_name;
}

function process() {
  var valid = [];

  answers.forEach(function(a) {
    var body = a.body;
    a.comments.forEach(function(c) {
      if(OVERRIDE_REG.test(c.body))
        body = '
' + c.body.replace(OVERRIDE_REG, '') + '
';
    });

    var match = body.match(SCORE_REG);
    if (match)
      valid.push({
        user: getAuthorName(a),
        size: +match[2],
        language: match[1],
        link: a.share_link,
      });

  });

  valid.sort(function (a, b) {
    var aB = a.size,
        bB = b.size;
    return aB - bB
  });

  var languages = {};
  var place = 1;
  var lastSize = null;
  var lastPlace = 1;
  valid.forEach(function (a) {
    if (a.size != lastSize)
      lastPlace = place;
    lastSize = a.size;
    ++place;

    var answer = jQuery("#answer-template").html();
    answer = answer.replace("{{PLACE}}", lastPlace + ".")
                   .replace("{{NAME}}", a.user)
                   .replace("{{LANGUAGE}}", a.language)
                   .replace("{{SIZE}}", a.size)
                   .replace("{{LINK}}", a.link);
    answer = jQuery(answer);
    jQuery("#answers").append(answer);

    var lang = a.language;
    if (/ b.lang) return 1;
    if (a.lang < b.lang) return -1;
    return 0;
  });

  for (var i = 0; i < langs.length; ++i)
  {
    var language = jQuery("#language-template").html();
    var lang = langs[i];
    language = language.replace("{{LANGUAGE}}", lang.lang)
                       .replace("{{NAME}}", lang.user)
                       .replace("{{SIZE}}", lang.size)
                       .replace("{{LINK}}", lang.link);
    language = jQuery(language);
    jQuery("#languages").append(language);
  }

}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body { text-align: left !important}

#answer-list {
  padding: 10px;
  width: 290px;
  float: left;
}

#language-list {
  padding: 10px;
  width: 290px;
  float: left;
}

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
V, 25 bytes (non-competing)

```<code>guGgUló® *¨á©/® Õ±
ó®$
A.
</code>```

Try it online!

This isn't super creative, since it's just a direct port of my vim answer. However, it's a lot shorter, so I'm happy with it.

Due to an oversight, this is one or two bytes longer than it needs to be. That should be fixed soon.

Title: Fix my Basic Orthography

Body:
V, 25 bytes (non-competing)

guGgUló® *¨á©/® Õ±
ó®$
A.

Try it online!

This isn't super creative, since it's just a direct port of my vim answer. However, it's a lot shorter, so I'm happy with it.

Due to an oversight, this is one or two bytes longer than it needs to be. That should be fixed soon.


问:
Falsify brief truths
Find the longest run of true in a list of booleans. Return the same list, with all other trues falsified.

Input, output

A list; any usual format (e.g., a delimited list as a string).

Details

True and false can be anything your language typically uses for those values, or the integers 1 and 0. If you use single characters, the list can be a concatenation (e.g., 10001).

If there's a tie for longest run, keep all tying runs true, and falsify all shorter runs.

Examples

```<code>input ↦ output
1,0,1,0,1 ↦ 1,0,1,0,1
1,1,0,1,1,0,1 ↦ 1,1,0,1,1,0,0
1,1,0,1,1,1,0,1,1 ↦ 0,0,0,1,1,1,0,0,0
1,1,1 ↦ 1,1,1
0,0,1 ↦ 0,0,1
0,0 ↦ 0,0
1,1,1,0,0,0,1,1,1,1,0,1,0,0,1,1,0,1,1,1,1,0,0,1,0 ↦ 0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0
</code>```

(directly from https://stackoverflow.com/q/37447114)

答:
C, 135 129 bytes

Try Online

m,c,i,d,j;f(int*l,int s){while(i<s)c=l[i++]?c+1:0,m=c>m?c:m;while(j<s)if(l[j++])d=d+1;else if(d<m)while(d)l[j-1-d--]=0;else d=0;}
```

<p><strong>Ungolfed</strong></p>

<pre class="lang-c prettyprint-override"><code>m,c,i;
f(int*l,int s)
{
    // obtain max
    while(i<s)
        c = l[i++] ? c+1 : 0,
        m = c>m ? c : m;

    c=0,i=0;

    // remove smaller segments
    while(i<s)
        if(l[i++]) c=c+1;
        else if(c<m) while(c) l[(i-1)-c--]=0;
        else c=0;
}
</code>```

Title: Falsify brief truths

Body:
C, 135 129 bytes

Try Online

m,c,i,d,j;f(int*l,int s){while(i<s)c=l[i++]?c+1:0,m=c>m?c:m;while(j<s)if(l[j++])d=d+1;else if(d<m)while(d)l[j-1-d--]=0;else d=0;}

Ungolfed

m,c,i;
f(int*l,int s)
{
    // obtain max
    while(i<s)
        c = l[i++] ? c+1 : 0,
        m = c>m ? c : m;

    c=0,i=0;

    // remove smaller segments
    while(i<s)
        if(l[i++]) c=c+1;
        else if(c<m) while(c) l[(i-1)-c--]=0;
        else c=0;
}


答:
05AB1E, 7 bytes

Code:

```<code>(3‰`<*(
</code>```

Explained:

```<code>(           # negate input: 12 -> -12
 3‰         # divmod by 3: [-4, 0]
   `        # flatten array: 0, -4
    <       # decrease the mod-result by 1: -1, -4
     *      # multiply: 4
      (     # negate -4
</code>```

Title: Alternating Sign Sequence

Body:
Introduction

The sign of a number is either a +, or a - for every non-zero integer. Zero itself is signless (+0 is the same as -0). In the following sequence, we are going to alternate between the positive sign, the zero and the negative sign. The sequence starts with 1, so we write 1 with a positive sign, with zero (this one is weird, but we just multiply the number by 0) and the negative sign:

```<code>1, 0, -1
</code>```

The next number is 2, and we do the same thing again:

```<code>2, 0, -2
</code>```

The sequence eventually is:

```<code>1, 0, -1, 2, 0, -2, 3, 0, -3, 4, 0, -4, 5, 0, -5, 6, 0, -6, 7, 0, -7, ...
</code>```

Or a more readable form:

```<code>a(0) = 1
a(1) = 0
a(2) = -1
a(3) = 2
a(4) = 0
a(5) = -2
a(6) = 3
a(7) = 0
a(8) = -3
a(9) = 4
...
</code>```

The Task

Given a non-negative integer n, output the nth term of the above sequence. You can choose if you use the zero-indexed or one-indexed version.

Test cases:

Zero-indexed:

```<code>a(0) = 1
a(11) = -4
a(76) = 0
a(134) = -45
a(296) = -99
</code>```

Or if you prefer one-indexed:

```<code>a(1) = 1
a(12) = -4
a(77) = 0
a(135) = -45
a(297) = -99
</code>```

This is code-golf, so the submission with the smallest number of bytes wins!

Body:
05AB1E, 7 bytes

Code:

(3‰`<*(

Explained:

(           # negate input: 12 -> -12
 3‰         # divmod by 3: [-4, 0]
   `        # flatten array: 0, -4
    <       # decrease the mod-result by 1: -1, -4
     *      # multiply: 4
      (     # negate -4


问:
Truth Tables: Your great-grandfather's computer
If you remember back to your schooling years, you might remember learning about Truth Tables. They seemed boring, but they are basis for logic and (some would argue) all computing...

Problem

Your mission, should you choose to accept it is to write a program, function, or widget of code that can output a truth table given input.

Input

Input will be a string (like data structure) containing the logic statement to make the Truth Table into. For example:

```<code>p ∧ q
</code>```

This means p and q(logical conjuction) and will output:

```<code> p  q  p ∧ q
 T  T    T
 T  F    F
 F  T    F
 F  F    F
</code>```

Notice the spacing: The item of the column is in the center of the header

Characters

Score via characters, not bytes
The logic comparison characters are special and not always what they look like. Use these characters:

Logical Conjunction (AND): ∧ U+2227

Logical Disjunction (OR): ∨ U+2228

Logical Negation (NOT) ~ or ¬ U+7e and U+ac respectively

Bonuses

All of these bonuses are optional, but will knock points off your score. Pick any.

Logical Negation

Logical Negation is a unary operator in truth tables. It is the equivalent of ! in most C-based languages. It makes false=>true and vise versa. It is notated with a ¬ or ~ (you must support both). Supporting this will knock off 10% of your score. You must, however, add an additional column to show its results:
For example:

```<code>~p ∧ q
</code>```

will output:

```<code>p  ~p  q  ~p ∧ q
T  F   T     F
T  F   F     F
F  T   T     T
F  T   F     F
</code>```

Pretty Print

The normal table notation is boring. Let's make it pretty! Pretty print format is as follows for p ∧ q is as follows:

```<code>+---+---+-------+
| p | q | p ∧ q |
+---+---+-------+
| T | T |   T   |
+---+---+-------+
| T | F |   F   |
+---+---+-------+
| F | T |   F   |
+---+---+-------+
| F | F |   F   |
+---+---+-------+
</code>```

Special details for pretty printing:

There is a 1 space padding in each cell

Cell values are still centered

If you pretty print your tables, from your code and then multiply by 0.6. Use this function for this bonus:

```<code>score = 0.6 * code
</code>```

Examples

p ∧ q:

```<code>p  q  p ∧ q
T  T    T
T  F    F
F  T    F
F  F    F
</code>```

p ∨ q:

```<code>p  q  p ∨ q
T  T    T
T  F    T
F  T    T
F  F    F
</code>```

~p ∧ q:

```<code>p  ~p  q  ~p ∧ q
T   F  T     F
T   F  F     F
F   T  T     T
F   T  F     F
</code>```

~p ∨ q:

```<code>p  ~p  q  ~p ∧ q
T   F  T     T
T   F  F     F
F   T  T     T
F   T  F     T
</code>```

Rules

Standard loopholes apply

No external resources

If you're going to break the rules, be clever ;)

Shortest Code (in characters) wins. Good Luck!

Body:
MediaWiki template - 2347 characters

MediaWiki has a built template function called {{#expr}} that can handle logical expressions. This must be the perfect challenge for MediaWiki templates! Features such as variables, loops and a readable syntax would have helped a bit, though. Also, the fact that there is no NOT operator for the expr function made it a bit more complex.

{{#sub:{{#replace:{{#replace:{{{1}}}|~|}}|¬|}}|0|1}} {{#sub:{{{1}}}|{{#expr:{{#len:{{{1}}}}}-1}}|{{#len:{{{1}}}}}}} {{{1}}}<br>T T &nbsp;{{#if:{{#pos:{{#sub:{{#replace:{{{1}}}|~|¬}}|0|1}}|¬}}|&nbsp;|}} {{#replace:{{#replace:{{#expr:{{#replace:{{#replace:{{#replace:{{#replace:{{#replace:{{#replace:{{{1}}}|~|¬}}|{{#sub:{{#replace:{{#replace:{{{1}}}|~|}}|¬|}}|0|1}}|{{#if:{{#pos:{{#replace:{{{1}}}|~|¬}}|¬{{#sub:{{#replace:{{#replace:{{{1}}}|~|}}|¬|}}|0|1}}}}|0|1}}}}|{{#sub:{{{1}}}|{{#expr:{{#len:{{{1}}}}}-1}}|{{#len:{{{1}}}}}}}|{{#if:{{#pos:{{#replace:{{{1}}}|~|¬}}|¬{{#sub:{{{1}}}|{{#expr:{{#len:{{{1}}}}}-1}}|{{#len:{{{1}}}}}}}}}|0|1}}|0|1}}|¬|}}|∧|and}}|∨|or}}}}|1|T}}|0|F}}<br>T F &nbsp;{{#if:{{#pos:{{#sub:{{#replace:{{{1}}}|~|¬}}|0|1}}|¬}}|&nbsp;|}} {{#replace:{{#replace:{{#expr:{{#replace:{{#replace:{{#replace:{{#replace:{{#replace:{{#replace:{{{1}}}|~|¬}}|{{#sub:{{#replace:{{#replace:{{{1}}}|~|}}|¬|}}|0|1}}|{{#if:{{#pos:{{#replace:{{{1}}}|~|¬}}|¬{{#sub:{{#replace:{{#replace:{{{1}}}|~|}}|¬|}}|0|1}}}}|0|1}}}}|{{#sub:{{{1}}}|{{#expr:{{#len:{{{1}}}}}-1}}|{{#len:{{{1}}}}}}}|{{#if:{{#pos:{{#replace:{{{1}}}|~|¬}}|¬{{#sub:{{{1}}}|{{#expr:{{#len:{{{1}}}}}-1}}|{{#len:{{{1}}}}}}}}}|1|0}}|1|0}}|¬|}}|∧|and}}|∨|or}}}}|1|T}}|0|F}}<br>F T &nbsp;{{#if:{{#pos:{{#sub:{{#replace:{{{1}}}|~|¬}}|0|1}}|¬}}|&nbsp;|}} {{#replace:{{#replace:{{#expr:{{#replace:{{#replace:{{#replace:{{#replace:{{#replace:{{#replace:{{{1}}}|~|¬}}|{{#sub:{{#replace:{{#replace:{{{1}}}|~|}}|¬|}}|0|1}}|{{#if:{{#pos:{{#replace:{{{1}}}|~|¬}}|¬{{#sub:{{#replace:{{#replace:{{{1}}}|~|}}|¬|}}|0|1}}}}|1|0}}}}|{{#sub:{{{1}}}|{{#expr:{{#len:{{{1}}}}}-1}}|{{#len:{{{1}}}}}}}|{{#if:{{#pos:{{#replace:{{{1}}}|~|¬}}|¬{{#sub:{{{1}}}|{{#expr:{{#len:{{{1}}}}}-1}}|{{#len:{{{1}}}}}}}}}|0|1}}|0|1}}|¬|}}|∧|and}}|∨|or}}}}|1|T}}|0|F}}<br>F F &nbsp;{{#if:{{#pos:{{#sub:{{#replace:{{{1}}}|~|¬}}|0|1}}|¬}}|&nbsp;|}} {{#replace:{{#replace:{{#expr:{{#replace:{{#replace:{{#replace:{{#replace:{{#replace:{{#replace:{{{1}}}|~|¬}}|{{#sub:{{#replace:{{#replace:{{{1}}}|~|}}|¬|}}|0|1}}|{{#if:{{#pos:{{#replace:{{{1}}}|~|¬}}|¬{{#sub:{{#replace:{{#replace:{{{1}}}|~|}}|¬|}}|0|1}}}}|1|0}}}}|{{#sub:{{{1}}}|{{#expr:{{#len:{{{1}}}}}-1}}|{{#len:{{{1}}}}}}}|{{#if:{{#pos:{{#replace:{{{1}}}|~|¬}}|¬{{#sub:{{{1}}}|{{#expr:{{#len:{{{1}}}}}-1}}|{{#len:{{{1}}}}}}}}}|1|0}}|1|0}}|¬|}}|∧|and}}|∨|or}}}}|1|T}}|0|F}}

Test:

{{TemplateName|¬X ∧ ~Y}}

{{TemplateName|p ∨ q}}

Result:

X Y ¬X ∧ ~Y
T T    F
T F    F
F T    F
F F    T

p q p ∨ q
T T   T
T F   T
F T   T
F F   F

I'm assuming MediaWiki >= 1.18, where the ParserFunctions extensions comes bundled with the software.


问:
Minimum cost block diagonalisation
Consider binary block diagonal matrices which have square blocks of 1s on the main diagonal, and are 0 everywhere else. Let's call such matrices "valid" matrices.

For example, here are some valid 4x4 matrices:

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

Note that an alternative way of describing such matrices is that there is a chain of square 1 blocks from the top-left to the bottom-right, touching corner to corner, and everywhere else is 0.

For contrast, here are some invalid 4x4 matrices:

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

You will be given an n by n binary matrix as input – what is the minimum number of 0 bits you'll need to set to 1 in order to get a valid matrix?

You may write a function or program taking in any convenient string, list or matrix format representing an n by n matrix of 0s and 1s (as long as it isn't preprocessed). Rows must be clearly separated in some way, so formats like a 1D array of bits are not allowed.

This is code-golf, so the goal is to minimise the number of bytes in your program.

Examples

For example, if the input is

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

then the answer is 5, since you can set five 0 bits to 1 to get:

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

and this is the minimum number required. However, if the input was

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

then the answer is 24, since the only valid 5x5 matrix where the top-right is 1 is the matrix of all 1s.

Test cases

Tests are represented here as a 2D array of integers.

```<code>[[0]] -> 1
[[1]] -> 0
[[0,1],[0,0]] -> 3
[[1,0],[0,0]] -> 1
[[0,0,0],[0,1,0],[0,0,0]] -> 2
[[0,1,0],[0,0,0],[0,1,0]] -> 7
[[0,1,0],[1,0,0],[0,0,1]] -> 2
[[1,1,1],[1,1,1],[1,1,1]] -> 0
[[0,0,0,0],[0,0,1,0],[0,1,0,0],[0,0,0,0]] -> 4
[[0,0,1,0],[0,0,0,0],[0,0,0,0],[0,0,0,1]] -> 8
[[0,0,1,0],[0,0,0,0],[0,0,0,0],[0,0,1,0]] -> 14
[[0,0,1,0],[0,0,0,0],[0,0,0,0],[0,1,0,0]] -> 14
[[0,0,0,0,0],[0,0,0,0,0],[0,1,0,0,0],[0,0,0,0,1],[0,0,0,0,0]] -> 7
[[0,0,0,0,0],[0,0,0,0,0],[1,0,0,0,0],[0,0,0,0,1],[0,0,0,0,0]] -> 11
[[0,0,0,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,1]] -> 5
[[0,0,0,0,1],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] -> 24
[[0,0,0,1,0],[0,0,0,0,1],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] -> 23
[[0,1,0,0,0],[1,0,0,0,0],[0,0,1,0,0],[0,0,0,0,1],[0,0,0,1,0]] -> 4
[[0,1,1,1,0],[0,1,1,0,1],[0,1,1,1,0],[0,1,0,0,1],[0,0,0,0,0]] -> 14
</code>```

Notes

Related challenge: Print a Block-Diagonal Matrix

Inspiration: Freedom Factory, Google Code Jam 2016 Problem 2D

答:
Pyth, 45 bytes

```<code>-hSlMf@I.DRlQx1sQTms.b^+LsYN2d+0._ds.pM./lQss
</code>```

Difficult task, so it's quite long.

Try it online: Demonstration or Test Suite

Explanation:

s.pM./lQ computes all integer partitions of len(matrix). ms.b^+LsYN2d+0._d converts them into coordinate-pairs. For instance the partition [1, 2, 2] of 5 gets converted into [[0,0], [1,1], [1,2], [2,1], [2,2], [3,3], [3,4], [4,3], [4,4].

f@I.DRlQx1sQT then filters for partitions, that completely overlap the matrix (.DRlQx1sQ computes all coordinate-pairs of the active cells in the matrix).

-hSlM...ss counts the cells of each remaining partitions, chooses the one with the least cells, and subtracts the already active cells.

Title: Minimum cost block diagonalisation


问:
Let's build a Staircase
We don't have enough (semi-)easy challenges for beginners. More and more of the easy ones are already taken. So I tried to come up with something that might be achievable by beginners, but that isn't a duplicate.

Input:

A single string separated with your OS new-line (i.e. \r\n),

or an array with multiple strings.

Output - The Stairs:

Remove all non-alphabetic and non-numeric symbols. So all that's left is [A-Za-z0-9]. And then 'build a stairs'; basically ordering them on length with the smallest at top and widest at the bottom.

Challenge rules:

When two strings are of equal length, we merge them with each other as one big string (the order doesn't matter, so it could be from first to last or last to first, whichever of the two you prefer).

The rule above can stack when the merged strings are of equal length again (see test case 2).

General rules:

The input is STDIN and contains only ASCII characters. And the output is STDOUT.

The case of the output must be the same as the input.

<s>Each submission must be a full program able to compile and run, so not just a method/function.</s> EDIT: I'm rather new, so perhaps it's indeed better to use the default from now on, even though I prefer a full program myself. Sorry for everyone that has already posted a full program. Feel free to edit, and I'll try to not change the post mid-challenge next time.

This is code-golf, so the shortest answer in bytes wins. I probably accept the shortest answer in a year from now.

Don't let code-golf answers discourage you from posting golfed non-codegolf languages like C# and alike! Try to come up with the shortest answer for any programming language.

Feel free to use newer languages than this question.

Test cases:

Input 1:

```<code>This is a sample text,
that you will have to use to build stairs.
The wood may be of excellent quality,
or pretty crappy almost falling apart and filled with termites.
Bla bla bla - some more text
Ok, that will do
</code>```

Output 1:

```<code>Okthatwilldo
Thisisasampletext
Blablablasomemoretext
Thewoodmaybeofexcellentquality
thatyouwillhavetousetobuildstairs
orprettycrappyalmostfallingapartandfilledwithtermites
</code>```

Input 2:

```<code>A
small
one
that
contains
equal
length
strings
for
the
special
rule
</code>```

Output 2:

```<code>A                   Or alternatively:       A
length                                      length
oneforthe                                   theforone
smallequal                                  equalsmall
stringsspecial                              specialstrings
thatrulecontains                            containsrulethat
</code>```

Steps explained of 2:

First order on length:

```<code>A
one
for
the
that
rule
small
equal
length
strings
special
contains
</code>```

First merge:

```<code>A
oneforthe
thatrule
smallequal
length
stringsspecial
contains
</code>```

Second order on length:

```<code>A
length
thatrule
contains
oneforthe
smallequal
stringsspecial
</code>```

Second merge:

```<code>A
length
thatrulecontains
oneforthe
smallequal
stringsspecial
</code>```

Third order on length:

```<code>A
length
oneforthe
smallequal
stringsspecial
thatrulecontains
</code>```

Input 3:

```<code>Test,
test.
This
is
a
test.
</code>```

Output 3:

```<code>Okthatwilldo
Thisisasampletext
Blablablasomemoretext
Thewoodmaybeofexcellentquality
thatyouwillhavetousetobuildstairs
orprettycrappyalmostfallingapartandfilledwithtermites
</code>```0

Input 4:

```<code>Okthatwilldo
Thisisasampletext
Blablablasomemoretext
Thewoodmaybeofexcellentquality
thatyouwillhavetousetobuildstairs
orprettycrappyalmostfallingapartandfilledwithtermites
</code>```1

Output 4:

```<code>Okthatwilldo
Thisisasampletext
Blablablasomemoretext
Thewoodmaybeofexcellentquality
thatyouwillhavetousetobuildstairs
orprettycrappyalmostfallingapartandfilledwithtermites
</code>```2

答:
Python 3, 264 Bytes

I'm not good at code golf so I'm confident this won't be the best Python 3 answer. This uses recursion and an ordered dict with all the words for each length.

```<code>from collections import*
def f(i):
 d = defaultdict(list)
 for l in i: x = "".join(c for c in l if c.isalnum());d[len(x)].append(x)
 n = (sorted(["".join(d[z]) for z in d.keys()], key=len))
 if n == i:return "\n".join(n)
 return f(n)
print(f(eval(input())))
</code>```

Takes input from stdin as a list, for example, test it with this list:

```<code>['A', 'small', 'one', 'that', 'contains', 'equal', 'length', 'strings', 'for', 'the', 'special', 'rule']
</code>```

Will output:

```<code>A
length
oneforthe
smallequal
stringsspecial
thatrulecontains
</code>```

Title: Let's build a Staircase

Body:
Python 3, 264 Bytes

I'm not good at code golf so I'm confident this won't be the best Python 3 answer. This uses recursion and an ordered dict with all the words for each length.

from collections import*
def f(i):
 d = defaultdict(list)
 for l in i: x = "".join(c for c in l if c.isalnum());d[len(x)].append(x)
 n = (sorted(["".join(d[z]) for z in d.keys()], key=len))
 if n == i:return "\n".join(n)
 return f(n)
print(f(eval(input())))

Takes input from stdin as a list, for example, test it with this list:

['A', 'small', 'one', 'that', 'contains', 'equal', 'length', 'strings', 'for', 'the', 'special', 'rule']

Will output:

A
length
oneforthe
smallequal
stringsspecial
thatrulecontains


答:
MATL, <s>46</s> 43 bytes

```<code>nX^tQt:qZ^!tsb=Z)"@!"@1$l]@n$YdG-Q?6MG>zvX<
</code>```

Input is a 2D array with semicolon as row separator. For example, the input for the last test case is

```<code>[0,1,1,1,0;0,1,1,0,1;0,1,1,1,0;0,1,0,0,1;0,0,0,0,0]
</code>```

Try it online! Or verify all test cases (code slightly modified to take all inputs; the results appear after a few seconds)

Explanation

Let the input be an N×N matrix. The code first computes all (N+1)-tuples of block sizes that produce the appropriate matrix size. For example, for N=4 the tuples are 0 0 0 0 4, 0 0 0 1 3, ..., 4 0 0 0 0. For each tuple it builds the block-diagonal matrix with those block sizes. It then checks if the matrix covers all the 1 entries in the input, and if so takes note of the number of 1 entries that were not present in the input. The final result is the minimum of all the obtained numbers.

```<code>nX^      % Implicit input  an N×N matrix. Get N
t        % Duplicate N
Qt:q     % Vector [0 1 ... N]
Z^       % Cartesian power. Gives 2D array
!ts      % Transpose, duplicate, sum of each column
b=       % Logical vector that equals true if the sum is N
Z)       % Filter columns according to that. Only keep columns that sum to N. Each
         % column is the size of one block
"        % For each column
  @      %   Push that column
  "      %   For each entry of that column
    @    %     Push that entry
    1$l  %     Square matrix with that size, filled with 1
  ]      %   End
  @n     %   Column size. This is the number of blocks in the block-diagonal matrix
  $Yd    %   Build block-diagonal matrix from those blocks
  G-Q    %   Subtract input matrix element-wise, and add 1
  ?      %   If all entries are nonzero (this means each that entry that is 1 in the
         %   block-diagonal matrix is also 1 in the input matrix)
    6M   %   Push block-diagonal matrix again
    G>   %   For each entry, gives 1 if it exceeds the corresponding entry of the
         %   input, that is, if the block-diagonal matrix is 1 and the input is 0
    z    %   Number of 1 entries
    v    %   Concatenate vertically with previous values
    X<   %   Take minimum so far
         %   Implicit end
         % Implicit end
         % Implicit display
</code>```

Title: Minimum cost block diagonalisation

Body:
Consider binary block diagonal matrices which have square blocks of 1s on the main diagonal, and are 0 everywhere else. Let's call such matrices "valid" matrices.

For example, here are some valid 4x4 matrices:

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

Note that an alternative way of describing such matrices is that there is a chain of square 1 blocks from the top-left to the bottom-right, touching corner to corner, and everywhere else is 0.

For contrast, here are some invalid 4x4 matrices:

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

You will be given an n by n binary matrix as input – what is the minimum number of 0 bits you'll need to set to 1 in order to get a valid matrix?

You may write a function or program taking in any convenient string, list or matrix format representing an n by n matrix of 0s and 1s (as long as it isn't preprocessed). Rows must be clearly separated in some way, so formats like a 1D array of bits are not allowed.

This is code-golf, so the goal is to minimise the number of bytes in your program.

Examples

For example, if the input is

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

then the answer is 5, since you can set five 0 bits to 1 to get:

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

and this is the minimum number required. However, if the input was

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

then the answer is 24, since the only valid 5x5 matrix where the top-right is 1 is the matrix of all 1s.

Test cases

Tests are represented here as a 2D array of integers.

```<code>[[0]] -> 1
[[1]] -> 0
[[0,1],[0,0]] -> 3
[[1,0],[0,0]] -> 1
[[0,0,0],[0,1,0],[0,0,0]] -> 2
[[0,1,0],[0,0,0],[0,1,0]] -> 7
[[0,1,0],[1,0,0],[0,0,1]] -> 2
[[1,1,1],[1,1,1],[1,1,1]] -> 0
[[0,0,0,0],[0,0,1,0],[0,1,0,0],[0,0,0,0]] -> 4
[[0,0,1,0],[0,0,0,0],[0,0,0,0],[0,0,0,1]] -> 8
[[0,0,1,0],[0,0,0,0],[0,0,0,0],[0,0,1,0]] -> 14
[[0,0,1,0],[0,0,0,0],[0,0,0,0],[0,1,0,0]] -> 14
[[0,0,0,0,0],[0,0,0,0,0],[0,1,0,0,0],[0,0,0,0,1],[0,0,0,0,0]] -> 7
[[0,0,0,0,0],[0,0,0,0,0],[1,0,0,0,0],[0,0,0,0,1],[0,0,0,0,0]] -> 11
[[0,0,0,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,1]] -> 5
[[0,0,0,0,1],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] -> 24
[[0,0,0,1,0],[0,0,0,0,1],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] -> 23
[[0,1,0,0,0],[1,0,0,0,0],[0,0,1,0,0],[0,0,0,0,1],[0,0,0,1,0]] -> 4
[[0,1,1,1,0],[0,1,1,0,1],[0,1,1,1,0],[0,1,0,0,1],[0,0,0,0,0]] -> 14
</code>```

Notes

Related challenge: Print a Block-Diagonal Matrix

Inspiration: Freedom Factory, Google Code Jam 2016 Problem 2D

Body:
MATL, <s>46</s> 43 bytes

nX^tQt:qZ^!tsb=Z)"@!"@1$l]@n$YdG-Q?6MG>zvX<

Input is a 2D array with semicolon as row separator. For example, the input for the last test case is

[0,1,1,1,0;0,1,1,0,1;0,1,1,1,0;0,1,0,0,1;0,0,0,0,0]

Try it online! Or <a href="http://matl.tryitonline.net/#code=YApYSW5YXnRRdDpxWl4hdHNiPVopIkAhIkAxJGxdQG4kWWRJLVE_Nk1JPnp2WDxdXQpEVA&input=WzBdClsxXQpbMCwxOzAsMF0KWzEsMDswLDBdClswLDAsMDswLDEsMDswLDAsMF0KWzAsMSwwOzAsMCwwOzAsMSwwXQpbMCwxLDA7MSwwLDA7MCwwLDFdClsxLDEsMTsxLDEsMTsxLDEsMV0KWzAsMCwwLDA7MCwwLDEsMDswLDEsMCwwOzAsMCwwLDBdClswLDAsMSwwOzAsMCwwLDA7MCwwLDAsMDswLDAsMCwxXQpbMCwwLDEsMDswLDAsMCwwOzAsMCwwLDA7MCwwLDEsMF0KWzAsMCwxLDA7MCwwLDAsMDswLDAsMCwwOzAsMSwwLDBdClswLDAsMCwwLDA7MCwwLDAsMCwwOzAsMSwwLDAsMDswLDAsMCwwLDE7MCwwLDAsMCwwXQpbMCwwLDAsMCwwOzAsMCwwLDAsMDsxLDAsMCwwLDA7MCwwLDAsMCwxOzAsMCwwLDAsMF0KWzAsMCwwLDAsMDswLDAsMSwwLDA7MCwwLDAsMCwwOzAsMCwwLDAsMDswLDAsMCwwLDFdClswLDAsMCwwLDE7MCwwLDAsMCwwOzAsMCwwLDAsMDswLDAsMCwwLDA7MCwwLDAsMCwwXQpbMCwwLDAsMSwwOzAsMCwwLDAsMTswLDAsMCwwLDA7MCwwLDAsMCwwOzAsMCwwLDAsMF0KWzAsMSwwLDAsMDsxLDAsMCwwLDA7MCwwLDEsMCwwOzAsMCwwLDAsMTswLDAsMCwxLDBdClswLDEsMSwxLDA7MCwxLDEsMCwxOzAsMSwxLDEsMDswLDEsMCwwLDE7MCwwLDAsMCwwXQ" rel="nofollow">verify all test cases (code slightly modified to take all inputs; the results appear after a few seconds)

Explanation

Let the input be an N×N matrix. The code first computes all (N+1)-tuples of block sizes that produce the appropriate matrix size. For example, for N=4 the tuples are 0 0 0 0 4, 0 0 0 1 3, ..., 4 0 0 0 0. For each tuple it builds the block-diagonal matrix with those block sizes. It then checks if the matrix covers all the 1 entries in the input, and if so takes note of the number of 1 entries that were not present in the input. The final result is the minimum of all the obtained numbers.

nX^      % Implicit input  an N×N matrix. Get N
t        % Duplicate N
Qt:q     % Vector [0 1 ... N]
Z^       % Cartesian power. Gives 2D array
!ts      % Transpose, duplicate, sum of each column
b=       % Logical vector that equals true if the sum is N
Z)       % Filter columns according to that. Only keep columns that sum to N. Each
         % column is the size of one block
"        % For each column
  @      %   Push that column
  "      %   For each entry of that column
    @    %     Push that entry
    1$l  %     Square matrix with that size, filled with 1
  ]      %   End
  @n     %   Column size. This is the number of blocks in the block-diagonal matrix
  $Yd    %   Build block-diagonal matrix from those blocks
  G-Q    %   Subtract input matrix element-wise, and add 1
  ?      %   If all entries are nonzero (this means each that entry that is 1 in the
         %   block-diagonal matrix is also 1 in the input matrix)
    6M   %   Push block-diagonal matrix again
    G>   %   For each entry, gives 1 if it exceeds the corresponding entry of the
         %   input, that is, if the block-diagonal matrix is 1 and the input is 0
    z    %   Number of 1 entries
    v    %   Concatenate vertically with previous values
    X<   %   Take minimum so far
         %   Implicit end
         % Implicit end
         % Implicit display


Title: Let's build a Staircase

Body:
We don't have enough (semi-)easy challenges for beginners. More and more of the easy ones are already taken. So I tried to come up with something that might be achievable by beginners, but that isn't a duplicate.

Input:

A single string separated with your OS new-line (i.e. \r\n),

or an array with multiple strings.

Output - The Stairs:

Remove all non-alphabetic and non-numeric symbols. So all that's left is [A-Za-z0-9]. And then 'build a stairs'; basically ordering them on length with the smallest at top and widest at the bottom.

Challenge rules:

When two strings are of equal length, we merge them with each other as one big string (the order doesn't matter, so it could be from first to last or last to first, whichever of the two you prefer).

The rule above can stack when the merged strings are of equal length again (see test case 2).

General rules:

The input is STDIN and contains only ASCII characters. And the output is STDOUT.

The case of the output must be the same as the input.

<s>Each submission must be a full program able to compile and run, so not just a method/function.</s> EDIT: I'm rather new, so perhaps it's indeed better to use the default from now on, even though I prefer a full program myself. Sorry for everyone that has already posted a full program. Feel free to edit, and I'll try to not change the post mid-challenge next time.

This is code-golf, so the shortest answer in bytes wins. I probably accept the shortest answer in a year from now.

Don't let code-golf answers discourage you from posting golfed non-codegolf languages like C# and alike! Try to come up with the shortest answer for any programming language.

Feel free to use newer languages than this question.

Test cases:

Input 1:

```<code>This is a sample text,
that you will have to use to build stairs.
The wood may be of excellent quality,
or pretty crappy almost falling apart and filled with termites.
Bla bla bla - some more text
Ok, that will do
</code>```

Output 1:

```<code>Okthatwilldo
Thisisasampletext
Blablablasomemoretext
Thewoodmaybeofexcellentquality
thatyouwillhavetousetobuildstairs
orprettycrappyalmostfallingapartandfilledwithtermites
</code>```

Input 2:

```<code>A
small
one
that
contains
equal
length
strings
for
the
special
rule
</code>```

Output 2:

```<code>A                   Or alternatively:       A
length                                      length
oneforthe                                   theforone
smallequal                                  equalsmall
stringsspecial                              specialstrings
thatrulecontains                            containsrulethat
</code>```

Steps explained of 2:

First order on length:

```<code>A
one
for
the
that
rule
small
equal
length
strings
special
contains
</code>```

First merge:

```<code>A
oneforthe
thatrule
smallequal
length
stringsspecial
contains
</code>```

Second order on length:

```<code>A
length
thatrule
contains
oneforthe
smallequal
stringsspecial
</code>```

Second merge:

```<code>A
length
thatrulecontains
oneforthe
smallequal
stringsspecial
</code>```

Third order on length:

```<code>A
length
oneforthe
smallequal
stringsspecial
thatrulecontains
</code>```

Input 3:

```<code>Test,
test.
This
is
a
test.
</code>```

Output 3:

```<code>Okthatwilldo
Thisisasampletext
Blablablasomemoretext
Thewoodmaybeofexcellentquality
thatyouwillhavetousetobuildstairs
orprettycrappyalmostfallingapartandfilledwithtermites
</code>```0

Input 4:

```<code>Okthatwilldo
Thisisasampletext
Blablablasomemoretext
Thewoodmaybeofexcellentquality
thatyouwillhavetousetobuildstairs
orprettycrappyalmostfallingapartandfilledwithtermites
</code>```1

Output 4:

```<code>Okthatwilldo
Thisisasampletext
Blablablasomemoretext
Thewoodmaybeofexcellentquality
thatyouwillhavetousetobuildstairs
orprettycrappyalmostfallingapartandfilledwithtermites
</code>```2

Body:
Retina, <s>69</s> 63 bytes

[^\w¶]|_

{`\b((.)+)¶((?.)+)\b(?(2)(?!))
$1$3
O$`(.)+
$#1$*

Try it online!


问:
Golf me an ASCII Alphabet
Don't you find that reading simple text isn't appealing enough? Try our

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

Much more fancy isn't it? But it's pretty long to write by hand, it would be wonderful if someone did a program that do it for me !

Your task, if you volunteer to help me, will be to write a program or a function that takes a string containing [a-zA-Z\s\n] only, and output (or return) the ascii writing of it!

You must use the following alphabet to format your output:

```<code>##### ####   ###  ####  ##### #####  ###  #   # ##### ##### #   # #     #   #
#   # #   # #   # #   # #     #     #     #   #   #     #   #  #  #     ## ##
##### ####  #     #   # ####  ####  #  ## #####   #     #   ###   #     # # #
#   # #   # #   # #   # #     #     #   # #   #   #   # #   # #   #     #   #
#   # ####   ###  ####  ##### #      ###  #   # ##### ###   #  #  ##### #   #

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

The space:

```<code>     |
     | it's a 5x5 square of spaces
     | but had to pad it with |s to make it appear in this post
     |
     |
</code>```

As this is a fixed-width font, the space character is also surrounded by spaces, resulting in a 7-width space between the two letters.

```<code>a b
     1234567       -- these numbers are just for the example, you don't have to output them
#####       ####
#   #       #   #
#####       ####
#   #       #   #
#   #       ####

a  b
     1234567890123
#####             ####
#   #             #   #
#####             ####
#   #             #   #
#   #             ####
</code>```

When you encounter a newline, as in the input

```<code>ascii
text
</code>```

Just make sure to separate the two blocks of text by at least one empty line

```<code>#####  ###   ###  ##### #####
#   # #     #   #   #     #
#####  ###  #       #     #
#   #     # #   #   #     #
#   #  ###   ###  ##### #####

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

Also, you are allowed to replace the #s with any other character as long as it is in the printable ASCII range, and is not spaces. You could for instance use As for the letter A, B for the letter B and so on.

As this is code-golf (and moreover kolmogorov-complexity) the winning submission will be the one that solve this challenge in the least byte possible, have fun!

答:
Clojure, 552 bytes

```<code>(defn t[s](print(reduce #(str %1"\n"%2)(map #(apply str %)(let[a[:jpcfl :j2uke :92y3y :j2kam :jomcf :jomc0 :92b72 :ayp81 :jfm3j :jfmho :azc7m :ab6zj :b5i5t :b43n5 :92ywe :j2uj4 :92yy7 :j2uqc :926um :jfm2s :aye5q :ay8g4 :ayhkh :at6q9 :at6kk :je7mn :0]](map(fn[o](map #(str(.replace %"0"" ")"\n")(map(fn[w](reduce #(str %1(.substring %2 w(+ w 5))"0")""(map #(str(apply str(repeat(- 25(count %))"0"))%)(map #(Integer/toString(Integer/valueOf(name %)36)2)(map a(map #(if(= % \space)26(-(int %)97))(.toLowerCase o)))))))(range 0 25 5))))(.split s"\n")))))))
</code>```

Each letter in ascii is represented as a binary string with # - 1, space - 0. Then it's converted to base 36 so that it only takes 5 chars to store + ":" to let Clojure know that it should be treated as symbol.
Then the input is split by newline symbol and for each line we convert a letter in 36 base back to binary base and get first [0:5] symbols add newline symbols, get next [5:10] symbols and so on.

You can see it running here - https://ideone.com/y99ST5

Title: Golf me an ASCII Alphabet

Body:
Clojure, 552 bytes

(defn t[s](print(reduce #(str %1"\n"%2)(map #(apply str %)(let[a[:jpcfl :j2uke :92y3y :j2kam :jomcf :jomc0 :92b72 :ayp81 :jfm3j :jfmho :azc7m :ab6zj :b5i5t :b43n5 :92ywe :j2uj4 :92yy7 :j2uqc :926um :jfm2s :aye5q :ay8g4 :ayhkh :at6q9 :at6kk :je7mn :0]](map(fn[o](map #(str(.replace %"0"" ")"\n")(map(fn[w](reduce #(str %1(.substring %2 w(+ w 5))"0")""(map #(str(apply str(repeat(- 25(count %))"0"))%)(map #(Integer/toString(Integer/valueOf(name %)36)2)(map a(map #(if(= % \space)26(-(int %)97))(.toLowerCase o)))))))(range 0 25 5))))(.split s"\n")))))))

Each letter in ascii is represented as a binary string with # - 1, space - 0. Then it's converted to base 36 so that it only takes 5 chars to store + ":" to let Clojure know that it should be treated as symbol.
Then the input is split by newline symbol and for each line we convert a letter in 36 base back to binary base and get first [0:5] symbols add newline symbols, get next [5:10] symbols and so on.

You can see it running here - https://ideone.com/y99ST5


答:
Oracle SQL 11.2, 346 bytes

The lines in the input string are separated by '¤'.
That way it is not necessary to create a table to use as the input.

This is a sample text,¤that you will have to use to build stairs.¤The wood may be of excellent quality,¤or pretty crappy almost falling apart and filled with termites.¤Bla bla bla - some more text¤Ok, that will do
A¤small¤one¤that¤contains¤equal¤length¤strings¤for¤the¤special¤rule
Test,¤test.¤This¤is¤a¤test.¤
```

<p>Query :</p>

<pre class="lang-sql prettyprint-override"><code>WITH v AS(SELECT REGEXP_REPLACE(COLUMN_VALUE,'[^a-zA-Z0-9]')s FROM XMLTABLE(('"'||REPLACE(:1,'¤','","')||'"'))),r(s,i,l)AS(SELECT s,1,1 FROM v UNION ALL SELECT LISTAGG(s)WITHIN GROUP(ORDER BY s)OVER(PARTITION BY LENGTH(s)),ROW_NUMBER()OVER(PARTITION BY LENGTH(s)ORDER BY s),l+1 FROM r WHERE l<LENGTH(:1)AND i=1)SELECT s FROM r WHERE l=LENGTH(:1);
</code>```

Un-golfed

WITH v AS
(
  -- Splits on ¤ and keeps only alphanum characters
  SELECT REGEXP_REPLACE(COLUMN_VALUE,'[^a-zA-Z0-9]')s FROM XMLTABLE(('"'||REPLACE(:1,'¤','","')||'"'))
)
-- Recursive view
-- s : string
-- i : index of the string in case of duplicates
-- l : exit condition
,r(s,i,l)AS
(
  -- Start with every element of the input
  SELECT s,1,1 FROM v
  UNION ALL
  SELECT -- Concatenate elements of the same lengths
         LISTAGG(s)WITHIN GROUP(ORDER BY s)OVER(PARTITION BY LENGTH(s))
         -- Index of elements of the same length (listagg with over generates duplicates)
        ,ROW_NUMBER()OVER(PARTITION BY LENGTH(s) ORDER BY s)
        -- exit condition
        ,l+1 FROM r WHERE l<LENGTH(:1) AND i=1
)
-- Keep only the elements from the last iteration (automaticaly sorted on my system)
SELECT s FROM r WHERE l=LENGTH(:1)
```

Title: Let's build a Staircase

Body:
Oracle SQL 11.2, 346 bytes

The lines in the input string are separated by '¤'.
That way it is not necessary to create a table to use as the input.

This is a sample text,¤that you will have to use to build stairs.¤The wood may be of excellent quality,¤or pretty crappy almost falling apart and filled with termites.¤Bla bla bla - some more text¤Ok, that will do
A¤small¤one¤that¤contains¤equal¤length¤strings¤for¤the¤special¤rule
Test,¤test.¤This¤is¤a¤test.¤

Query :

WITH v AS(SELECT REGEXP_REPLACE(COLUMN_VALUE,'[^a-zA-Z0-9]')s FROM XMLTABLE(('"'||REPLACE(:1,'¤','","')||'"'))),r(s,i,l)AS(SELECT s,1,1 FROM v UNION ALL SELECT LISTAGG(s)WITHIN GROUP(ORDER BY s)OVER(PARTITION BY LENGTH(s)),ROW_NUMBER()OVER(PARTITION BY LENGTH(s)ORDER BY s),l+1 FROM r WHERE l<LENGTH(:1)AND i=1)SELECT s FROM r WHERE l=LENGTH(:1);

Un-golfed

WITH v AS
(
  -- Splits on ¤ and keeps only alphanum characters
  SELECT REGEXP_REPLACE(COLUMN_VALUE,'[^a-zA-Z0-9]')s FROM XMLTABLE(('"'||REPLACE(:1,'¤','","')||'"'))
)
-- Recursive view
-- s : string
-- i : index of the string in case of duplicates
-- l : exit condition
,r(s,i,l)AS
(
  -- Start with every element of the input
  SELECT s,1,1 FROM v
  UNION ALL
  SELECT -- Concatenate elements of the same lengths
         LISTAGG(s)WITHIN GROUP(ORDER BY s)OVER(PARTITION BY LENGTH(s))
         -- Index of elements of the same length (listagg with over generates duplicates)
        ,ROW_NUMBER()OVER(PARTITION BY LENGTH(s) ORDER BY s)
        -- exit condition
        ,l+1 FROM r WHERE l<LENGTH(:1) AND i=1
)
-- Keep only the elements from the last iteration (automaticaly sorted on my system)
SELECT s FROM r WHERE l=LENGTH(:1)


答:
Javascript <s>198</s> <s>188</s> <s>186</s> 179 bytes

This is my second longest golfed javascript program

```<code>s=>s.replace(/[^\w]|_/g,``,l=0).split(/\s/g).sort(g=(a,b)=>a[m=`length`]-b[m]).reduce((a,b,c)=>a+(a.split(/\s/g)[c-1][m]<b[m]?`
`:` `)+b).replace(/ /g,``).split`
`.sort(g).join`
`
</code>```

Probably can be golfed further

Title: Let's build a Staircase

Body:
Javascript <s>198</s> <s>188</s> <s>186</s> 179 bytes

This is my second longest golfed javascript program

s=>s.replace(/[^\w]|_/g,``,l=0).split(/\s/g).sort(g=(a,b)=>a[m=`length`]-b[m]).reduce((a,b,c)=>a+(a.split(/\s/g)[c-1][m]<b[m]?`
`:` `)+b).replace(/ /g,``).split`
`.sort(g).join`
`

Probably can be golfed further


答:
Python 3, 375 bytes

```<code>f=lambda i:"\n\n".join("\n".join(map(" ".join,zip(*[[x.replace("0"," ")[a*5:a*5+5]for a in range(5)]for x in[["{:025b}".format(int(c,36))for c in'0 JPCFL J2UKE 92Y3Y J2KAM JOMCF JOMC0 92B72 AYP81 JFM3J JFMHO AZC7M AB6ZJ B5I5T B43N5 92YWE J2UJ4 92YY7 J2UQC 926UM JFM2S AYE5Q AY8G4 AYHKH AT6Q9 AT6KK AWU7'.split()][x!=" "and ord(x)-64]for x in j.upper()]])))for j in i.split("\n"))
</code>```

See this code running on ideone.com.

The same code, but somehow nicely indented, formatted and commented:

```<code>f = lambda i: \

    # join multiline strings together using an empty line as separator:
    "\n\n".join(

        # join the string lines of one big output line together:
        "\n".join(

            # join the corresponding rows of the letters together using " ":
            map(" ".join, zip(*

                # make a list (output line) of list (output characters)
                # of strings (single character's rows):
                [

                    # replace 0s with spaces and split the bit strings into
                    # chunks of 5 characters - the rows of each letter:
                    [x.replace("0", " ")[a*5 : a*5+5] for a in range(5)]

                    for x in [

                        # split the space separated character codes and
                        # convert them from base 36 to
                        # base 2 strings of length 25:
                        ["{:025b}".format(int(c, 36)) for c in

                         # the encoded font data (reformatted):
                         '0 JPCFL J2UKE 92Y3Y J2KAM JOMCF JOMC0 92B72 '
                         'AYP81 JFM3J JFMHO AZC7M AB6ZJ B5I5T B43N5 92YWE '
                         'J2UJ4 92YY7 J2UQC 926UM JFM2S AYE5Q AY8G4 AYHKH '
                         'AT6Q9 AT6KK AWU7'.split()]

                        # select element 0 if we want a space, else find
                        # out the index from the ASCII code of the letter:
                        [x != " " and ord(x) - 64]

                        # repeat for every character in the input line:
                        for x in j.upper()
                    ]
                ]
            ))

        # repeat for every line in the input
        ) for j in i.split("\n")
    )
</code>```

I also decided to go for base 36 encoding as that's the highest base Python's built-in int() natively supports. Here is a short Python 3 script I wrote (ungolfed) that converts font definitions like in the question into base 36 codes: My converter on ideone.com

The result consists of the character 1 as enabled pixel and a space   as disabled pixel. Here's a single example run:

Input (line break as \n):

```<code>Hello World
Python rocks
</code>```

Output:

```<code>1   1 11111 1     1      111        1   1  111  1111  1     1111
1   1 1     1     1     1   1       1   1 1   1 1   1 1     1   1
11111 1111  1     1     1   1       1 1 1 1   1 1111  1     1   1
1   1 1     1     1     1   1       11 11 1   1 11    1     1   1
1   1 11111 11111 11111  111        1   1  111  1 1   11111 1111

1111  1   1 11111 1   1  111  1   1       1111   111   111  1   1  111
1   1  1 1    1   1   1 1   1 11  1       1   1 1   1 1   1 1  1  1
1111    1     1   11111 1   1 1 1 1       1111  1   1 1     111    111
1       1     1   1   1 1   1 1  11       11    1   1 1   1 1 1       1
1       1     1   1   1  111  1   1       1 1    111   111  1  1   111
</code>```

Title: Golf me an ASCII Alphabet

Body:
Don't you find that reading simple text isn't appealing enough? Try our

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

Much more fancy isn't it? But it's pretty long to write by hand, it would be wonderful if someone did a program that do it for me !

Your task, if you volunteer to help me, will be to write a program or a function that takes a string containing [a-zA-Z\s\n] only, and output (or return) the ascii writing of it!

You must use the following alphabet to format your output:

```<code>##### ####   ###  ####  ##### #####  ###  #   # ##### ##### #   # #     #   #
#   # #   # #   # #   # #     #     #     #   #   #     #   #  #  #     ## ##
##### ####  #     #   # ####  ####  #  ## #####   #     #   ###   #     # # #
#   # #   # #   # #   # #     #     #   # #   #   #   # #   # #   #     #   #
#   # ####   ###  ####  ##### #      ###  #   # ##### ###   #  #  ##### #   #

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

The space:

```<code>     |
     | it's a 5x5 square of spaces
     | but had to pad it with |s to make it appear in this post
     |
     |
</code>```

As this is a fixed-width font, the space character is also surrounded by spaces, resulting in a 7-width space between the two letters.

```<code>a b
     1234567       -- these numbers are just for the example, you don't have to output them
#####       ####
#   #       #   #
#####       ####
#   #       #   #
#   #       ####

a  b
     1234567890123
#####             ####
#   #             #   #
#####             ####
#   #             #   #
#   #             ####
</code>```

When you encounter a newline, as in the input

```<code>ascii
text
</code>```

Just make sure to separate the two blocks of text by at least one empty line

```<code>#####  ###   ###  ##### #####
#   # #     #   #   #     #
#####  ###  #       #     #
#   #     # #   #   #     #
#   #  ###   ###  ##### #####

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

Also, you are allowed to replace the #s with any other character as long as it is in the printable ASCII range, and is not spaces. You could for instance use As for the letter A, B for the letter B and so on.

As this is code-golf (and moreover kolmogorov-complexity) the winning submission will be the one that solve this challenge in the least byte possible, have fun!

Body:
Python 3, 375 bytes

f=lambda i:"\n\n".join("\n".join(map(" ".join,zip(*[[x.replace("0"," ")[a*5:a*5+5]for a in range(5)]for x in[["{:025b}".format(int(c,36))for c in'0 JPCFL J2UKE 92Y3Y J2KAM JOMCF JOMC0 92B72 AYP81 JFM3J JFMHO AZC7M AB6ZJ B5I5T B43N5 92YWE J2UJ4 92YY7 J2UQC 926UM JFM2S AYE5Q AY8G4 AYHKH AT6Q9 AT6KK AWU7'.split()][x!=" "and ord(x)-64]for x in j.upper()]])))for j in i.split("\n"))

See this code running on ideone.com.

The same code, but somehow nicely indented, formatted and commented:

f = lambda i: \

    # join multiline strings together using an empty line as separator:
    "\n\n".join(

        # join the string lines of one big output line together:
        "\n".join(

            # join the corresponding rows of the letters together using " ":
            map(" ".join, zip(*

                # make a list (output line) of list (output characters)
                # of strings (single character's rows):
                [

                    # replace 0s with spaces and split the bit strings into
                    # chunks of 5 characters - the rows of each letter:
                    [x.replace("0", " ")[a*5 : a*5+5] for a in range(5)]

                    for x in [

                        # split the space separated character codes and
                        # convert them from base 36 to
                        # base 2 strings of length 25:
                        ["{:025b}".format(int(c, 36)) for c in

                         # the encoded font data (reformatted):
                         '0 JPCFL J2UKE 92Y3Y J2KAM JOMCF JOMC0 92B72 '
                         'AYP81 JFM3J JFMHO AZC7M AB6ZJ B5I5T B43N5 92YWE '
                         'J2UJ4 92YY7 J2UQC 926UM JFM2S AYE5Q AY8G4 AYHKH '
                         'AT6Q9 AT6KK AWU7'.split()]

                        # select element 0 if we want a space, else find
                        # out the index from the ASCII code of the letter:
                        [x != " " and ord(x) - 64]

                        # repeat for every character in the input line:
                        for x in j.upper()
                    ]
                ]
            ))

        # repeat for every line in the input
        ) for j in i.split("\n")
    )

I also decided to go for base 36 encoding as that's the highest base Python's built-in int() natively supports. Here is a short Python 3 script I wrote (ungolfed) that converts font definitions like in the question into base 36 codes: My converter on ideone.com

The result consists of the character 1 as enabled pixel and a space   as disabled pixel. Here's a single example run:

Input (line break as \n):

Hello World
Python rocks

Output:

1   1 11111 1     1      111        1   1  111  1111  1     1111
1   1 1     1     1     1   1       1   1 1   1 1   1 1     1   1
11111 1111  1     1     1   1       1 1 1 1   1 1111  1     1   1
1   1 1     1     1     1   1       11 11 1   1 11    1     1   1
1   1 11111 11111 11111  111        1   1  111  1 1   11111 1111

1111  1   1 11111 1   1  111  1   1       1111   111   111  1   1  111
1   1  1 1    1   1   1 1   1 11  1       1   1 1   1 1   1 1  1  1
1111    1     1   11111 1   1 1 1 1       1111  1   1 1     111    111
1       1     1   1   1 1   1 1  11       11    1   1 1   1 1 1       1
1       1     1   1   1  111  1   1       1 1    111   111  1  1   111


答:
Pyth, 39 bytes

Back to golfing !

There is the program :

<s>```<code>=Qm:d"[\W_]"kQKYLmsd.glkolNb;WnKQ=KQ=yQ;jQ
</code>```</s>

```<code>=Qm:d"[\W_]"kQLmsd.glkolNb;WnYQ=YQ=yQ;j
</code>```

Test it here !

Explanations

```<code>=Qm:d"[\W_]"kQLmsd.glkolNb;WnYQ=YQ=yQ;j       (Implicit) Assign evaluated imput to Q (In this case, an array)
=Q                                            Reassign a value to Q
  m          Q                                map a function over Q
   :d"[\W_]"k                                 Replace any special character with an empty string
              L           ;                   Declare a function y(b)
                      olNb                      Sort b by length
                  .glk                          Group strings of same length in arrays
               msd                              Concat each inner array
                           WnYQ      ;        While Y != Q (previous array is not equal to current array)
                               =YQ              Assign the current array to Y (Y=Q)
                                  =yQ           Assign y(Q) to Q (Q=yQ). Here, the assigned variable name is implicit
                                      j       Display the resulting array
</code>```

Title: Let's build a Staircase

Body:
Pyth, 39 bytes

Back to golfing !

There is the program :

<s>
=Qm:d"[\W_]"kQKYLmsd.glkolNb;WnKQ=KQ=yQ;jQ

</s>

=Qm:d"[\W_]"kQLmsd.glkolNb;WnYQ=YQ=yQ;j

Test it here !

Explanations

=Qm:d"[\W_]"kQLmsd.glkolNb;WnYQ=YQ=yQ;j       (Implicit) Assign evaluated imput to Q (In this case, an array)
=Q                                            Reassign a value to Q
  m          Q                                map a function over Q
   :d"[\W_]"k                                 Replace any special character with an empty string
              L           ;                   Declare a function y(b)
                      olNb                      Sort b by length
                  .glk                          Group strings of same length in arrays
               msd                              Concat each inner array
                           WnYQ      ;        While Y != Q (previous array is not equal to current array)
                               =YQ              Assign the current array to Y (Y=Q)
                                  =yQ           Assign y(Q) to Q (Q=yQ). Here, the assigned variable name is implicit
                                      j       Display the resulting array


问:
Separate alphabets and numbers
A paragraph of text has numbers and alphabetic letters mixed. Your task is to separate the numbers to the left side and the alphabetic letters to the right side in the same order of each line.

Rules:

Numbers are plain integers; so no decimal point, and no negative/positive signs.

Numbers may or may not be contiguous, but whatever the case may be, they have to be pushed to left side in the same order.

Numbers may occur in between words.

The text contains only ASCII alphabetic letters and numbers, along with spaces, underscores, commas and dots.

The one who does this with minimum keystrokes (like vim macros) or least amount of bytes in case of scripting is the winner.

Example Text:

```<code>A word can have any number of text like 433884,
but all the numb89ers has to be moved left side
but alph6abetical va9lues has to be pas46ted on right side.
The text might con4tain chara29cters s2huffled like hlep or dfeintino or even
meaningless1 words co43mbined togeth81er.
</code>```

Expected output:

```<code>433884A word can have any number of text like ,
89but all the numbers has to be moved left side
6946but alphabetical values has to be pasted on right side.
4292The text might contain characters shuffled like hlep or dfeintino or even
14381meaningless words combined together.
</code>```

答:
Pyth, 14 bytes

```<code>FG.zo_:N"\d"0G
</code>```

Try it online!

Explanation:

```<code>FG             : For every G in ...
  .z           : the-list-where-lines-of-input-are-stored ...
               : (implicitly print)
    o        G : sorted G ...
     _N        : where, a negative key is given ...
       :"\d"0  : to the individual character if it is a digit
</code>```

The logic of the solution is the same as in Lynn's answer.

Title: Separate alphabets and numbers

Body:
Pyth, 14 bytes

FG.zo_:N"\d"0G

Try it online!

Explanation:

FG             : For every G in ...
  .z           : the-list-where-lines-of-input-are-stored ...
               : (implicitly print)
    o        G : sorted G ...
     _N        : where, a negative key is given ...
       :"\d"0  : to the individual character if it is a digit

The logic of the solution is the same as in Lynn's answer.


答:
Octave, 23 bytes

With no mod cons...

```<code>@(n)(-[-1:1]'*[1:n])(n)
</code>```

Uses 1-based indexing magic.

Explanation

Creates an anonymous function that will:

```<code>(-[-1:1]'*[1:n])(n)
  [-1:1]              % make a row vector [-1 0 1]
 -      '             % negate and take its transpose making a column vector
          [1:n]       % make a row vector [1..n], where n is the input
         *            % multiply with singleton expansion
               (n)    % use linear indexing to get the nth value
</code>```

After the multiplication step we'll have a 3xn matrix like so (for n=12):

```<code> 1    2    3    4    5    6    7    8    9   10   11   12
 0    0    0    0    0    0    0    0    0    0    0    0
-1   -2   -3   -4   -5   -6   -7   -8   -9  -10  -11  -12
</code>```

Making n columns is overkill, but it's a convenient number that is guaranteed to be large enough. Linear indexing counts down each column from left to right, so the element at linear index 4 would be 2.

All test cases on ideone.

Title: Alternating Sign Sequence

Body:
Octave, 23 bytes

With no mod cons...

@(n)(-[-1:1]'*[1:n])(n)

Uses 1-based indexing magic.

Explanation

Creates an anonymous function that will:

(-[-1:1]'*[1:n])(n)
  [-1:1]              % make a row vector [-1 0 1]
 -      '             % negate and take its transpose making a column vector
          [1:n]       % make a row vector [1..n], where n is the input
         *            % multiply with singleton expansion
               (n)    % use linear indexing to get the nth value

After the multiplication step we'll have a 3xn matrix like so (for n=12):

 1    2    3    4    5    6    7    8    9   10   11   12
 0    0    0    0    0    0    0    0    0    0    0    0
-1   -2   -3   -4   -5   -6   -7   -8   -9  -10  -11  -12

Making n columns is overkill, but it's a convenient number that is guaranteed to be large enough. Linear indexing counts down each column from left to right, so the element at linear index 4 would be 2.

All test cases on ideone.


问:
Tips for Golfing in ECMAScript 6 and above
This is similar to other "Tips for golfing in <...>" but specifically targeting the newer features in JavaScript brought up in ECMAScript 6 and above.

JavaScript inherently is a very verbose language, function(){}, .forEach(), converting string to array, array-like object to array, etc, etc are super bloats and not healthy for Golfing.

ES6+, on the other hand, has some super handy features and reduced footprint. x=>y, [...x], etc. are just some of the examples.

Please post some nice tricks that can help shave off those few extra bytes from your code.

NOTE: Tricks for ES5 are already available in Tips for golfing in JavaScript; answers to this thread should focus on tricks only available in ES6 and other future ES versions.

However, this thread is also for users who currently golf using ES5 features. Answers may also contain tips to help them understand and map ES6 features to their style of ES5 coding.

答:
Use eval instead of braces for arrow functions

Arrow functions are awesome. They take the form x=>y, where x is an argument and y is the return value. However, if you need to use a control structure, such as while, you would have to put braces, e.g. =>{while(){};return}. However, we can get around this; luckily, the eval function takes a string, evaluates that string as JS code, and returns the last evaluated expression. For example, compare these two:

x=>{while(foo){bar};return baz} // before
x=>eval('while(foo){bar};baz')  // after
//                            ^
```

<p>We can use an extension of this concept to further shorten our code: in the eyes of <code>eval</code>, control structures also return their last evaluated expression. For example:</p>

<pre class="lang-js prettyprint-override"><code>x=>{while(foo)bar++;return bar} // before
x=>eval('while(foo)++bar')      // after
//                        ^^^^^
</code>```

Body:
Use eval instead of braces for arrow functions

Arrow functions are awesome. They take the form x=>y, where x is an argument and y is the return value. However, if you need to use a control structure, such as while, you would have to put braces, e.g. =>{while(){};return}. However, we can get around this; luckily, the eval function takes a string, evaluates that string as JS code, and returns the last evaluated expression. For example, compare these two:

x=>{while(foo){bar};return baz} // before
x=>eval('while(foo){bar};baz')  // after
//                            ^

We can use an extension of this concept to further shorten our code: in the eyes of eval, control structures also return their last evaluated expression. For example:

x=>{while(foo)bar++;return bar} // before
x=>eval('while(foo)++bar')      // after
//                        ^^^^^