答:
Turtlèd, 40 bytes

Interpreter is <s>slightly</s> no longer buggèd

```<code>?;,u[*'|u]'|?@-[*:l'|l[|,l]d@ ],ur[|'-r]
</code>```

Explanation

```<code>?                            - input integer into register
 ;                           - move down by the contents of register
  ,                          - write the char variable, default *
   u                         - move up
    [*   ]                   - while current cell is not *
      '|                     - write |
        u                    - move up
          '|                 - write | again
            ?                - input other integer into register
             @-              - set char variable to -
               [*             ] - while current char is not *
                 :l'|l          - move right by amount in register, move left, write |, move left again
                      [|,l]     - while current cell is not |, write char variable, move left
                           d@   - move down, set char variable to space (this means all but first iteration of loop writes space)
                               ,ur   -write char variable, move up, right
                                  [|   ] -while current char is not |
                                    '-r - write -, move right
</code>```

Title: Draw an ASCII Rectangle

Body:
Given two integers as input in an array, draw a rectangle, using the first integer as width and second as height.

Or, if your language supports it, the two integers can be given as separate inputs.

Assume the width and height will never be less than 3, and they will always be given.

Example Outputs:

[3, 3]

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

[5, 8]

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

[10, 3]

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

This is code-golf, so the answer with the lowest amount of bytes wins.

Body:
Turtlèd, 40 bytes

Interpreter is <s>slightly</s> no longer buggèd

?;,u[*'|u]'|?@-[*:l'|l[|,l]d@ ],ur[|'-r]

Explanation

?                            - input integer into register
 ;                           - move down by the contents of register
  ,                          - write the char variable, default *
   u                         - move up
    [*   ]                   - while current cell is not *
      '|                     - write |
        u                    - move up
          '|                 - write | again
            ?                - input other integer into register
             @-              - set char variable to -
               [*             ] - while current char is not *
                 :l'|l          - move right by amount in register, move left, write |, move left again
                      [|,l]     - while current cell is not |, write char variable, move left
                           d@   - move down, set char variable to space (this means all but first iteration of loop writes space)
                               ,ur   -write char variable, move up, right
                                  [|   ] -while current char is not |
                                    '-r - write -, move right


问:
Compute the Carmichael function

Task description

In number theory, the Carmichael function λ takes a positive integer n and returns the least positive integer k so that the k-th power of each integer coprime to n equals 1 modulo n.

Given a positive integer n, your solution must compute λ(n). The shortest code in bytes wins.

Your program should theoretically work for arbitrarily large inputs, but doesn’t need to be efficient.

Tips

The sequence of all λ(n) is OEIS A002322.

An ungolfed Python implementation would look like

```<code>from fractions import gcd

def carmichael(n):
    coprimes = [x for x in range(1, n) if gcd(x, n) == 1]
    k = 1
    while not all(pow(x, k, n) == 1 for x in coprimes):
        k += 1
    return k
</code>```

(In Python, pow(A, B, C) efficiently computes pow(A, B) % C.)

Test cases

```<code>Input    Output
1        1
2        1
3        2
10       4
35       12
101      100
530      52
3010     84
6511     3056
10000    500
</code>```

答:
Python, <s>76</s> <s>73</s> 67 bytes

f=lambda n,k=1:1-any(a**-~k*~-a**k%n for a in range(n))or-~f(n,k+1)
```
<p>Try it online!</p>
<p>A further byte could be saved by returning <em>True</em> instead of <strong>1</strong>.</p>
<h3>Alternative implementation</h3>
<p>Using the same approach, there is also the following implementation by @feersum which doesn't use list comprehensions.</p>
<pre class="lang-python prettyprint-override"><code>f=lambda n,k=1,a=1:a/n or(a**-~k*~-a**k%n<1)*f(n,k,a+1)or-~f(n,k+1)
</code>```

Note that this implementation requires O(nλ(n)) time. Efficiency could be improved dramatically while actually decreasing score to 66 bytes, but the function would return True for input 2.

f=lambda n,k=1,a=1:a/n or~-a**k*a**-~k%n<1==f(n,k,a+1)or-~f(n,k+1)
```

Background

Definitions and notation

All employed variables will denote integers; n, k, and α will denote positive integers; and p will denote a positive prime.

a | b if b is divisible by a, i.e., if there is q such that b = qa.

a ≡ b (mod m) if a and b have the same residue modulo m, i.e., if m | a - b.

λ(n) is the smallest k such that ak ≡ 1 (mod n) – i.e., such that n | ak - 1 – for all a that are coprime to n.

f(n) is the smallest k such that a2k+1 ≡ ak+1 (mod n) – i.e., such that n | ak+1(ak - 1) – for all a.

λ(n) ≤ f(n)

Fix n and let a be coprime to n.

By the definition of f, n | af(n)+1(af(n) - 1). Since a and n do not have a common prime factor, neither do af(n)+1 and n, which implies that n | af(n) - 1.

Since λ(n) is the smallest integer k such that n | ak - 1 for all integers a that are coprime to n, it follows that λ(n) ≤ f(n).

λ(n) = f(n)

Since we've already established the inequality λ(n) ≤ f(n), it is sufficient to verify that k = λ(n) satisfies the condition that defines f, i.e., that n | aλ(n)+1(aλ(n) - 1) for all a. For this purpose, we'll establish that pα | aλ(n)+1(aλ(n) - 1) whenever pα | n.

λ(k) | λ(n) whenever k | n (source), so (aλ(k) - 1)(aλ(n)-λ(k) + aλ(n)-2λ(k) + ⋯ + aλ(k) + 1) = aλ(n) - 1 and, therefore, aλ(k) - 1 | aλ(n) - 1 | aλ(n)+1(aλ(n) - 1).

If a and pα are coprime, by the definition of λ and the above, pα | aλ(pα) - 1 | aλ(n)+1(aλ(n) - 1) follows, as desired.

If a = 0, then aλ(n)+1(aλ(n) - 1) = 0, which is divisible by all integers.

Finally, we must consider the case where a and pα have a common prime factor. Since p is prime, this implies that p | a. Carmichael's theorem establishes that λ(pα) = (p - 1)pα - 1 if p > 2 or α < 3 and that λ(pα) = pα - 2 otherwise. In all cases, λ(pα) ≥ pα - 2 ≥ 2α - 2 > α - 2.

Therefore, λ(n) + 1 ≥ λ(pα) + 1 > α - 1, so λ(n) + 1 ≥ α and pα | pλ(n)+1 | aλ(n)+1 | aλ(n)+1(aλ(n) - 1). This completes the proof.

How it works

While the definitions of f(n) and λ(n) consider all possible values of a, it is sufficient to test those that lie in [0, ..., n - 1].

When f(n, k) is called, it computes ak+1(ak - 1) % n for all values of a in that range, which is 0 if and only if n | ak+1(ak - 1).

If all computed residues are zero, k = λ(n) and any returns False, so f(n, k) returns 1.

On the other hand, while k < λ(n), 1-any(...) will return 0, so f is called recursively with an incremented value of k. The leading -~ increments the return value of f(n, k + 1), so we add 1 to f(n, λ(n)) = 1 once for every integer in [1, ..., λ(n) - 1]. The final result is thus λ(n).

ContentLicense: CC BY-SA 3.0

Title: Compute the Carmichael function

Body:
Python, <s>76</s> <s>73</s> 67 bytes

f=lambda n,k=1:1-any(a**-~k*~-a**k%n for a in range(n))or-~f(n,k+1)

Try it online!

A further byte could be saved by returning True instead of 1.

Alternative implementation

Using the same approach, there is also the following implementation by @feersum which doesn't use list comprehensions.

f=lambda n,k=1,a=1:a/n or(a**-~k*~-a**k%n<1)*f(n,k,a+1)or-~f(n,k+1)

Note that this implementation requires O(nλ(n)) time. Efficiency could be improved dramatically while actually decreasing score to 66 bytes, but the function would return True for input 2.

f=lambda n,k=1,a=1:a/n or~-a**k*a**-~k%n<1==f(n,k,a+1)or-~f(n,k+1)

Background

Definitions and notation

All employed variables will denote integers; n, k, and α will denote positive integers; and p will denote a positive prime.

a | b if b is divisible by a, i.e., if there is q such that b = qa.

a ≡ b (mod m) if a and b have the same residue modulo m, i.e., if m | a - b.

λ(n) is the smallest k such that ak ≡ 1 (mod n) – i.e., such that n | ak - 1 – for all a that are coprime to n.

f(n) is the smallest k such that a2k+1 ≡ ak+1 (mod n) – i.e., such that n | ak+1(ak - 1) – for all a.

λ(n) ≤ f(n)

Fix n and let a be coprime to n.

By the definition of f, n | af(n)+1(af(n) - 1). Since a and n do not have a common prime factor, neither do af(n)+1 and n, which implies that n | af(n) - 1.

Since λ(n) is the smallest integer k such that n | ak - 1 for all integers a that are coprime to n, it follows that λ(n) ≤ f(n).

λ(n) = f(n)

Since we've already established the inequality λ(n) ≤ f(n), it is sufficient to verify that k = λ(n) satisfies the condition that defines f, i.e., that n | aλ(n)+1(aλ(n) - 1) for all a. For this purpose, we'll establish that pα | aλ(n)+1(aλ(n) - 1) whenever pα | n.

λ(k) | λ(n) whenever k | n (source), so (aλ(k) - 1)(aλ(n)-λ(k) + aλ(n)-2λ(k) + ⋯ + aλ(k) + 1) = aλ(n) - 1 and, therefore, aλ(k) - 1 | aλ(n) - 1 | aλ(n)+1(aλ(n) - 1).

If a and pα are coprime, by the definition of λ and the above, pα | aλ(pα) - 1 | aλ(n)+1(aλ(n) - 1) follows, as desired.

If a = 0, then aλ(n)+1(aλ(n) - 1) = 0, which is divisible by all integers.

Finally, we must consider the case where a and pα have a common prime factor. Since p is prime, this implies that p | a. Carmichael's theorem establishes that λ(pα) = (p - 1)pα - 1 if p > 2 or α < 3 and that λ(pα) = pα - 2 otherwise. In all cases, λ(pα) ≥ pα - 2 ≥ 2α - 2 > α - 2.

Therefore, λ(n) + 1 ≥ λ(pα) + 1 > α - 1, so λ(n) + 1 ≥ α and pα | pλ(n)+1 | aλ(n)+1 | aλ(n)+1(aλ(n) - 1). This completes the proof.

How it works

While the definitions of f(n) and λ(n) consider all possible values of a, it is sufficient to test those that lie in [0, ..., n - 1].

When f(n, k) is called, it computes ak+1(ak - 1) % n for all values of a in that range, which is 0 if and only if n | ak+1(ak - 1).

If all computed residues are zero, k = λ(n) and any returns False, so f(n, k) returns 1.

On the other hand, while k < λ(n), 1-any(...) will return 0, so f is called recursively with an incremented value of k. The leading -~ increments the return value of f(n, k + 1), so we add 1 to f(n, λ(n)) = 1 once for every integer in [1, ..., λ(n) - 1]. The final result is thus λ(n).


问:
Minecraft castle fractal
Inpsired by a youtube video from a fellow PPCG user...

You challenge is to use ASCII-art draw a Minecraft castle wall of Andesite and Diorite. The shape of the wall is the Cantor Set. For reference, the Cantor Set is made by repeating the following N times:

Triple the current step

Replace the middle one with blank space

Add a full line below it

This creates the following for the first four steps:

```<code>*

* *
***

* *   * *
***   ***
*********

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

However, your challenge is not quite that simple. You see, after the cantor set gets really big, it becomes boring to look at the same character repeated over and over and over. So we're going to change that by overlaying an alternating series of asterisks * and pound signs #. You should alternate on every three characters horizontally, and on every row vertically. (Of course leaving the spaces the same) For example, the second example will become:

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

and the third example will become:

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

For completeness, here are examples four and five:

```<code>#4
* *   * *         * *   * *
###   ###         ###   ###
***###***         ***###***
###***###***###***###***###

#5
* *   * *         * *   * *                           * *   * *         * *   * *
###   ###         ###   ###                           ###   ###         ###   ###
***###***         ***###***                           ***###***         ***###***
###***###***###***###***###                           ###***###***###***###***###
***###***###***###***###***###***###***###***###***###***###***###***###***###***
</code>```

And one mega example, the 6th iteration:

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

The challenge

You must write a full program or function that accepts a positive integer for input, and outputs the N'th generation of this minecraft castle fractal. You can take Input and output by any reasonable method, and you do not have to worry about invalid inputs (such as numbers less than 1, floating point numbers, non-numbers, etc.).

The shortest answer, measured in bytes wins!

答:
J, <s>47</s> 45 bytes

```<code>' *#'{~3(]*$@]$1 2#~[)(,:1)1&(,~],.0&*,.])~<:
</code>```

Based on my solution to the Cantor set challenge.

Usage

```<code>   f =: ' *#'{~3(]*$@]$1 2#~[)(,:1)1&(,~],.0&*,.])~<:
   f 1
*
   f 2
* *
###
   f 3
* *   * *
###   ###
***###***
</code>```

Explanation

```<code>' *#'{~3(]*$@]$1 2#~[)(,:1)1&(,~],.0&*,.])~<:  Input: n
                                           <:  Decrement n
                      (,:1)                    A constant [1]
                           1&(           )~    Repeating n-1 times on x starting
                                               with x = [1]
                                        ]        Identity function, gets x
                                   0&*           Multiply x elementwise by 0
                                      ,.         Join them together by rows
                                ]                Get x
                                 ,.              Join by rows
                           1  ,~                 Append a row of 1's and return
       3                                       The constant 3
        (                 )                    Operate on 3 and the result
                    [                          Get LHS = 3
               1 2                             The constant [1, 2]
                  #~                           Duplicate each 3 times
                                               Forms [1, 1, 1, 2, 2, 2]
           $@]                                 Get the shape of the result
              $                                Shape the list of [1, 2] to
                                               the shape of the result
         ]                                     Get the result
          *                                    Multiply elementwise between the
                                               result and the reshaped [1, 2]
' *#'                                        The constant string ' *#'
     {~                                       Select from it using the result
                                             as indices and return
</code>```

Title: Minecraft castle fractal

Body:
J, <s>47</s> 45 bytes

' *#'{~3(]*$@]$1 2#~[)(,:1)1&(,~],.0&*,.])~<:

Based on my solution to the Cantor set challenge.

Usage

   f =: ' *#'{~3(]*$@]$1 2#~[)(,:1)1&(,~],.0&*,.])~<:
   f 1
*
   f 2
* *
###
   f 3
* *   * *
###   ###
***###***

Explanation

' *#'{~3(]*$@]$1 2#~[)(,:1)1&(,~],.0&*,.])~<:  Input: n
                                           <:  Decrement n
                      (,:1)                    A constant [1]
                           1&(           )~    Repeating n-1 times on x starting
                                               with x = [1]
                                        ]        Identity function, gets x
                                   0&*           Multiply x elementwise by 0
                                      ,.         Join them together by rows
                                ]                Get x
                                 ,.              Join by rows
                           1  ,~                 Append a row of 1's and return
       3                                       The constant 3
        (                 )                    Operate on 3 and the result
                    [                          Get LHS = 3
               1 2                             The constant [1, 2]
                  #~                           Duplicate each 3 times
                                               Forms [1, 1, 1, 2, 2, 2]
           $@]                                 Get the shape of the result
              $                                Shape the list of [1, 2] to
                                               the shape of the result
         ]                                     Get the result
          *                                    Multiply elementwise between the
                                               result and the reshaped [1, 2]
' *#'                                        The constant string ' *#'
     {~                                       Select from it using the result
                                             as indices and return


问:
Draw an ASCII Rectangle
Given two integers as input in an array, draw a rectangle, using the first integer as width and second as height.

Or, if your language supports it, the two integers can be given as separate inputs.

Assume the width and height will never be less than 3, and they will always be given.

Example Outputs:

[3, 3]

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

[5, 8]

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

[10, 3]

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

This is code-golf, so the answer with the lowest amount of bytes wins.

Title: Draw an ASCII Rectangle

Body:
Python 3, 74 chars

p="|"
def r(w,h):m=w-2;b=p+"-"*m+p;return b+"\n"+(p+m*" "+p+"\n")*(h-2)+b


答:
Actually, 35 bytes

```<code>¬'|@α(¬;)' *╗`╜o'|o`Mi('-*"|%s|"%;)
</code>```

Try it online!

Explanation:

```<code>¬'|@α(¬;)' *╗`╜o'|o`Mi('-*"|%s|"%;)
¬                                    height - 2
 '|@α                                ["|" for _ in range(height-2)]
     (¬;)                            width - 2, duplicate, move to bottom of stack
         ' *                         " "*(width-2)
            ╗                        save to register 0
             `╜o'|o`M                for each "|" in list of "|"s:
              ╜o                       append (width-2) spaces
                '|o                    append a second "|"
                     i               flatten list
                      (              bring copy of (width-2) back to top
                       '-*           "-"*(width-2)
                          "|%s|"%    surround with "|"s
                                 ;)  dupe, move copy to bottom of stack
                                     (implicitly print stack contents, one element per line)
</code>```

Title: Draw an ASCII Rectangle

Body:
Actually, 35 bytes

¬'|@α(¬;)' *╗`╜o'|o`Mi('-*"|%s|"%;)

Try it online!

Explanation:

¬'|@α(¬;)' *╗`╜o'|o`Mi('-*"|%s|"%;)
¬                                    height - 2
 '|@α                                ["|" for _ in range(height-2)]
     (¬;)                            width - 2, duplicate, move to bottom of stack
         ' *                         " "*(width-2)
            ╗                        save to register 0
             `╜o'|o`M                for each "|" in list of "|"s:
              ╜o                       append (width-2) spaces
                '|o                    append a second "|"
                     i               flatten list
                      (              bring copy of (width-2) back to top
                       '-*           "-"*(width-2)
                          "|%s|"%    surround with "|"s
                                 ;)  dupe, move copy to bottom of stack
                                     (implicitly print stack contents, one element per line)


答:
Lua, 120 93 bytes

Saved quite a few bytes by removing stupid over complexities.

```<code>function(w,h)function g(s)return'|'..s:rep(w-2)..'|\n'end b=g'-'print(b..g' ':rep(h-2)..b)end
</code>```

Ungolfed:

```<code>function(w,h)                           -- Define Anonymous Function
    function g(s)                       -- Define 'Row Creation' function. We use this twice, so it's less bytes to function it.
        return'|'..s:rep(w-2)..'|\n'    -- Sides, Surrounding the chosen filler character (' ' or '-'), followed by a newline
    end
    b=g'-'                              -- Assign the top and bottom rows to the g of '-', which gives '|---------|', or similar.
    print(b..g' ':rep(h-2)..b)          -- top, g of ' ', repeated height - 2 times, bottom. Print.
end
</code>```

Try it on Repl.it

Title: Draw an ASCII Rectangle

Body:
Lua, 120 93 bytes

Saved quite a few bytes by removing stupid over complexities.

function(w,h)function g(s)return'|'..s:rep(w-2)..'|\n'end b=g'-'print(b..g' ':rep(h-2)..b)end

Ungolfed:

function(w,h)                           -- Define Anonymous Function
    function g(s)                       -- Define 'Row Creation' function. We use this twice, so it's less bytes to function it.
        return'|'..s:rep(w-2)..'|\n'    -- Sides, Surrounding the chosen filler character (' ' or '-'), followed by a newline
    end
    b=g'-'                              -- Assign the top and bottom rows to the g of '-', which gives '|---------|', or similar.
    print(b..g' ':rep(h-2)..b)          -- top, g of ' ', repeated height - 2 times, bottom. Print.
end

Try it on Repl.it


答:
Python (70 bytes)

```<code>def r(w,h): print '\n'.join(['|'+('-' if i%(h-1)==0 else ' ')*(w-2)+'|' for i in range(h)])
</code>```

Edit: lambda function for a few less bytes (thanks @DJMcMayhem)

```<code>r=lambda w,h:'\n'.join(['|'+('-'if i%(h-1)==0 else' ')*(w-2)+'|'for i in range(h)])
</code>```

Edit#2: if notation is greedy

```<code>r=lambda w,h:'\n'.join(['|'+(0<i<h-1 and' 'or'-')*(w-2)+'|'for i in range(h)])
</code>```

Edit#3: -8 bytes with list trick

```<code>r=lambda w,h:'\n'.join(['|'+'- '[0<i<h-1]*(w-2)+'|'for i in range(h)])
</code>```

Title: Draw an ASCII Rectangle

Body:
Python (70 bytes)

def r(w,h): print '\n'.join(['|'+('-' if i%(h-1)==0 else ' ')*(w-2)+'|' for i in range(h)])

Edit: lambda function for a few less bytes (thanks @DJMcMayhem)

r=lambda w,h:'\n'.join(['|'+('-'if i%(h-1)==0 else' ')*(w-2)+'|'for i in range(h)])

Edit#2: if notation is greedy

r=lambda w,h:'\n'.join(['|'+(0<i<h-1 and' 'or'-')*(w-2)+'|'for i in range(h)])

Edit#3: -8 bytes with list trick

r=lambda w,h:'\n'.join(['|'+'- '[0<i<h-1]*(w-2)+'|'for i in range(h)])


问:
Invert a boolean array
A nice simple one

Input

Given a boolean array (Or an acceptable alternative), you can assume the array will never be more than 32 elements long.

```<code>[false, false, true, false, false]
</code>```

Output

Invert every element of the array and output it.

```<code>[true, true, false, true, true]
</code>```

Rules

You can write a full program or just a function

Standard loopholes apply

Shortest code in bytes, per language, wins!

Test cases

```<code>Input:
[true, false]
Output:
[false, true]

Input: //Example of acceptable alternative
[0,1,1]
Output:
[1,0,0]
</code>```

答:
Racket 11 bytes

```<code>(map not l)
</code>```

Testing:

```<code>(define l '(#t #f #t)) ; define a list of booleans

(map not l)
</code>```

Output:

```<code>'(#f #t #f)
</code>```

Title: Invert a boolean array

Body:
Racket 11 bytes

(map not l)

Testing:

(define l '(#t #f #t)) ; define a list of booleans

(map not l)

Output:

'(#f #t #f)


答:
Actually, <s>30</s> <s>28</s> <s>25</s> <s>19</s> 26 bytes

The Carmichael function, λ(n) where n = p_0**k_0 * p_1**k_1 * ... * p_a**k_a, is defined as the least common multiple (LCM) of λ(p_i**k_i) for the maximal prime powers p_i**k_i that divide into n. Given that for every prime power except where the prime is 2, the Carmichael function is equivalent to the Euler totient function, λ(n) == φ(n), we use φ(n) instead. For the special case of 2**k where k ≥ 3, we just check if 2**3 = 8 divides into n at the beginning of the program, and divide by 2 if it does.

Unfortunately, Actually doesn't currently have an LCM builtin, so I made a brute-force LCM. Golfing suggestions welcome. Try it online!

```<code>;7&Yu@\w`iⁿ▒`M╗2`╜@♀%ΣY`╓N
</code>```

Ungolfing

```<code>         Implicit input n.
;        Duplicate n.
7&       n&7 == n%8.
Yu       Logical NOT and increment. If n%8 == 0, return 2. Else, return 1.
@\       Integer divide n by 2 if n%8==0, by 1 otherwise.
          Thus, we have dealt with the special case where p_i == 2 and e_i >= 3.
w        Full prime factorization of n as a list of [prime, exponent] lists.
`...`M   Map the following function over the prime factorization.
  i        Flatten the array, pushing exponent, then prime to the stack.
  ⁿ▒       totient(pow(prime, exponent)).
╗        Save that list of totients in register 0.
2`...`╓  Get the first two values of n where the following function f(n) is truthy.
         Those two numbers will be 0 and our LCM.
  ╜@       Push the list in register 0 and swap with our n.
  ♀%       Get n mod (every number in the list)
  Σ        Sum the modulos. This sum will be 0, if and only if this number is 0 or LCM.
  Y        Logical NOT, so that we only get a truthy if the sum of modulos is 0.
N        Grab the second number, our LCM. Implicit return.
</code>```

Title: Compute the Carmichael function

Body:
Task description

In number theory, the Carmichael function λ takes a positive integer n and returns the least positive integer k so that the k-th power of each integer coprime to n equals 1 modulo n.

Given a positive integer n, your solution must compute λ(n). The shortest code in bytes wins.

Your program should theoretically work for arbitrarily large inputs, but doesn’t need to be efficient.

Tips

The sequence of all λ(n) is OEIS A002322.

An ungolfed Python implementation would look like

```<code>from fractions import gcd

def carmichael(n):
    coprimes = [x for x in range(1, n) if gcd(x, n) == 1]
    k = 1
    while not all(pow(x, k, n) == 1 for x in coprimes):
        k += 1
    return k
</code>```

(In Python, pow(A, B, C) efficiently computes pow(A, B) % C.)

Test cases

```<code>Input    Output
1        1
2        1
3        2
10       4
35       12
101      100
530      52
3010     84
6511     3056
10000    500
</code>```

Body:
Actually, <s>30</s> <s>28</s> <s>25</s> <s>19</s> 26 bytes

The Carmichael function, λ(n) where n = p_0**k_0 * p_1**k_1 * ... * p_a**k_a, is defined as the least common multiple (LCM) of λ(p_i**k_i) for the maximal prime powers p_i**k_i that divide into n. Given that for every prime power except where the prime is 2, the Carmichael function is equivalent to the Euler totient function, λ(n) == φ(n), we use φ(n) instead. For the special case of 2**k where k ≥ 3, we just check if 2**3 = 8 divides into n at the beginning of the program, and divide by 2 if it does.

Unfortunately, Actually doesn't currently have an LCM builtin, so I made a brute-force LCM. Golfing suggestions welcome. Try it online!

;7&Yu@\w`iⁿ▒`M╗2`╜@♀%ΣY`╓N

Ungolfing

         Implicit input n.
;        Duplicate n.
7&       n&7 == n%8.
Yu       Logical NOT and increment. If n%8 == 0, return 2. Else, return 1.
@\       Integer divide n by 2 if n%8==0, by 1 otherwise.
          Thus, we have dealt with the special case where p_i == 2 and e_i >= 3.
w        Full prime factorization of n as a list of [prime, exponent] lists.
`...`M   Map the following function over the prime factorization.
  i        Flatten the array, pushing exponent, then prime to the stack.
  ⁿ▒       totient(pow(prime, exponent)).
╗        Save that list of totients in register 0.
2`...`╓  Get the first two values of n where the following function f(n) is truthy.
         Those two numbers will be 0 and our LCM.
  ╜@       Push the list in register 0 and swap with our n.
  ♀%       Get n mod (every number in the list)
  Σ        Sum the modulos. This sum will be 0, if and only if this number is 0 or LCM.
  Y        Logical NOT, so that we only get a truthy if the sum of modulos is 0.
N        Grab the second number, our LCM. Implicit return.


问:
Shortest program that throws StackOverflow Error
Write a program that throws a StackOverflow Error or the equivalent in the language used. For example, in java, the program should throw java.lang.StackOverflowError.

You are not allowed to define a function that calls itself or a new class(except the one containing main in java). It should use the classes of the selected programming language.

And it should not throw the error explicitly.

答:
X86 assembly (AT&T), 33 characters

Note that although I'm using the label main as a jump target, this is not a recursive function.

```<code>.globl main
main:push $0;jmp main
</code>```

Body:
X86 assembly (AT&T), 33 characters

Note that although I'm using the label main as a jump target, this is not a recursive function.

.globl main
main:push $0;jmp main


问:
Bake a slice of Pi
Write a program or function that prints or outputs this exact text (consisting of 142 characters):

```<code>()()()()()()
|\3.1415926|
|:\53589793|
\::\2384626|
 \::\433832|
  \::\79502|
   \::\8841|
    \::\971|
     \::\69|
      \::\3|
       \__\|
</code>```

Your program must take no input (except in languages where this is impossible, such as sed), and produce the above text (and only the above text) as output. A trailing newline is acceptable.

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

Title: Bake a slice of Pi

Body:
Java 7, <s>260</s> <s>236</s> 191 bytes

String d(){return"()()()()()()\n|\\3.1415926|\n|:\\53589793|\n\\::\\2384626|\n \\::\\433832|\n  \\::\\79502|\n   \\::\\8841|\n    \\::\\971|\n     \\::\\69|\n      \\::\\3|\n       \\__\\|";}

Sigh, simply outputting the pie is shorter, even with all the escaped backslashes.. >.>

Here is previous answer with a tiny bit of afford, although still not very generic or fancy (236 bytes):

String c(){String n="\n",p="|",q=p+n,x="\\::\\",s=" ",z=s;return"()()()()()()"+n+p+"\\"+3.1415926+q+p+":\\53589793"+q+x+2384626+q+s+x+433832+q+(z+=s)+x+79502+q+(z+=s)+x+8841+q+(z+=s)+x+971+q+(z+=s)+x+69+q+(z+=s)+x+3+q+(z+=s)+"\\__\\|";}

A pretty boring answer, since simply outputting the result without too much fancy things is shorter in Java than a generic approach.

Ungolfed & test code:

Try it here.

class M{
  static String c(){
    String n = "\n",
           p = "|",
           q = p + n,
           x = "\\::\\",
           s = " ",
           z = s;
    return "()()()()()()" + n + p + "\\" + 3.1415926 + q + p + ":\\53589793" + q + x + 2384626 + q + s
            + x + 433832 + q + (z += s) + x + 79502 + q + (z += s) + x + 8841 + q
            + (z += s) + x + 971 + q + (z += s) + x + 69 + q + (z += s) + x + 3 + q
            + (z += s) + "\\__\\|";
  }

  public static void main(String[] a){
    System.out.println(c());
  }
}

Output:

()()()()()()
|\3.1415926|
|:\53589793|
\::\2384626|
 \::\433832|
  \::\79502|
   \::\8841|
    \::\971|
     \::\69|
      \::\3|
       \__\|


问:
Periodic Arrays

Challenge

The challenge is to write a function that prints the number of repeats a given array of integers has.

What are repeats?

Repeats of a slice (as in a section of an array) [ a1, a2, a3, ..., an] are any other non-overlapping slices of the forms [ a1+an, a2+an, a3+an, ..., an+an], [ a1+2an, a2+2an, a3+2an, ..., an+2an], and so on. Incomplete repeats, e.g. [ a1+3an, a2+3an], are not counted.

Input and output

Inputs should be ordered collections of integers, e.g. arrays, lists, tuples, etc. The integers will be sorted and unique.

Output a single integer that is the number of repeats that covers the whole input. The output should correspond to the greatest possible number of repeats. E.g. certain inputs could be modeled to have 3 repeats of a 4-element slice, or 6 repeats of a 2-element slice; 6 should be the output because it is greater than 3.

Examples

```<code>Input -> Output

[ 1,  3,  5,
  6,  8, 10,
 11, 13, 15,
 16, 18, 20]
-> 4

[ 3,  5, 7, 10,
 13, 15]
-> 1

[1,
 2,
 3]
-> 3

[1,2,4]
-> 1

[ 3, 5, 7, 9,
 12,14,16,18]
-> 2
</code>```

This is a code-golf challenge, so the shortest code possible wins

If you have any questions related to the challenge feel free to ask.

I know that my attempts to explain something can be difficult to understand sometimes.

答:
Perl, <s>48</s> 47 bytes

Includes +3 for -p

Give input as a list of numbers on STDIN

```<code>repeats.pl <<< "3 5 7 9 12 14 16 18"
</code>```

repeats.pl:

```<code>#!/usr/bin/perl -p
s//0 /;s/\d+/$'-$&/eg;/(.+?)\1*-/;$_=s/$1//g
</code>```

Does not work if the input is a single 0 (not clear if that is a valid input). Fixing that takes 2 more bytes:

```<code>#!/usr/bin/perl -p
$_=s//0 /%s/\d+/$'-$&/eg-/^(.+?)\1*-/||s/$1//g
</code>```

Explanation

Adds a 0 in front of the sequence and then constructs a list of differences. The example input

```<code>3 5 7 9 12 14 16 18
</code>```

becomes:

```<code>3 2 2 2 3 2 2 2 -18
</code>```

The -18 is because the last difference is calculated relative to the end of the string which in perl will behave like 0. On this transformed list the problem is equivalent to finding the most often repeating substring before the - sign (this is why a single 0 as input does not work because only in that case there is no minus sign)

Title: Periodic Arrays

Body:
Perl, <s>48</s> 47 bytes

Includes +3 for -p

Give input as a list of numbers on STDIN

repeats.pl <<< "3 5 7 9 12 14 16 18"

repeats.pl:

#!/usr/bin/perl -p
s//0 /;s/\d+/$'-$&/eg;/(.+?)\1*-/;$_=s/$1//g

Does not work if the input is a single 0 (not clear if that is a valid input). Fixing that takes 2 more bytes:

#!/usr/bin/perl -p
$_=s//0 /%s/\d+/$'-$&/eg-/^(.+?)\1*-/||s/$1//g

Explanation

Adds a 0 in front of the sequence and then constructs a list of differences. The example input

3 5 7 9 12 14 16 18

becomes:

3 2 2 2 3 2 2 2 -18

The -18 is because the last difference is calculated relative to the end of the string which in perl will behave like 0. On this transformed list the problem is equivalent to finding the most often repeating substring before the - sign (this is why a single 0 as input does not work because only in that case there is no minus sign)


问:
Words -> City Skyline

The challenge

Your program or function will accept a single string input from STDIN or a function parameter. You can assume the input will contain only alphabetic characters (a-zA-Z), spaces, and full stops. Input is case insensitive, so you should treat 'a' exactly the same as you would treat 'A'.

For each character in the string, you will output a representation of a building as per the following specification.

Each building must have a roof, designated by an underscore on the top line then a slash, space, backslash on the second line.

```<code> _
/ \
</code>```

You will then have a number of floors, matching the letter number (a=1, b=2, c=3 etc.) which are represented by a wall (|) on each side and a space in the middle. The bottom floor (and only the bottom floor) should have a foundation, which is an underscore between the walls. Like this...

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

So for example, 'b' would look like this

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

Now, we know that very tall, narrow buildings cannot stand and must get wider at the base, so no building can stand more than three storeys high without some additional support. So every three levels (no less) you should add a 'widening layer'. The widening layer consists of a slash and backslash directly above the walls of the section below it, and the section below should be two spaces wider than the section above. The extra layer does not count towards the height of the building.

Buildings should not overlap but should not have any unnecessary spaces between them, and the ground is always flat so all buildings should have their base on the same level.

For example, 'abcdefga' will look like this.

```<code>                           _
                          / \
                     _    | |
                _   / \   | |
           _   / \  | |   | |
          / \  | |  | |  /   \
       _  | |  | |  | |  |   |
    _ / \ | |  | | /   \ |   |
 _ / \| | | | /   \|   | |   |  _
/ \| || |/   \|   ||   |/     \/ \
|_||_||_||___||___||___||_____||_|
</code>```

Spaces in the string input should be represented by a double space.

Full stops in the string input should be represented by rubble like this.

```<code>/\/\
</code>```

Further examples

Input = Hello world.

Output =

```<code>                                                   _
                                                  / \
                                                  | |
                                                  | |
                                                  | |
                                                 /   \
                                                 |   |
                                                 |   |                       _
                                                 |   |                      / \
                                                /     \                     | |
                                                |     |                     | |
                                   _            |     |          _          | |
                                  / \           |     |         / \        /   \
                                  | |          /       \        | |        |   |
                                  | |          |       |        | |        |   |
                _        _        | |          |       |        | |        |   |        _
               / \      / \      /   \         |       |       /   \      /     \      / \
               | |      | |      |   |        /         \      |   |      |     |      | |
               | |      | |      |   |        |         |      |   |      |     |      | |
               | |      | |      |   |        |         |      |   |      |     |      | |
   _          /   \    /   \    /     \       |         |     /     \    /       \    /   \
  / \         |   |    |   |    |     |      /           \    |     |    |       |    |   |
  | |         |   |    |   |    |     |      |           |    |     |    |       |    |   |
  | |         |   |    |   |    |     |      |           |    |     |    |       |    |   |
  | |    _   /     \  /     \  /       \     |           |   /       \  /         \  /     \
 /   \  / \  |     |  |     |  |       |    /             \  |       |  |         |  |     |   _
 |   |  | |  |     |  |     |  |       |    |             |  |       |  |         |  |     |  / \
 |   |  | |  |     |  |     |  |       |    |             |  |       |  |         |  |     |  | |
 |   |  | | /       \/       \/         \   |             | /         \/           \/       \ | |
/     \/   \|       ||       ||         |  /               \|         ||           ||       | | |
|     ||   ||       ||       ||         |  |               ||         ||           ||       |/   \
|_____||___||_______||_______||_________|  |_______________||_________||___________||_______||___|/\/\
</code>```

Input = lorem ipsum

```<code>                                                                                _
                                                                                / \
                                                                              _             | |
                                                                             / \            | |
                          _                                                  | |            | |
                         / \                                                 | |           /   \
                         | |                                    _            | |           |   |
                         | |                                   / \          /   \          |   |
              _          | |                                   | |          |   |          |   |
             / \        /   \                                  | |          |   |         /     \
             | |        |   |              _                   | |          |   |         |     |         _
             | |        |   |             / \                 /   \        /     \        |     |        / \
    _        | |        |   |             | |                 |   |        |     |        |     |        | |
   / \      /   \      /     \            | |                 |   |        |     |       /       \       | |
   | |      |   |      |     |            | |                 |   |        |     |       |       |       | |
   | |      |   |      |     |           /   \               /     \      /       \      |       |      /   \
   | |      |   |      |     |           |   |        _      |     |      |       |      |       |      |   |
  /   \    /     \    /       \          |   |       / \     |     |      |       |     /         \     |   |
  |   |    |     |    |       |          |   |       | |     |     |      |       |     |         |     |   |
  |   |    |     |    |       |         /     \      | |    /       \    /         \    |         |    /     \
  |   |    |     |    |       |         |     |      | |    |       |    |         |    |         |    |     |
 /     \  /       \  /         \   _    |     |     /   \   |       |    |         |   /           \   |     |
 |     |  |       |  |         |  / \   |     |     |   |   |       |    |         |   |           |   |     |
 |     |  |       |  |         |  | |  /       \    |   |  /         \  /           \  |           |  /       \
 |     |  |       |  |         |  | |  |       |    |   |  |         |  |           |  |           |  |       |
/       \/         \/           \ | |  |       |   /     \ |         |  |           | /             \ |       |
|       ||         ||           |/   \ |       |   |     | |         |  |           | |             | |       |
|       ||         ||           ||   |/         \  |     |/           \/             \|             |/         \
|_______||_________||___________||___||_________|  |_____||___________||_____________||_____________||_________|
</code>```

Input = a.a.a.x.x.x.a.a.a

```<code>                             _                    _                    _
                            / \                  / \                  / \
                            | |                  | |                  | |
                            | |                  | |                  | |
                            | |                  | |                  | |
                           /   \                /   \                /   \
                           |   |                |   |                |   |
                           |   |                |   |                |   |
                           |   |                |   |                |   |
                          /     \              /     \              /     \
                          |     |              |     |              |     |
                          |     |              |     |              |     |
                          |     |              |     |              |     |
                         /       \            /       \            /       \
                         |       |            |       |            |       |
                         |       |            |       |            |       |
                         |       |            |       |            |       |
                        /         \          /         \          /         \
                        |         |          |         |          |         |
                        |         |          |         |          |         |
                        |         |          |         |          |         |
                       /           \        /           \        /           \
                       |           |        |           |        |           |
                       |           |        |           |        |           |
                       |           |        |           |        |           |
                      /             \      /             \      /             \
                      |             |      |             |      |             |
                      |             |      |             |      |             |
                      |             |      |             |      |             |
                     /               \    /               \    /               \
 _      _      _     |               |    |               |    |               |     _      _      _
/ \    / \    / \    |               |    |               |    |               |    / \    / \    / \
|_|/\/\|_|/\/\|_|/\/\|_______________|/\/\|_______________|/\/\|_______________|/\/\|_|/\/\|_|/\/\|_|
</code>```

Rules

Of course this is code golf, lowest score in bytes wins

Standard loophole rules apply

Any number of additional blank lines before or after the output are allowed

You can choose to output the entire result in one string or offer the output as an array where each element represents one line of output, or send to STDOUT

Note

This is my first post to PPCG, so please go easy on me. It's been through the sandbox. Any negative points or possible improvements please post as a comment and I'll do what I can

Title: Words -> City Skyline

Body:
PHP, <s>386</s> <s>376</s> <s>367</s> <s>364</s> <s>362</s> <s>358</s> 356 bytes

first approach; may still be golfable.

foreach(str_split($argv[1])as$c)for($n=28,$w='.'!=$c?1+2*ceil(1/3*$n=31&ord($c)):4,$p=$y=0;$y<36;){$s=str_pad("",$w,$y||!$n?" ":_);if($n>26&&!$y){$s="/\\/\\";$n=-1;}elseif($n-->0){$s[$p]=$s[$w-$p-1]="|";if($n%3<1){$o[$y++].=$s;$s=str_pad("",$w);$s[$p]="/";$s[$w-++$p]="\\";}}$o[$y++].=$s;if(!$n)$o[$y++].=str_pad(_,$w," ",2);}for($y=36;$y--;)echo"$o[$y]
";

PHP, <s>366</s> <s>362</s> <s>361</s> <s>360</s> 357 bytes

similar approach with a subfunction:

function a($p,$r){global$o,$w,$y;$o[$y++].=str_pad(str_pad($r[0],2*$p,$r[1]).$r[2],$w," ",2);}foreach(str_split($argv[1])as$i=>$c)for($n=28,$w='.'!=$c?1+2*$p=ceil(1/3*$n=31&ord($c)):$p=4,$y=0;$y<36;)if($n>26&&!$y)$o[$n=$y++].="/\\/\\";elseif($n-->0){a($p,$y?"| |":"|_|");if($n%3<1)a($p--,"/ \\");if(!$n)a(1," _");}else a(0,"");for($y=36;$y--;)echo"$o[$y]
";

breakdown for the second approach

function a($p,$r)
{
    global$o,$w,$y;
    $o[$y++].=                  // 3. add result to current line, increase line counter
        str_pad(                // 2. pad ...
        str_pad($r[0],2*$p,$r[1]).$r[2]     // 1. A + inner width(=2*$p-1) times B + C
        ,$w," ",2);             // ... to $w with blanks on both sides # 2==STR_PAD_BOTH
}

foreach(str_split($argv[1])as$i=>$c)
    for(
    $n=28,
    $w='.'!=$c                          // $w=total width
        ?1+2*$p=ceil(1/3*$n=31&ord($c)) // $n=storey count, $p=(inner width+1)/2
        :$p=4                           // $n=28, $p <= $w=4 for rubble
    ,
    $y=0;$y<36;)                        // $y=line counter
        if($n>26&&!$y)
            $o[$n=$y++].="/\\/\\";      // bottom line=rubble, $n=0
        elseif($n-->0)
        {
            a($p,$y?"| |":"|_|");       // add storey
            if($n%3<1)a($p--,"/ \\");   // add widening layer/roof
            if(!$n)a(1," _");           // add roof top
        }
        else
            a(0,"");                    // idk why str_pad doesn´t yield a warning here

for($y=36;$y--;)if($s=rtrim($o[$y]))echo"$s\n"; // output

+16 bytes if leading newlines are not allowed:

Replace echo"$o[$y]\n; with if($s=rtrim($o[$y]))echo"$s\n";.

-3 bytes for any of ;<=>?[\]^_{|}~ as rubble:
Replace 1) ($n=31&ord($c)) with $n, 2) $n=28,$w='.'!=$c with ($n=31&ord($c))<27 and 3) 4 with ($n=28)/7.

Another -8 for >, ^ or ~ as rubble: Undo 3)


答:
C#, 102 93 bytes

Saved 9 bytes thanks to milk - completely forgot to concatenate strings. The compare trick is pretty cool too.

```<code>w=>h=>{var s="";for(int i=0;i<h;)s+="|"+new String(1>i++%(h-1)?'-':' ',w-2)+"|\n";return s;};
</code>```

Try it online!

Full source, including test cases:

```<code>using System;

namespace DrawASCIIRectangle
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<int,Func<int,string>> d= w=>h=>{var s="";for(int i=0;i<h;)s+="|"+new String(1>i++%(h-1)?'-':' ',w-2)+"|\n";return s;};
            Console.WriteLine(d(3)(3));
            Console.WriteLine(d(5)(8));
            Console.WriteLine(d(10)(3));
        }
    }
}
</code>```

Title: Draw an ASCII Rectangle

Body:
C#, 102 93 bytes

Saved 9 bytes thanks to milk - completely forgot to concatenate strings. The compare trick is pretty cool too.

w=>h=>{var s="";for(int i=0;i<h;)s+="|"+new String(1>i++%(h-1)?'-':' ',w-2)+"|\n";return s;};

Try it online!

Full source, including test cases:

using System;

namespace DrawASCIIRectangle
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<int,Func<int,string>> d= w=>h=>{var s="";for(int i=0;i<h;)s+="|"+new String(1>i++%(h-1)?'-':' ',w-2)+"|\n";return s;};
            Console.WriteLine(d(3)(3));
            Console.WriteLine(d(5)(8));
            Console.WriteLine(d(10)(3));
        }
    }
}


问:
Let's get Animated!

The Challenge

GIFs are the most common image format for animation, and are used pretty heavily in today's social media. For the purpose of this challenge, I'm going to redefine what a GIF can be. This challenge will require you to take in a 3D array containing some sort of representation of a 2D 'image' and iterate through them, displaying an animation. This animation can be done anywhere, in a GIF, in your console, in a GUI, etc; the delivery doesn't matter, so long as it is animated.

The Input

A 3D array where the data inside somehow represents a 2D image.

The array may contain RGB data, true/false data or anything else you see fit.

I'm also fine with you dumbing it down to a 2D array of strings or something similar, but the animation must be a 2D animation.

The time between each frame in a format of your choosing (Seconds, Milliseconds, etc...).

People have been asking me whether or not they HAVE to include the duration length. My answer is "meh", as long as you are able to show animation. I'm more concerned that you adhere to the "Array" parameter than this one, meaning no random animations.

The Output

A seamlessly iterated sequence of output that looks like a 2D animation with the correct delay on each transition based on the value input.

The Rules

Output can be, but is not limited to:

GIF image.

GUI animation (my example).

In-console animation.

Honestly, any "animation" that you see fit, as long as it follows the below rules.

When outputting your image you must clear the console before showing the next frame, you cannot just print them sequentially.

Emulating a console "clear" is also acceptable, as long as it looks like a seamless animation (see the hint under my example for more information on what I mean).

Regardless of implementation, your animation should loop forever, or until stopped.

The "looping" can be as simple as while(true){} or infinite recursion, you may assume the user wants to view this masterpiece until they hit "ctrl+c".

You must be able to handle any size 2D 'images', if your language is limited by buffer sizes, this is acceptable and you may state this in your explanation.

Standard loopholes are disallowed.

Example I/O

Input (3D Array, Delay)

```<code>f([
  [[1,0,0],
   [0,0,0],
   [0,0,0]],
  [[0,0,0],
   [0,1,0],
   [0,0,0]],
  [[0,0,0],
   [0,0,0],
   [0,0,1]],
], 1)
</code>```

Output (Example, 2020 Bytes - Java)

```<code>import javax.swing.JFrame;
import javax.swing.JTextArea;

/**
 * Simple GIF class to animate a 3D integer array in a swing text area.
 * (Clearing the console in java isn't something you really do, so I chose
 * java on purpose to make it an extremely ungolf-able answer that someone
 * wouldn't bother to steal).
 */
public class Gif implements Runnable {
    /**
     * The output area.
     */
    private final JTextArea area;

    /**
     * The list of images.
     */
    private final int[][][] images;

    /**
     * The delay between image transitions.
     */
    private final long transitionDelay;

    /**
     * Main method, instantiates a GIF object and runs it.
     * @param args Does absolutely nothing.
     */
    public static void main(String[] args) {
        final int[][][] images = {{{1,0,0},{0,0,0},{0,0,0}},{{0,0,0},{0,1,0},{0,0,0}},{{0,0,0},{0,0,0},{0,0,1}}};
        final long transitionDelay = 1000L;
        new Thread(new Gif(images, transitionDelay)).start();
    }

    /**
     * Constructor for a GIF, takes in a 3D array of images and a transition
     * delay to wait between transitioning the images.
     * @param images The list of images.
     * @param delay The delay between each image.
     */
    public Gif(int[][][] images, long transitionDelay) {
        this.images = images;
        this.transitionDelay = transitionDelay;
        this.area = new JTextArea();
        final JFrame frame = new JFrame("It's a GIF!");
        frame.setSize(10,100);
        frame.add(area);
        frame.setVisible(true);
    }

    /**
     * When run, it will alter the area to imitate an animated GIF.
     */
    @Override
    public void run() {
        while (true) {
            for (int i = 0; i < images.length; i++) {
                final StringBuffer frame = new StringBuffer();
                for (int j = 0; j < images[i].length; j++) {
                    for (int k = 0; k < images[i][j].length; k++) {
                        frame.append("" + images[i][j][k]);
                    }
                    frame.append("\n");
                }
                this.area.setText(frame.toString());
                try{Thread.sleep(transitionDelay);}catch(Exception e){}
                this.area.setText("");
            }
        }
    }
}
</code>```

This results in a swing GUI popping up, animating the array:

HINT HINT: Use a language where console clearing is possible, or specify why what you are doing will end up with a result that looks like an animation in the language you chose. I think some languages have default buffer sizes on their consoles, you may use this to your advantage, but I expect an explanation or example. Just because I output my animation as a string, you don't have to; I could've just as easily used 0 for black and 1 for white and made a real GIF.

Judging

This is code-golf, lowest byte count wins (inputs excluded).

I'll +1 anyone who uses a language in a cool or unexpected way as well.

答:
GNU sed, <s>88</s> 84 + 1(n flag) = 85 bytes

Edit: 3 bytes less thanks to Riley

H;1h;${:
g;s:\n.*::;H;x;s:[^\n]*\n::;x;y:,:\n:;s:^:ESC[2J:;s:ESC:\d27:gp;esleep 1
b}
```

<p>The input format is one animation frame per line. For multiple output lines in a frame, use comma as separator. Because I run the program in a Linux console, the maximum image size available (measured in rows and columns) is dependent on the size of the terminal window. The pause between two frames is accomplished by the <em>sleep</em> shell command; to get a faster animation call <code>esleep 0.4</code> (seconds).</p>

<pre class="lang-sh prettyprint-override"><code>100,000,000            # The timer could be read from the input as well, but that
000,010,000            #would require a lot more bytes and I understand I'm allowed
000,000,001            #to hardcode the value.
</code>```

The best part is that I support color animation! To do this, I used the so called ANSI Escape Sequences to control the text font, foreground and background color, plus the position of the cursor, thus being able to clear the screen before each frame (code ESC[2J). To add color information, use the following format in the input, which is better explained here.

ESC[$FORMATm$textESC[0m     # 'ESC' is an actual string, it is then replaced
                            #in sed by the character with the ASCII value 27
```

<p><strong>Run:</strong></p>

<pre class="lang-sh prettyprint-override"><code>sed -nf animate.sed input.txt
</code>```

Examples: for each test, 2 animation cycles were screen-captured and saved in image GIF format (apologies for the low resolution)

0.4 seconds pause

1 second by default

Explanation:

H;1h                           # read each line/frame and store them in hold space
${:                            # when the input was read, start a loop
   g                           # copy hold space to pattern space
   s:\n.*::                    # remove all except the first/current frame
   H                           # append frame to hold space
   x;s:[^\n]*\n::;x            # delete first frame from hold space
   y:,:\n:                     # replace all commas with a newline
   s:^:ESC[2J:;s:ESC:\d27:gp   # use an ANSI Escape Sequence to clear the screen
                               #and print frame in color
   esleep 1                    # wait 1 second
b}                             # repeat
```

Title: Let's get Animated!

Body:
GNU sed, <s>88</s> 84 + 1(n flag) = 85 bytes

Edit: 3 bytes less thanks to Riley

H;1h;${:
g;s:\n.*::;H;x;s:[^\n]*\n::;x;y:,:\n:;s:^:ESC[2J:;s:ESC:\d27:gp;esleep 1
b}

The input format is one animation frame per line. For multiple output lines in a frame, use comma as separator. Because I run the program in a Linux console, the maximum image size available (measured in rows and columns) is dependent on the size of the terminal window. The pause between two frames is accomplished by the sleep shell command; to get a faster animation call esleep 0.4 (seconds).

100,000,000            # The timer could be read from the input as well, but that
000,010,000            #would require a lot more bytes and I understand I'm allowed
000,000,001            #to hardcode the value.

The best part is that I support color animation! To do this, I used the so called ANSI Escape Sequences to control the text font, foreground and background color, plus the position of the cursor, thus being able to clear the screen before each frame (code ESC[2J). To add color information, use the following format in the input, which is better explained here.

ESC[$FORMATm$textESC[0m     # 'ESC' is an actual string, it is then replaced
                            #in sed by the character with the ASCII value 27

Run:

sed -nf animate.sed input.txt

Examples: for each test, 2 animation cycles were screen-captured and saved in image GIF format (apologies for the low resolution)

0.4 seconds pause

1 second by default

Explanation:

H;1h                           # read each line/frame and store them in hold space
${:                            # when the input was read, start a loop
   g                           # copy hold space to pattern space
   s:\n.*::                    # remove all except the first/current frame
   H                           # append frame to hold space
   x;s:[^\n]*\n::;x            # delete first frame from hold space
   y:,:\n:                     # replace all commas with a newline
   s:^:ESC[2J:;s:ESC:\d27:gp   # use an ANSI Escape Sequence to clear the screen
                               #and print frame in color
   esleep 1                    # wait 1 second
b}                             # repeat


答:
Shakespeare Programming Language, 240 bytes

```<code>.
Ajax,.
Puck,.
Act I:.
Scene I:.
[Enter Ajax and Puck]
Puck:
Open your mind.Is hog as big as you?If so, let us return to scene II.You be sum of difference of zero and you and cat.Open thy heart!Let us return to scene I.
Scene II:.
[Exeunt]
</code>```

Takes input as a string of \0 and \1 control characters. Outputs as a string of 0 or 1. If the input must be the same as the output, replace Open thy heart with Speak thy mind for no change in bytecount. If \0 and \1 can't be used, do the above, but also replace Open your mind with Listen to thy heart for a 5-byte penalty.

Ungolfed:

```<code>The Invertion of Veronan Arrays.

Romeo, who stores the element.
Juliet, who lectures him.

Act I: In which an array is inverted.

Scene I: A silent entrance.

[Enter Romeo and Juliet]

Scene II: In which Juliet pours out her heart to Romeo.

Juliet:
  Open your mind. Is nothing better than thee? If so, let us proceed to scene III.
  Thou art as good as the sum of the difference between nothing and thee and my
  cat. Open your heart! Let us return to scene II.

Scene III: Finale.

[Exeunt]
</code>```

This roughly translates to the following C pseudocode:

```<code>int romeo;

Scene1:
romeo = getchar();
if (0 > romeo) goto Scene2;
romeo = 0 - romeo + 1;
printf("%d", romeo);
goto Scene1;

Scene2:;
</code>```

I'm using this interpreter. Sample run:

```<code>$ python splc.py invert.spl > invert.c
$ gcc invert.c -o invert.exe
$ echo -ne "\x00\x01\x00" | ./invert
101
</code>```

Title: Invert a boolean array

Body:
A nice simple one

Input

Given a boolean array (Or an acceptable alternative), you can assume the array will never be more than 32 elements long.

```<code>[false, false, true, false, false]
</code>```

Output

Invert every element of the array and output it.

```<code>[true, true, false, true, true]
</code>```

Rules

You can write a full program or just a function

Standard loopholes apply

Shortest code in bytes, per language, wins!

Test cases

```<code>Input:
[true, false]
Output:
[false, true]

Input: //Example of acceptable alternative
[0,1,1]
Output:
[1,0,0]
</code>```

Body:
Shakespeare Programming Language, 240 bytes

.
Ajax,.
Puck,.
Act I:.
Scene I:.
[Enter Ajax and Puck]
Puck:
Open your mind.Is hog as big as you?If so, let us return to scene II.You be sum of difference of zero and you and cat.Open thy heart!Let us return to scene I.
Scene II:.
[Exeunt]

Takes input as a string of \0 and \1 control characters. Outputs as a string of 0 or 1. If the input must be the same as the output, replace Open thy heart with Speak thy mind for no change in bytecount. If \0 and \1 can't be used, do the above, but also replace Open your mind with Listen to thy heart for a 5-byte penalty.

Ungolfed:

The Invertion of Veronan Arrays.

Romeo, who stores the element.
Juliet, who lectures him.

Act I: In which an array is inverted.

Scene I: A silent entrance.

[Enter Romeo and Juliet]

Scene II: In which Juliet pours out her heart to Romeo.

Juliet:
  Open your mind. Is nothing better than thee? If so, let us proceed to scene III.
  Thou art as good as the sum of the difference between nothing and thee and my
  cat. Open your heart! Let us return to scene II.

Scene III: Finale.

[Exeunt]

This roughly translates to the following C pseudocode:

int romeo;

Scene1:
romeo = getchar();
if (0 > romeo) goto Scene2;
romeo = 0 - romeo + 1;
printf("%d", romeo);
goto Scene1;

Scene2:;

I'm using this interpreter. Sample run:

$ python splc.py invert.spl > invert.c
$ gcc invert.c -o invert.exe
$ echo -ne "\x00\x01\x00" | ./invert
101


答:
Python 2, 56 bytes

```<code>w,h=input()
for c in'-%*c'%(h-1,45):print'|'+c*(w-2)+'|'
</code>```

flornquake saved one byte.

Title: Draw an ASCII Rectangle

Body:
Given two integers as input in an array, draw a rectangle, using the first integer as width and second as height.

Or, if your language supports it, the two integers can be given as separate inputs.

Assume the width and height will never be less than 3, and they will always be given.

Example Outputs:

[3, 3]

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

[5, 8]

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

[10, 3]

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

This is code-golf, so the answer with the lowest amount of bytes wins.

Body:
Python 2, 56 bytes

w,h=input()
for c in'-%*c'%(h-1,45):print'|'+c*(w-2)+'|'

flornquake saved one byte.


答:
Python 3, <s>104</s> 95 bytes

( feedback from @mbomb007 : -9 bytes)

def d(x,y):return'\n'.join(('|'+('-'*(x-2)if n<1or n==~-y else' '*(x-2))+'|')for n in range(y))
```

(my first code golf, appreciate feedback)

Title: Draw an ASCII Rectangle

Body:
Python 3, <s>104</s> 95 bytes

( feedback from @mbomb007 : -9 bytes)

def d(x,y):return'\n'.join(('|'+('-'*(x-2)if n<1or n==~-y else' '*(x-2))+'|')for n in range(y))

(my first code golf, appreciate feedback)


问:
Print all integers
Write a program or function which will provably print all integers exactly once given infinite time and memory.

Possible outputs could be:

```<code>0, 1, -1, 2, -2, 3, -3, 4, -4, …

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

This is not a valid output, as this would never enumerate negative numbers:

<s>```0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, …```</s>

The output must be in decimal, unless your language does not support decimal integer (in that case use the natural representation of integers your language uses).

Your program has to work up to the numbers with the biggest magnitude of the standard integer type of your language.

Each integer must be separated from the next using any separator (a space, a comma, a linebreak, etc.) that is not a digit nor the negative sign of your language.

The separator must not change at any point.

The separator can consist of multiple characters, as long as none of them is a digit nor the negative sign (e.g. ,  is as valid as just ,).

Any supported integer must eventually be printed after a finite amount of time.

Scoring

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

Leaderboard

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
R, <s>33</s> 29 bytes

```<code>x=0;while(T)cat("",-x,x<-x+1)
</code>```

Output (for < 10)

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

Explanation

It works because x is set to 0, then prints -0 which displays as 0. It then increments and prints that, giving 1. The next element is the negative value of the last which is -1 and so on...

EDIT: Cut it down by 4 bytes after I realised that I could just have it loop forever. In R, T is TRUE by default.

Title: Print all integers

Body:
R, <s>33</s> 29 bytes

x=0;while(T)cat("",-x,x<-x+1)

Output (for < 10)

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

Explanation

It works because x is set to 0, then prints -0 which displays as 0. It then increments and prints that, giving 1. The next element is the negative value of the last which is -1 and so on...

EDIT: Cut it down by 4 bytes after I realised that I could just have it loop forever. In R, T is TRUE by default.


问:
English to Alien translator

Briefing

Aliens have settled on earth and strangely enough, their alphabet is the exact same as ours. Their language is also very similar to ours with some very distinct and easy to compute differences.

Challenge

Take a string and output the alien's language equivalent. The translation works as such:

Swap all the vowels in the word with the corresponding:

```<code>  Vowel |   With
--------+--------
   a    |   obo
   e    |   unu
   i    |   ini
   o    |   api
   u    |   iki
</code>```

You may also write another translator to translate Alien->English, this is optional however.

Examples

```<code>Input: Shaun
Output: Shoboikin

Input: Java
Output: Jobovobo

Input: Hello, World!
Output: Hunullapi, Wapirld!
</code>```

If the vowel is capitalized then you capitalize the first letter..

```<code>Input: Alan
Output: Obolobon

Input: Australia
Output: Oboikistroboliniobo
</code>```

Rules

Standard loopholes apply

Must work for text that contains new lines

You can either write a function, lambda, or full program

Capingrobotikilobotiniapins apin wrinitining thunu runuvunursunu trobonslobotapir!

Title: English to Alien translator

Body:
C, <s>163</s> <s>162</s> 159 bytes

char*t="aeiou";n,k;q(char*x){for(;*x;n<0||(*x=t[n>1?n%2?0:2:n+3])&&k>90||(*x-=32),printf("%c%.2s",*x++,n<0?"":&"bonunipiki"[2*n]))n=strchr(t,tolower(k=*x))-t;}


问:
Tips for golfing in MATL
MATL is a golfing language created by Luis Mendo. MATL has proven to be highly competitive, often beating submissions in other golfing languages such as Pyth, CJam and Jelly.

What are some useful tips for golfing in MATL? (As always, one tip per answer, please!)

For the record, MATL can be tested online here.

Documentation can be found on Github

答:
The & Meta-Function (Alternative Input / Output Specification)

The traditional way to specify the number of input arguments to pass to a function is to use the $ meta-function

```<code>2$:     % Two-input version of :
</code>```

Similarly, to specify the number of output arguments you can use the # meta-function specifying either the number of output arguments,

```<code>2#S     % Two-output version of sort
</code>```

or if you pass a number that is greater than the number of output arguments defined for a function, only the mod(N, numberOfOutputs) + 1 output is supplied.

```<code>4#S     % Get only the second output of sort
</code>```

You can additionally specify a logical array as the input to # to retrieve only specific output arguments.

```<code>TFT#u   % Three output version of unique and discard the second output
</code>```

All of these input / output specifications are handy but they drive up your byte-count very quickly. To deal with this, MATL introduced the & meta-function in the 17.0.0 release. This & meta-function acts as a shortcut for a particular input or output specification for a function. Let's see what that means.

In our example above, we wanted to use the two-input version of : (creates a vector of equally-spaced values). While the default number of input arguments to : is 1 (creates an array from [1...N]), it is very common that a user would want to specify the start value of the range which requires the second input. So for :, we have defined & to be a shortcut for 2$.

```<code>10      % Push 10 to the stack
12      % Push 12 to the stack
2$:     % Create an array: [10, 11, 12]
</code>```

Now becomes the following, saving a byte!

```<code>10 12 &:
</code>```

How can we determine what the alternate number of arguments is?

The input / output specification that & translates to is function specific such that we optimize the byte-savings.

The input / output argument section of the help description for each function has been updated to indicate what this alternative number of inputs / outputs is (if any). The possible number of input or output arguments are displayed as a range and the default values for each are shown in parentheses. The input / output spec that can be substituted with & is shown after the / character within the parentheses.

Here is the input / output argument section of the help description for :

```<code> +- Min-Max range of # of inputs
 |        +----- Alt. Default # of inputs
 |        |
 V        V
1--3 (1 / 2); 1 <--- Possible / Default # of outputs
      ^
      |
  Default # of inputs
</code>```

How did you determine what & means for each function?

Very carefully. Using the StackExchange API, we were able to download all MATL answers that have ever been used in a PPCG challenge. By parsing each of the answers, we were then able to determine the frequency with which each input / output spec was used for each function. Using this information we were then able to objectively identify the input / output specification the & meta-function should represent for each function. Sometimes there was no clear winner, so many functions currently don't have & defined.

Here is the script we used (unfortunately it's written in MATLAB and not MATL).

And here is an example of the histogram of $/# usage

Title: Tips for golfing in MATL

Body:
The & Meta-Function (Alternative Input / Output Specification)

The traditional way to specify the number of input arguments to pass to a function is to use the $ meta-function

2$:     % Two-input version of :

Similarly, to specify the number of output arguments you can use the # meta-function specifying either the number of output arguments,

2#S     % Two-output version of sort

or if you pass a number that is greater than the number of output arguments defined for a function, only the mod(N, numberOfOutputs) + 1 output is supplied.

4#S     % Get only the second output of sort

You can additionally specify a logical array as the input to # to retrieve only specific output arguments.

TFT#u   % Three output version of unique and discard the second output

All of these input / output specifications are handy but they drive up your byte-count very quickly. To deal with this, MATL introduced the & meta-function in the 17.0.0 release. This & meta-function acts as a shortcut for a particular input or output specification for a function. Let's see what that means.

In our example above, we wanted to use the two-input version of : (creates a vector of equally-spaced values). While the default number of input arguments to : is 1 (creates an array from [1...N]), it is very common that a user would want to specify the start value of the range which requires the second input. So for :, we have defined & to be a shortcut for 2$.

10      % Push 10 to the stack
12      % Push 12 to the stack
2$:     % Create an array: [10, 11, 12]

Now becomes the following, saving a byte!

10 12 &:

How can we determine what the alternate number of arguments is?

The input / output specification that & translates to is function specific such that we optimize the byte-savings.

The input / output argument section of the help description for each function has been updated to indicate what this alternative number of inputs / outputs is (if any). The possible number of input or output arguments are displayed as a range and the default values for each are shown in parentheses. The input / output spec that can be substituted with & is shown after the / character within the parentheses.

Here is the input / output argument section of the help description for :

 +- Min-Max range of # of inputs
 |        +----- Alt. Default # of inputs
 |        |
 V        V
1--3 (1 / 2); 1 <--- Possible / Default # of outputs
      ^
      |
  Default # of inputs

How did you determine what & means for each function?

Very carefully. Using the StackExchange API, we were able to download all MATL answers that have ever been used in a PPCG challenge. By parsing each of the answers, we were then able to determine the frequency with which each input / output spec was used for each function. Using this information we were then able to objectively identify the input / output specification the & meta-function should represent for each function. Sometimes there was no clear winner, so many functions currently don't have & defined.

Here is the script we used (unfortunately it's written in MATLAB and not MATL).

And here is an example of the histogram of $/# usage


答:
PowerShell v3+, 55 bytes

```<code>param($a,$b)1..$b|%{"|$((' ','-')[$_-in1,$b]*($a-2))|"}
</code>```

Takes input $a and $b. Loops from 1 to $b. Each iteration, we construct a single string. The middle is selected from an array of two single-length strings, then string-multiplied by $a-2, while it's surrounded by pipes. The resulting strings are left on the pipeline, and output via implicit Write-Output happens on program completion, with default newline separator.

Alternatively, also at 55 bytes

```<code>param($a,$b)1..$b|%{"|$((''+' -'[$_-in1,$b])*($a-2))|"}
</code>```

This one came about because I was trying to golf the array selection in the middle by using a string instead. However, since [char] times [int] isn't defined, we lose out on the savings by needing to cast as a string with parens and ''+.

Both versions require v3 or newer for the -in operator.

Examples

```<code>PS C:\Tools\Scripts\golfing> .\draw-an-ascii-rectangle.ps1 10 3
|--------|
|        |
|--------|

PS C:\Tools\Scripts\golfing> .\draw-an-ascii-rectangle.ps1 7 6
|-----|
|     |
|     |
|     |
|     |
|-----|
</code>```

Title: Draw an ASCII Rectangle

Body:
PowerShell v3+, 55 bytes

param($a,$b)1..$b|%{"|$((' ','-')[$_-in1,$b]*($a-2))|"}

Takes input $a and $b. Loops from 1 to $b. Each iteration, we construct a single string. The middle is selected from an array of two single-length strings, then string-multiplied by $a-2, while it's surrounded by pipes. The resulting strings are left on the pipeline, and output via implicit Write-Output happens on program completion, with default newline separator.

Alternatively, also at 55 bytes

param($a,$b)1..$b|%{"|$((''+' -'[$_-in1,$b])*($a-2))|"}

This one came about because I was trying to golf the array selection in the middle by using a string instead. However, since [char] times [int] isn't defined, we lose out on the savings by needing to cast as a string with parens and ''+.

Both versions require v3 or newer for the -in operator.

Examples

PS C:\Tools\Scripts\golfing> .\draw-an-ascii-rectangle.ps1 10 3
|--------|
|        |
|--------|

PS C:\Tools\Scripts\golfing> .\draw-an-ascii-rectangle.ps1 7 6
|-----|
|     |
|     |
|     |
|     |
|-----|


问:
Tips for golfing in R
I'm looking for tips for golfing in the R statistical language.  R is perhaps an unconventional choice for Golf.  However, it does certain things very compactly (sequences, randomness, vectors, and lists), many of the built-in functions have very short names, and it has an optional line terminator (;).  What tips and tricks can you give to help solve code golf problems in R?</p>

答:
Abuse the builtins T and F. By default, they evaluate to TRUE and FALSE, which can be automatically converted to numerics 1 and 0, and they can be re-defined at will. This means that you don't need to initialize a counter (e.g. i=0 ... i=i+1), you can just use T or F as needed (and jump straight to F=F+1 later).

Remember that functions return the last object called and do not need an explicit return() call.

Defining short aliases for commonly used functions is great, such as p=paste. If you use a function a lot, and with exactly two arguments, it is possible that an infixing alias will save you some bytes. Infixing aliases must be surrounded by %. For example:

```<code>`%p%`=paste
</code>```

And subsequently x%p%y, which is 1 byte shorter than p(x,y). The infixing alias definition is 4 bytes longer than the non-infixing p=paste though, so you have to be sure it's worth it.

Title: Tips for golfing in R

Body:
Abuse the builtins T and F. By default, they evaluate to TRUE and FALSE, which can be automatically converted to numerics 1 and 0, and they can be re-defined at will. This means that you don't need to initialize a counter (e.g. i=0 ... i=i+1), you can just use T or F as needed (and jump straight to F=F+1 later).

Remember that functions return the last object called and do not need an explicit return() call.

Defining short aliases for commonly used functions is great, such as p=paste. If you use a function a lot, and with exactly two arguments, it is possible that an infixing alias will save you some bytes. Infixing aliases must be surrounded by %. For example:

`%p%`=paste

And subsequently x%p%y, which is 1 byte shorter than p(x,y). The infixing alias definition is 4 bytes longer than the non-infixing p=paste though, so you have to be sure it's worth it.


问:
Draw some ASCII-boxes
Take two lists of non-negative integers, and output an ASCII-box as it's defined below.

Corners and intersections are pluses: + (ASCII-code 43)

Vertical lines are bars | (ASCII-code 124)

Horizontal lines are minuses - (ASCII-code 45)

The first input list specifies the number of minuses between each plus sign, in the horizontal direction.

The second input list specifies the number of bars between each plus sign, in the vertical direction.

It's easier to explain with a few examples:

```<code>0    // No minuses between each + sign
0    // No bars between + signs

++
++

------------------
1 2   // First a single minus, then two minuses
1 2   // First  one bar, then two bars

+-+--+
| |  |
+-+--+
| |  |
| |  |
+-+--+

------------------
1 0 3 0 2 0
2 1 0 0

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

Clarifications:

Input order and format are optional

Only the boxes should be printed/displayed, but a trailing space or newlines are accepted.

You may optionally add 1 to all input values if that's more convenient. The second example would then be: 2 3; 2 3.

This is code golf, so the shortest code in bytes win.

答:
PowerShell v2+, 89 bytes

```<code>param($a,$b)($x="+$(($a|%{'-'*$_})-join'+')+")
$b|%{,"|$(($a|%{' '*$_})-join'|')|"*$_;$x}
</code>```

Dang, don't think I can quite catch JavaScript.

Takes input $a and $b as explicit arrays. Sets variable $x to be the top row of the boxes based on looping through $a and some string concatenation. That's encapsulated in parens so it's placed on the pipeline. Then, we loop through $b, each iteration putting two strings on the pipeline -- the same style string but with spaces and | instead of hyphens and +, and $x. Those strings are all gathered from the pipeline with an implicit Write-Output at program completion, with default newline between them.

Examples

```<code>PS C:\Tools\Scripts\golfing> .\make-some-ascii-boxes.ps1 @(0) @(0)
++
++

PS C:\Tools\Scripts\golfing> .\make-some-ascii-boxes.ps1 @(1,0,3,0,2,0) @(2,1,0,0)
+-++---++--++
| ||   ||  ||
| ||   ||  ||
+-++---++--++
| ||   ||  ||
+-++---++--++
+-++---++--++
+-++---++--++

PS C:\Tools\Scripts\golfing> .\make-some-ascii-boxes.ps1 @(1,4,1) @(1,2,1)
+-+----+-+
| |    | |
+-+----+-+
| |    | |
| |    | |
+-+----+-+
| |    | |
+-+----+-+
</code>```

Title: Draw some ASCII-boxes

Body:
PowerShell v2+, 89 bytes

param($a,$b)($x="+$(($a|%{'-'*$_})-join'+')+")
$b|%{,"|$(($a|%{' '*$_})-join'|')|"*$_;$x}

Dang, don't think I can quite catch JavaScript.

Takes input $a and $b as explicit arrays. Sets variable $x to be the top row of the boxes based on looping through $a and some string concatenation. That's encapsulated in parens so it's placed on the pipeline. Then, we loop through $b, each iteration putting two strings on the pipeline -- the same style string but with spaces and | instead of hyphens and +, and $x. Those strings are all gathered from the pipeline with an implicit Write-Output at program completion, with default newline between them.

Examples

PS C:\Tools\Scripts\golfing> .\make-some-ascii-boxes.ps1 @(0) @(0)
++
++

PS C:\Tools\Scripts\golfing> .\make-some-ascii-boxes.ps1 @(1,0,3,0,2,0) @(2,1,0,0)
+-++---++--++
| ||   ||  ||
| ||   ||  ||
+-++---++--++
| ||   ||  ||
+-++---++--++
+-++---++--++
+-++---++--++

PS C:\Tools\Scripts\golfing> .\make-some-ascii-boxes.ps1 @(1,4,1) @(1,2,1)
+-+----+-+
| |    | |
+-+----+-+
| |    | |
| |    | |
+-+----+-+
| |    | |
+-+----+-+


答:
Python, 40 bytes

```<code>p=print
p(0)
i=1
while 1:p(i);p(-i);i+=1
</code>```

Title: Print all integers

Body:
Write a program or function which will provably print all integers exactly once given infinite time and memory.

Possible outputs could be:

```<code>0, 1, -1, 2, -2, 3, -3, 4, -4, …

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

This is not a valid output, as this would never enumerate negative numbers:

<s>```0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, …```</s>

The output must be in decimal, unless your language does not support decimal integer (in that case use the natural representation of integers your language uses).

Your program has to work up to the numbers with the biggest magnitude of the standard integer type of your language.

Each integer must be separated from the next using any separator (a space, a comma, a linebreak, etc.) that is not a digit nor the negative sign of your language.

The separator must not change at any point.

The separator can consist of multiple characters, as long as none of them is a digit nor the negative sign (e.g. ,  is as valid as just ,).

Any supported integer must eventually be printed after a finite amount of time.

Scoring

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

Leaderboard

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Body:
Python, 40 bytes

p=print
p(0)
i=1
while 1:p(i);p(-i);i+=1


答:
><> Fish - 9 (16?) Bytes

My second golf and my first in ><> Fish!

```<code>l?!;r0=nr
</code>```

I'm not sure how to count bytes when flags are considered, but this solution works when running the python interpreter with the -v flag and then space-separated 1's and 0's. If this doesn't match spec, I can remove the answer.

Example

Input/Run:

```<code>python fish.py --code "l?!;r0=nr" -v 0 1 0 1 1
</code>```

Output:

```<code>10100
</code>```

If I'm not allowed to use flags, and instead need to take the input from the input stack (such as on https://fishlanguage.com/playground), the code becomes longer as I must read from the input stack (either 1 or 0 without any separation) until there are no more values, and then convert the char value of the input (1 becomes 49 and 0 becomes 48) to their decimal values before my comparison. I'm not sure how to count bytes for ><> but I believe this would be 16 bytes.

```<code>i:1+?!;f3*3+-0=n
</code>```

Title: Invert a boolean array

Body:
><> Fish - 9 (16?) Bytes

My second golf and my first in ><> Fish!

l?!;r0=nr

I'm not sure how to count bytes when flags are considered, but this solution works when running the python interpreter with the -v flag and then space-separated 1's and 0's. If this doesn't match spec, I can remove the answer.

Example

Input/Run:

python fish.py --code "l?!;r0=nr" -v 0 1 0 1 1

Output:

10100

If I'm not allowed to use flags, and instead need to take the input from the input stack (such as on https://fishlanguage.com/playground), the code becomes longer as I must read from the input stack (either 1 or 0 without any separation) until there are no more values, and then convert the char value of the input (1 becomes 49 and 0 becomes 48) to their decimal values before my comparison. I'm not sure how to count bytes for ><> but I believe this would be 16 bytes.

i:1+?!;f3*3+-0=n


问:
Hexagolf: Validagons

Challenge

Given an ASCII art shape, you must find out whether the shape is a regular hexagon or not.

Hexagons

A regular hexagon is defined using two rules:

It has six sides

Each side has equal numbers of characters

For example, the following shape is regular but it doesn't have six sides and so is not a regular hexagon:

```<code>B a a h
s a i d
y o u r
g a o t
</code>```

Similarly, the following shape has six sides but has sides of different lengths and so is not a regular hexagon:

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

However, the following shape has six sides and all of the sides have the same number of characters, so it is a regular hexagon:

```<code>  T h e
 h e x a
g o n s a
 r e c o
  m i n
</code>```

Rules

Output should be a truthy or a falsey value (truthy if the shape is a regular hexagon, falsey if not).

The shapes will only ever contain printable ASCII characters.

The border of the shape will never contain spaces. If it does, you can return falsey.

There can be arbitrary amounts of whitespace before and/or after the shape.

All angles in the shape may not be equal for example, the following shape is valid input:

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

It will return a falsey value.

All shape inputs will be on a space separated grid. Hexagonal input will be on a staggered grid (each line is offset from the next).

Examples

Truthy

The following shapes should return truthy values:

```<code> # _
+ + +
 9 :
</code>```

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

```<code>    t h i s
   i       s
  a         h
 e           x
  a         g
   o       n
    ! ! ! !
</code>```

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

Falsey

The following should return falsey values

```<code>r e c t a
n g l e s
</code>```

```<code>  h e l l o
 w o r l d s
t h i s i s b
 e t a d e c
  a y n o w
</code>```

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

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

This shape is not on a space separated grid and is not staggered.

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

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

For single character inputs, your program may output either truthy or falsey:

```<code>&
</code>```

Winning

The shortest program in bytes wins.

Title: Hexagolf: Validagons

Body:
Perl, <s>127</s> <s>125</s> <s>124</s> 121 bytes

Includes +4 for -0p

Give input on STDIN

#!/usr/bin/perl -0p
/ *(.*\S)/;$a=join'\S *
\1',map$"x(abs).'\S '.(/$n/?'\S ':'. ')x(2*$n-1-abs),-($n=$1=~y/ //)..$n;$_=/^$`( *)$a\S\s*$/