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

答:
Matlab, <s>69</s> <s>65</s> 56 bytes

Thanks @WeeingIfFirst and @LuisMendo for some bytes=)

```<code>function z=f(a,b);z(b,a)=' ';z([1,b],:)=45;z(:,[1,a])='|'
</code>```

This is really simple in Matlab: First make a matrix of the desired size, then index the first and last row to insert the -, and do the same with the first and last column to insert |.

For example f(4,3) returns

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

Title: Draw an ASCII Rectangle

Body:
Matlab, <s>69</s> <s>65</s> 56 bytes

Thanks @WeeingIfFirst and @LuisMendo for some bytes=)

function z=f(a,b);z(b,a)=' ';z([1,b],:)=45;z(:,[1,a])='|'

This is really simple in Matlab: First make a matrix of the desired size, then index the first and last row to insert the -, and do the same with the first and last column to insert |.

For example f(4,3) returns

|--|
|  |
|--|


答:
05AB1E, <s>23</s> <s>22</s> 20 bytes

Input taken as height, then width.

```<code>F„ -N_N¹<Q~è²Í×'|.ø,
</code>```

Explanation

```<code>F                          # height number of times do
    N_                     # current row == first row
          ~                # OR
      N¹<Q                 # current row == last row
 „ -       è               # use this to index into " -"
            ²Í×            # repeat this char width-2 times
               '|          # push a pipe
                 .ø        # surround the repeated string with the pipe
                   ,       # print with newline
</code>```

Try it online!

Saved 2 bytes thanks to Adnan

ContentLicense: CC BY-SA 3.0

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:
05AB1E, <s>23</s> <s>22</s> 20 bytes

Input taken as height, then width.

F„ -N_N¹<Q~è²Í×'|.ø,

Explanation

F                          # height number of times do
    N_                     # current row == first row
          ~                # OR
      N¹<Q                 # current row == last row
 „ -       è               # use this to index into " -"
            ²Í×            # repeat this char width-2 times
               '|          # push a pipe
                 .ø        # surround the repeated string with the pipe
                   ,       # print with newline

Try it online!

Saved 2 bytes thanks to Adnan


Title: Draw an ASCII Rectangle

Body:
PHP, 74 Bytes

for(;$i<$n=$argv[2];)echo str_pad("|",$argv[1]-1,"- "[$i++&&$n-$i])."|\n";


答:
Ruby, <s>59</s> <s>54</s> 52 bytes

Oh, that's a lot simpler :)

```<code>->x,y{y.times{|i|puts"|#{(-~i%y<2??-:' ')*(x-2)}|"}}
</code>```

Test run at ideone

Title: Draw an ASCII Rectangle

Body:
Ruby, <s>59</s> <s>54</s> 52 bytes

Oh, that's a lot simpler :)

->x,y{y.times{|i|puts"|#{(-~i%y<2??-:' ')*(x-2)}|"}}

Test run at ideone


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

答:
C, <s>207</s> 202 bytes (thanks to Cyoce)

```<code>#include <stdio.h>
#define r(c,t) case c:printf(t);continue;
int main(){int c;while(~(c=getchar())){switch(c){r('a',"obo")r('e',"unu")r('i',"ini")r('o',"api")r('u',"iki")default:putchar(c);}}return 0;}
</code>```

1) I hate to omit type before any kind of declarations

2) I don't really like to put unusable code (without main() function)

Usage:

```<code>c89 cg.c -o cg; echo "Testing" | ./cg
</code>```

Title: English to Alien translator

Body:
C, <s>207</s> 202 bytes (thanks to Cyoce)

#include <stdio.h>
#define r(c,t) case c:printf(t);continue;
int main(){int c;while(~(c=getchar())){switch(c){r('a',"obo")r('e',"unu")r('i',"ini")r('o',"api")r('u',"iki")default:putchar(c);}}return 0;}

1) I hate to omit type before any kind of declarations

2) I don't really like to put unusable code (without main() function)

Usage:

c89 cg.c -o cg; echo "Testing" | ./cg


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

答:
JavaScript (ES6), 83 bytes

```<code>(a,b,g=(a,[s,t])=>t+a.map(n=>s.repeat(n)+t).join``+`
`)=>g(b,[g(a,` |`),g(a,`-+`)])
</code>```

Output includes two trailing newlines.

Title: Draw some ASCII-boxes

Body:
JavaScript (ES6), 83 bytes

(a,b,g=(a,[s,t])=>t+a.map(n=>s.repeat(n)+t).join``+`
`)=>g(b,[g(a,` |`),g(a,`-+`)])

Output includes two trailing newlines.


问:
Output the largest number with the fewest digits
Given a nonempty list of positive decimal integers, output the largest number from the set of numbers with the fewest digits.

The input list will not be in any particular order and may contain repeated values.

Examples:

```<code>[1] -> 1
[9] -> 9
[1729] -> 1729
[1, 1] -> 1
[34, 3] -> 3
[38, 39] -> 39
[409, 12, 13] -> 13
[11, 11, 11, 1] -> 1
[11, 11, 11, 11] -> 11
[78, 99, 620, 1] -> 1
[78, 99, 620, 10] -> 99
[78, 99, 620, 100] -> 99
[1, 5, 9, 12, 63, 102] -> 9
[3451, 29820, 2983, 1223, 1337] -> 3451
[738, 2383, 281, 938, 212, 1010] -> 938
</code>```

The shortest code in bytes wins.

答:
Common Lisp, 136 bytes

Golfed:

```<code>(defun o(&rest r &aux(s(sort r '<)))(flet((f(x)(floor(log x 10))))(apply 'max(remove-if(lambda(x)(<(apply 'min(mapcar 'f s))(f x)))s))))
</code>```

Ungolfed:

```<code>(defun o (&rest r
      &aux (s (sort r '<)))
  (flet ((f (x) (floor (log x 10))))
    (apply 'max
       (remove-if (lambda (x)
            (< (apply 'min (mapcar 'f s))
               (f x)))
              s))))
</code>```

Body:
Common Lisp, 136 bytes

Golfed:

(defun o(&rest r &aux(s(sort r '<)))(flet((f(x)(floor(log x 10))))(apply 'max(remove-if(lambda(x)(<(apply 'min(mapcar 'f s))(f x)))s))))

Ungolfed:

(defun o (&rest r
      &aux (s (sort r '<)))
  (flet ((f (x) (floor (log x 10))))
    (apply 'max
       (remove-if (lambda (x)
            (< (apply 'min (mapcar 'f s))
               (f x)))
              s))))


问:
Print a Cantor Set

The Challenge

Build a N-Leveled Cantor Set.

The Cantor ternary set is created by repeatedly deleting the open
  middle thirds of a set of line segments.

The program receives one parameter N (a integer number) and then prints (in console or similar way) a Cantor Set of N levels. The print can only contain undescore (_) and whithe spaces characters. The parameter can be positive or negative and the sign indicates the Cantor Set construction orientation: If N > 0 the Cantor Set is constructed downwards and if N < 0 the Cantor Set is constructed upwards. If N = 0 then the program prints a single line (_).

For example:

N = 2

```<code>_________
___   ___
_ _   _ _
</code>```

N = -2

```<code>_ _   _ _
___   ___
_________
</code>```

N = 3

```<code>___________________________
_________         _________
___   ___         ___   ___
_ _   _ _         _ _   _ _
</code>```

N = -3

```<code>_ _   _ _         _ _   _ _
___   ___         ___   ___
_________         _________
___________________________
</code>```

Winning criteria

As it is a code golf challenge, the shortest code wins.

Edited: Modify 0 input by ugoren's suggestion.

答:
Batch, <s>265</s> <s>262</s> <s>242</s> <s>236</s> 235 bytes

```<code>@echo off
set/pn=
set c=%n%,-1,0
if %n% lss 0 set c=0,1,%n:-=%
for /l %%i in (%c%)do call:l %%i
exit/b
:l
set s=_
for /l %%j in (1,1,%n:-=%)do call:m %1 %%j
echo %s%
:m
set t=%s%
if %1 lss +%2 set t=%s:_= %
set s=%s%%t%%s%
</code>```

Edit: Saved <s>12</s> 19 bytes thanks to @l4m2. Saved 8 bytes by removing the unnecessary %a% variable.

Title: Print a Cantor Set

Body:
Batch, <s>265</s> <s>262</s> <s>242</s> <s>236</s> 235 bytes

@echo off
set/pn=
set c=%n%,-1,0
if %n% lss 0 set c=0,1,%n:-=%
for /l %%i in (%c%)do call:l %%i
exit/b
:l
set s=_
for /l %%j in (1,1,%n:-=%)do call:m %1 %%j
echo %s%
:m
set t=%s%
if %1 lss +%2 set t=%s:_= %
set s=%s%%t%%s%

Edit: Saved <s>12</s> 19 bytes thanks to @l4m2. Saved 8 bytes by removing the unnecessary %a% variable.

ContentLicense: CC BY-SA 4.0


答:
PHP, 82 bytes

```<code>list(,$w,$h)=$argv;for($p=$h--*$w;$p;)echo$p--%$w?$p%$w?$p/$w%$h?" ":"-":"|
":"|";
</code>```

indexing a static string including the newline

```<code>list(,$w,$h)=$argv;         // import arguments
for($p=$h--*++$w;$p;)       // loop $p through all positions counting backwards
    // decrease $h and increase $w to avoid parens in ternary conditions
    echo" -|\n"[
        $p--%$w             // not (last+1 column -> 3 -> "\n")
        ?   $p%$w%($w-2)    // not (first or last row -> 2 -> "|")
            ?+!($p/$w%$h)   // 0 -> space for not (first or last row -> 1 -> "-")
            :2
        :3
    ];
</code>```

Title: Draw an ASCII Rectangle

Body:
PHP, 82 bytes

list(,$w,$h)=$argv;for($p=$h--*$w;$p;)echo$p--%$w?$p%$w?$p/$w%$h?" ":"-":"|
":"|";

indexing a static string including the newline

list(,$w,$h)=$argv;         // import arguments
for($p=$h--*++$w;$p;)       // loop $p through all positions counting backwards
    // decrease $h and increase $w to avoid parens in ternary conditions
    echo" -|\n"[
        $p--%$w             // not (last+1 column -> 3 -> "\n")
        ?   $p%$w%($w-2)    // not (first or last row -> 2 -> "|")
            ?+!($p/$w%$h)   // 0 -> space for not (first or last row -> 1 -> "-")
            :2
        :3
    ];


问:
"First time" test
What is the shortest C expression that is defined to evaluated to false the first time and true for every time after that:

Reference implementation:

```<code>bool b = false;  // you get this for free.

(b ? true : b = true, false)  // only this line is measured.
</code>```

答:
APL (5 or 6)

If I'm only allowed to initialize the variable to 0, it's 6 characters:

```<code>A←0    ⍝ free
⊃A←⍴⍴A
</code>```

How it works: ⍴A is the size of A (which is the empty list the first time around, because 0 is a scalar), so ⍴⍴A is the size of the size of A (which is [0] the first time, because a one-dimensional empty list has zero values in one dimension). This is then assigned to A (A←) and the first element is returned (⊃).

A is 0, ⍴A is [], then A is set to ⍴⍴A which is [0], and the first element is returned (0).

A is [0], ⍴A is [1], then A is set to ⍴⍴A which is [1], and the first element is returned (1).

A is [1], so ⍴A remains [1], so A is set to ⍴⍴A which remains [1] and it returns 1.

If I'm allowed to initialise the variable to anything I want, I can set it to the empty list and drop one of the ⍴s to make it 5 characters:

```<code>A←⍬    ⍝ free, set to empty list
⊃A←⍴A
</code>```

Title: "First time" test

Body:
APL (5 or 6)

If I'm only allowed to initialize the variable to 0, it's 6 characters:

A←0    ⍝ free
⊃A←⍴⍴A

How it works: ⍴A is the size of A (which is the empty list the first time around, because 0 is a scalar), so ⍴⍴A is the size of the size of A (which is [0] the first time, because a one-dimensional empty list has zero values in one dimension). This is then assigned to A (A←) and the first element is returned (⊃).

A is 0, ⍴A is [], then A is set to ⍴⍴A which is [0], and the first element is returned (0).

A is [0], ⍴A is [1], then A is set to ⍴⍴A which is [1], and the first element is returned (1).

A is [1], so ⍴A remains [1], so A is set to ⍴⍴A which remains [1] and it returns 1.

If I'm allowed to initialise the variable to anything I want, I can set it to the empty list and drop one of the ⍴s to make it 5 characters:

A←⍬    ⍝ free, set to empty list
⊃A←⍴A


答:
bash, sed and coreutils, 95 89 bytes

You can define a function like this

```<code>f(){ n=$[$1-2];yes \ |sed $[$2*n]q|tr -d \\n|fold -w$n|sed 's/^\|$/|/g;1!{$!b};s/ /-/g';}
</code>```

Or in a more readable format:

```<code>f() {
  n=$(($1-2))

  # The next couple of lines create a rectangle of spaces
  # matching the desired size
  yes ' '          |
  head -n$(($2*n)) |
  tr -d '\n'       |
  fold -w$n        |

  # Add the pipes and dashes
  sed '
    s/^\|$/|/g   # Replace first and last character by a pipe
    1! {$!b }    # Do nothing if not on first or last line
    s/ /-/g      # Add the dashes
  '
  echo
}
</code>```

You can now say f 4 3:

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

If you care about trailing new-line, add an echo at the end of function.

Title: Draw an ASCII Rectangle

Body:
bash, sed and coreutils, 95 89 bytes

You can define a function like this

f(){ n=$[$1-2];yes \ |sed $[$2*n]q|tr -d \\n|fold -w$n|sed 's/^\|$/|/g;1!{$!b};s/ /-/g';}

Or in a more readable format:

f() {
  n=$(($1-2))

  # The next couple of lines create a rectangle of spaces
  # matching the desired size
  yes ' '          |
  head -n$(($2*n)) |
  tr -d '\n'       |
  fold -w$n        |

  # Add the pipes and dashes
  sed '
    s/^\|$/|/g   # Replace first and last character by a pipe
    1! {$!b }    # Do nothing if not on first or last line
    s/ /-/g      # Add the dashes
  '
  echo
}

You can now say f 4 3:

|--|
|  |
|--|

If you care about trailing new-line, add an echo at the end of function.


Title: Draw an ASCII Rectangle

Body:
Python 2, 67 bytes

def f(a,b):c="|"+"-"*(a-2)+"|\n";print c+c.replace("-"," ")*(b-2)+c

Examples

f(3,3)

|-|
| |
|-|

f(5,8)

|---|
|   |
|   |
|   |
|   |
|   |
|   |
|---|

f(10,3)

|--------|
|        |
|--------|


Title: Draw an ASCII Rectangle

Body:
Common Lisp, 104 bytes

Golfed:

(defun a(w h)(flet((f(c)(format t"|~v@{~A~:*~}|~%"(- w 2)c)))(f"-")(loop repeat(- h 2)do(f" "))(f"-")))

Ungolfed:

(defun a (w h)
  (flet ((f (c) (format t "|~v@{~A~:*~}|~%" (- w 2) c)))
    (f "-")
    (loop repeat (- h 2) do
     (f " "))
    (f "-")))


答:
JavaScript (ES6), 63 bytes

f=
(w,h,g=c=>`|${c[0].repeat(w-2)}|
`)=>g`-`+g` `.repeat(h-2)+g`-`
;```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div oninput=o.textContent=f(w.value,h.value)><input id=w type=number min=3 value=3><input id=h type=number min=3 value=3><pre id=o></code>```

Title: Draw an ASCII Rectangle

Body:
JavaScript (ES6), 63 bytes

f=
(w,h,g=c=>`|${c[0].repeat(w-2)}|
`)=>g`-`+g` `.repeat(h-2)+g`-`
;

<div oninput=o.textContent=f(w.value,h.value)><input id=w type=number min=3 value=3><input id=h type=number min=3 value=3><pre id=o>


答:
MATL, 19 bytes

```<code>'|-| '2:"iqWQB]E!+)
</code>```

Try it online!

Explanation

The approach is similar to that used in this other answer. The code builds a numerical array of the form

```<code>3 2 2 2 3
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
3 2 2 2 3
</code>```

and then its values are used as (1-based, modular) indices into the string '|-| ' to produce the desired result.

```<code>'|-| '                % Push this string
      2:"     ]       % Do this twice
         i            % Take input
          q           % Subtract 1
           W          % 2 raised to that
            Q         % Add 1
             B        % Convert to binary
               E      % Multiply by 2
                !     % Transpose
                 +    % Add with broadcast
                  )   % Index (modular, 1-based) into the string
</code>```

Title: Draw an ASCII Rectangle

Body:
MATL, 19 bytes

'|-| '2:"iqWQB]E!+)

Try it online!

Explanation

The approach is similar to that used in this other answer. The code builds a numerical array of the form

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

and then its values are used as (1-based, modular) indices into the string '|-| ' to produce the desired result.

'|-| '                % Push this string
      2:"     ]       % Do this twice
         i            % Take input
          q           % Subtract 1
           W          % 2 raised to that
            Q         % Add 1
             B        % Convert to binary
               E      % Multiply by 2
                !     % Transpose
                 +    % Add with broadcast
                  )   % Index (modular, 1-based) into the string


答:
Batch, 128 bytes

```<code>@set s=
@for /l %%i in (3,1,%1)do @call set s=-%%s%%
@echo ^|%s%^|
@for /l %%i in (3,1,%2)do @echo ^|%s:-= %^|
@echo ^|%s%^|
</code>```

Takes width and height as command-line parameters.

Title: Draw an ASCII Rectangle

Body:
Batch, 128 bytes

@set s=
@for /l %%i in (3,1,%1)do @call set s=-%%s%%
@echo ^|%s%^|
@for /l %%i in (3,1,%2)do @echo ^|%s:-= %^|
@echo ^|%s%^|

Takes width and height as command-line parameters.


Title: Draw an ASCII Rectangle

Body:
Haxe, <s>112</s> 106 bytes

function R(w,h){for(l in 0...h){var s="";for(i in 0...w)s+=i<1||i==w-1?'|':l<1||l==h-1?'-':' ';trace(s);}}

Testcases

R(5, 8)
|---|
|   |
|   |
|   |
|   |
|   |
|   |
|---|

R(10, 3)
|---------|
|         |
|---------|


答:
MATL, <s>21</s> 17 bytes

```<code>Z"45ILJhY('|'5MZ(
</code>```

This is a slightly different approach than the one of the MATL-God.

```<code>Z"                   Make a matrix of spaces of the given size
  45ILJhY(           Fill first and last row with '-' (code 45)
          '|'5MZ(    Fill first and last column with '|' (using the automatic clipboard entry 5M to get ILJh back)
</code>```

Thanks @LuisMendo for all the help!

Try it Online!

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:
MATL, <s>21</s> 17 bytes

Z"45ILJhY('|'5MZ(

This is a slightly different approach than the one of the MATL-God.

Z"                   Make a matrix of spaces of the given size
  45ILJhY(           Fill first and last row with '-' (code 45)
          '|'5MZ(    Fill first and last column with '|' (using the automatic clipboard entry 5M to get ILJh back)

Thanks @LuisMendo for all the help!

Try it Online!


问:
StringgnirtSStringgnirtSStringgnirtS
Here is a relatively simple challenge for you.

Given a string of length N, output the string forwards, then backwards, then forwards, then backwards... etc. N times. For example, if your input was

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

You should output:

```<code>Hello!!olleHHello!!olleHHello!!olleH
</code>```

You may also optionally output one trailing newline.

Your submission may be either a full program or a function, and you may take input and output in any reasonable format. For example, you may take IO from STDIN/STDOUT, function arguments and return value, from a file, etc. You can safely assume that the input string will not be empty, and will only contain printable ASCII. You must output the new string on a single line. So, for example, if the output to the last example was

```<code>Hello!
!olleH
Hello!
!olleH
Hello!
!olleH
</code>```

This would not be a valid solution!

Here are some more test cases:

```<code>Input:
a
Output:
a

Input:
abcd
Output:
abcddcbaabcddcba

Input:
OK!
Output:
OK!!KOOK!

Input:
4815162342
Output:
4815162342243261518448151623422432615184481516234224326151844815162342243261518448151623422432615184

Input:
PPCG
Output:
PPCGGCPPPPCGGCPP

Input:
42
Output:
4224
</code>```

Leaderboards

Since this is a code-golf challenge, standard loopholes are banned, and the shortest answer in bytes wins! However, this is also a competition to have the shortest answer in any particular langauge. While it's unlikely that a Java answer will beat an answer in perl, or some golfing language, it's still very impressive to have the shortest Java answer. So, you can use this leaderboard to see both

The shortest answer out of all languages, and

The shortest answer in each individual language.

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

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

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

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

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

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

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

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

var QUESTION_ID=93261,OVERRIDE_USER=31716;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

```

Title: StringgnirtSStringgnirtSStringgnirtS

Body:
Haxe, <s>121</s> <s>118</s> 117 bytes

function R(s:String){var r="",o="",l=s.length;for(i in-l+1...1)r+=s.charAt(-i);for(i in 0...l)o+=i%2<1?s:r;trace(o);}

Reverting the string took a lot of bytes :(

Testcases

R("a")
a

R("Hello!")
Hello!!olleHHello!!olleHHello!!olleH

R("4815162342")
4815162342243261518448151623422432615184481516234224326151844815162342243261518448151623422432615184


问:
print 1 to 100 without using recursion and conditions
can we print 1 to 100 without using any if conditions and loops in c&c++?

Conditon:
main point is you must not use recursion...and doesnt hardcode code in it
for e.g

print(1 2 3..etc);

答:
Perl 6 (10)

```<code>print ^101
</code>```

If one wants to be able to read the numbers and therefore spaces between the numbers would be nice, the following will do the trick.

```<code>say ~ ^101
</code>```

Body:
Perl 6 (10)

print ^101

If one wants to be able to read the numbers and therefore spaces between the numbers would be nice, the following will do the trick.

say ~ ^101


答:
Haskell, <s>62</s> 55 bytes

```<code>f[a,b]n=a:(b<$[3..n])++[a]
g i=unlines.f[f"|-"i,f"| "i]
</code>```

Usage example:

```<code>*Main> putStr $ g 10 3
|--------|
|        |
|--------|
</code>```

The helper function f takes a two element list [a,b] and a number n and returns a list of one a followed by n-2 bs followed by one a. We can use f thrice: to build the top/bottom line: f "|-" i, a middle line: f "| " i and from those two the whole rectangle: f [<top>,<middle>] j (note: j doesn't appear as a parameter in g i because of partial application).

Edit: @dianne saved some bytes by combining two Char arguments into one String of length 2. Thanks a lot!

Title: Draw an ASCII Rectangle

Body:
Haskell, <s>62</s> 55 bytes

f[a,b]n=a:(b<$[3..n])++[a]
g i=unlines.f[f"|-"i,f"| "i]

Usage example:

*Main> putStr $ g 10 3
|--------|
|        |
|--------|

The helper function f takes a two element list [a,b] and a number n and returns a list of one a followed by n-2 bs followed by one a. We can use f thrice: to build the top/bottom line: f "|-" i, a middle line: f "| " i and from those two the whole rectangle: f [<top>,<middle>] j (note: j doesn't appear as a parameter in g i because of partial application).

Edit: @dianne saved some bytes by combining two Char arguments into one String of length 2. Thanks a lot!


答:
Python 2, <s>61</s> 58 bytes

-3 bytes thanks to @flornquake (remove unnecessary parentheses; use h as counter)

def f(w,h):exec"print'|'+'- '[1<h<%d]*(w-2)+'|';h-=1;"%h*h
```

Test cases are at ideone

Title: Draw an ASCII Rectangle

Body:
Python 2, <s>61</s> 58 bytes

-3 bytes thanks to @flornquake (remove unnecessary parentheses; use h as counter)

def f(w,h):exec"print'|'+'- '[1<h<%d]*(w-2)+'|';h-=1;"%h*h

Test cases are at ideone


答:
Jelly, 14 bytes

```<code>,þ%,ỊḄị“-|| ”Y
</code>```

Try it online! or verify all test cases.

How it works

```<code>,þ%,ỊḄị“-|| ”Y  Main link. Left argument: w. Right argument: h

,þ              Pair table; yield a 2D array of all pairs [i, j] such that
                1 ≤ i ≤ w and 1 ≤ j ≤ h.
   ,            Pair; yield [w, h].
  %             Take the remainder of the element-wise division of each [i, j]
                by [w, h]. This replaces the highest coordinates with zeroes.
    Ị           Insignificant; map 0 and 1 to 1, all other coordinates to 0.
     Ḅ          Unbinary; convert each pair from base 2 to integer.
                  [0, 0] -> 0 (area)
                  [0, 1] -> 1 (top or bottom edge)
                  [1, 0] -> 2 (left or right edge)
                  [1, 1] -> 3 (vertex)
       “-|| ”   Yield that string. Indices are 1-based and modular in Jelly, so the
                indices of the characters in this string are 1, 2, 3, and 0.
      ị         At-index; replace the integers by the correspoding characters.
             Y  Join, separating by linefeeds.
</code>```

Title: Draw an ASCII Rectangle

Body:
Jelly, 14 bytes

,þ%,ỊḄị“-|| ”Y

Try it online! or verify all test cases.

How it works

,þ%,ỊḄị“-|| ”Y  Main link. Left argument: w. Right argument: h

,þ              Pair table; yield a 2D array of all pairs [i, j] such that
                1 ≤ i ≤ w and 1 ≤ j ≤ h.
   ,            Pair; yield [w, h].
  %             Take the remainder of the element-wise division of each [i, j]
                by [w, h]. This replaces the highest coordinates with zeroes.
    Ị           Insignificant; map 0 and 1 to 1, all other coordinates to 0.
     Ḅ          Unbinary; convert each pair from base 2 to integer.
                  [0, 0] -> 0 (area)
                  [0, 1] -> 1 (top or bottom edge)
                  [1, 0] -> 2 (left or right edge)
                  [1, 1] -> 3 (vertex)
       “-|| ”   Yield that string. Indices are 1-based and modular in Jelly, so the
                indices of the characters in this string are 1, 2, 3, and 0.
      ị         At-index; replace the integers by the correspoding characters.
             Y  Join, separating by linefeeds.


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

答:
Emacs Lisp, 25 bytes

```<code>(lambda(x)(mapcar'not x))
</code>```

Not very creative.

Title: Invert a boolean array

Body:
Emacs Lisp, 25 bytes

(lambda(x)(mapcar'not x))

Not very creative.


答:
PHP 4.1, 76 bytes

```<code><?$R=str_repeat;echo$l="|{$R('-',$w=$W-2)}|
",$R("|{$R(' ',$w)}|
",$H-2),$l;
</code>```

This assumes you have the default php.ini settings for this version, including short_open_tag and register_globals enabled.

This requires access through a web server (e.g.: Apache), passing the values over session/cookie/POST/GET variables.

The key W controls the width and the key H controls the height.

For example: http://localhost/file.php?W=3&H=5

Title: Draw an ASCII Rectangle

Body:
PHP 4.1, 76 bytes

<?$R=str_repeat;echo$l="|{$R('-',$w=$W-2)}|
",$R("|{$R(' ',$w)}|
",$H-2),$l;

This assumes you have the default php.ini settings for this version, including short_open_tag and register_globals enabled.

This requires access through a web server (e.g.: Apache), passing the values over session/cookie/POST/GET variables.

The key W controls the width and the key H controls the height.

For example: http://localhost/file.php?W=3&H=5


问:
What is the smallest positive base 10 integer that can be printed by a program shorter (in characters) than itself?
I think the question as above is clear, but just in case:

Write a full program (not just a function) which prints a positive base 10 integer, optionally followed by a single newline.

Qualifying programs will be those whose output is longer (in bytes) than the source code of the program, measured in bytes (assuming ASCII or UTF-8 encoding for the program source code).

I.e. the code must be shorter than the number of digits in the resulting number.

Leading zeros are disallowed under all circumstances. Counting leading zeroes trivialises the problem; ignoring leading zeros unnecessarily complicates the question.

The winning program will be the qualifying program which prints the integer with the smallest magnitude.

Leaderboard snippet

var QUESTION_ID = 67921;
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe"; var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;
function answersUrl(index) { return "https://api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER; }
function commentUrl(index, answers) { return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER; }
function getAnswers() { jQuery.ajax({ url: answersUrl(answer_page++), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { answers.push.apply(answers, data.items); answers_hash = []; answer_ids = []; data.items.forEach(function(a) { a.comments = []; var id = +a.share_link.match(/\d+/); answer_ids.push(id); answers_hash[id] = a; }); if (!data.has_more) more_answers = false; comment_page = 1; getComments(); } }); } function getComments() { jQuery.ajax({ url: commentUrl(comment_page++, answer_ids), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { if (data.has_more) getComments(); else if (more_answers) getAnswers(); else process(); } }); }
getAnswers();
var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*)(?:,|[-\u2013] ).*?([\d,^!e+]+)(?=\:?[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;
var OVERRIDE_REG = /^Override\s*header:\s*/i;
function getAuthorName(a) { return a.owner.display_name; }
function process() { var valid = []; answers.forEach(function(a) { var body = a.body; a.comments.forEach(function(c) { if(OVERRIDE_REG.test(c.body)) body = '
' + c.body.replace(OVERRIDE_REG, '') + '
'; }); var match = body.replace(/([^\n<]*)<\/sup>/g, "^$1").replace(/\(\d+(?:\^\d+,)? [\w\s]+\)/g, "").replace(/floor\(10\^(\d+)\/9\)/g, "$1 ones").replace(/(\d+) ones/g, function (_, x) { return Array(+x + 1).join(1); }).match(SCORE_REG); if (match) valid.push({ user: getAuthorName(a), size: +match[2].replace(/,/g, "").replace(/(\d+)\s*\^\s*(\d+)/, function (_, a, b) { return Math.pow(a, b); }).replace(/(\d+)!/, function (_, n) { for (var i = 1, j = 1; i <= n; i++) j *= i; return j; }), language: match[1], link: a.share_link, }); else console.log(body); }); valid.sort(function (a, b) { var aB = a.size, bB = b.size; return aB - bB }); var languages = {}; var place = 1; var lastSize = null; var lastPlace = 1; valid.forEach(function (a) { if (a.size != lastSize) lastPlace = place; lastSize = a.size; ++place; var answer = jQuery("#answer-template").html(); answer = answer.replace("{{PLACE}}", lastPlace + ".") .replace("{{NAME}}", a.user) .replace("{{LANGUAGE}}", a.language) .replace("{{SIZE}}", a.size) .replace("{{LINK}}", a.link); answer = jQuery(answer); jQuery("#answers").append(answer); var lang = a.language; lang = jQuery(''+lang+'').text(); languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang.toLowerCase(), user: a.user, size: a.size, link: a.link}; }); var langs = []; for (var lang in languages) if (languages.hasOwnProperty(lang)) langs.push(languages[lang]); langs.sort(function (a, b) { if (a.lang_raw > b.lang_raw) return 1; if (a.lang_raw < b.lang_raw) return -1; return 0; }); for (var i = 0; i < langs.length; ++i) { var language = jQuery("#language-template").html(); var lang = langs[i]; language = language.replace("{{LANGUAGE}}", lang.lang) .replace("{{NAME}}", lang.user) .replace("{{SIZE}}", lang.size) .replace("{{LINK}}", lang.link); language = jQuery(language); jQuery("#languages").append(language); } }```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style>body { text-align: left !important} #answer-list { padding: 10px; width: 290px; float: left; } #language-list { padding: 10px; width: 290px; float: left; } table thead { font-weight: bold; } table td { padding: 5px; }</style>
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">
<div id="language-list"> <h2>Shortest Solution by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr> </thead> <tbody id="languages"> </tbody> </table> </div> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr> </thead> <tbody id="answers"> </tbody> </table> </div> <table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td>Link</td></tr> </tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td>Link</td></tr> </tbody> </table></code>```

Body:
///, score 111111111111

/./111/....

Try it online!

/./111/ removes itself and replaces every . with 111, so .... becomes 111111111111.


问:
Showcase of Languages

Notes

This thread is open and unlocked only because the community decided to make an exception. Please do not use this question as evidence that you can ask similar questions here. Please do not create additional showcase questions.

This is no longer a popularity-contest, nor are snippet lengths limited by the vote tally. If you know this thread from before, please make sure you familiarize yourself with the changes.

This thread is dedicated to showing off interesting, useful, obscure, and/or unique features your favorite programming languages have to offer. This is neither a challenge nor a competition, but a collaboration effort to showcase as many programming languages as possible as well as possible.

How this works

All answers should include the name of the programming language at the top of the post, prefixed by a #.

Answers may contain one (and only one) factoid, i.e., a couple of sentences without code that describe the language.

Aside from the factoid, answers should consist of snippets of code, which can (but don't have to be) programs or functions.

The snippets do not need to be related. In fact, snippets that are too related may be redundant.

Since this is not a contest, all programming languages are welcome, whenever they were created.

Answers that contain more than a handful of code snippets should use a Stack Snippet to collapse everything except the factoid and one of the snippets.

Whenever possible, there should be only one answer per programming language. This is a community wiki, so feel free to add snippets to any answer, even if you haven't created it yourself. There is a Stack Snippet for compressing posts, which should mitigate the effect of the 30,000 character limit.

Answers that predate these guidelines should be edited. Please help updating them as needed.

Current answers, sorted alphabetically by language name

$.ajax({type:"GET",url:"https://api.stackexchange.com/2.2/questions/44680/answers?site=codegolf&filter=withbody",success:function(data){for(var i=0;i<data.items.length;i++){var temp=document.createElement('p');temp.innerHTML = data.items[i].body.split("\n")[0];$('#list').append('
' + temp.innerText || temp.textContent + '');}}})```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><base href="http://codegolf.stackexchange.com"><ul id="list"></ul></code>```

答:
///

/// is a minimalist Turing-complete esoteric programming language. The only operation is repeated string substitution, using the syntax /pattern/replacement/.

Factoid

/// was proved Turing-complete by Ørjan Johansen in 2009, who created an interpreter for the Turing-complete language Bitwise Cyclic Tag.

(from http://esolangs.org/wiki////)

You can test the snippets here, or click their header.

Length 1

```<code>☃
</code>```

There's not much that can be done with one character in this language, so have a unicode snowman.

Length 2

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

This won't print a newline. A \ in this language means that it'll print the next character, so it'll print a n. \s are used mostly for printing /s, like this: \/.

Length 3

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

This is an infinite loop that does nothing, and is also the language name. It keeps replacing nothing with nothing.

Length 4 ★

```<code>/☃//
</code>```

This attempts to replace a snowman with nothing/remove every snowman. Since the entire source code, except the /☃// part, doesn't contain a snowman, it doesn't do anything.

Alternative Length 4 ★

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

Unary addition! Put both numbers on the right side of the snippet. (since /// can't take input) Like this: / //00000 000

Length 5

```<code>☃/☃//
</code>```

This snippet is important for showing one thing: string substitution doesn't work on anything that comes before the /pattern/replacement/.

If you take a look at snippet length 4, it removes every snowman. But that won't work if there are snowmen before the /pattern/replacement/, so he stays there and get printed.

However, this snippet would remove the snowman, because the snowman comes after the /pattern/replacement/ part: /☃//☃.

Alternative Length 5 ★

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

This snippet completely breaks the language. It works by removing every /.

Try it here.

Length 6

```<code>/
/☃/
(newline)
</code>```

Remember the second snippet? Instead of writing \n, you use a literal new line.

Because Markdown apparently doesn't like empty lines of code, you have to remove the (newline) part when trying this in Try it online! or any other /// interpreter.

You probably guessed it by now, but I'll explain it anyways. The /\n/☃/ part replaces every newline with a snowman. Since there's a trailing new line in the snippet, it gets replaced by a snowman and printed.

This is probably kinda boring, but don't worry, I have something more interesting planned for the seventh snippet :-)

Length 7

```<code>/☃/☃8/☃
</code>```

This is an infinite loop. More interesting than the sixth snippet IMO.

When /// finds a /pattern/replacement/, it will keep replacing pattern with replacement until there are no more patterns to be replaced. Therefore, if replacement contains pattern, it will always end up on an infinite loop.

There will always be a snowman to get replaced with a snowman and a badly drawn snowman:

```<code>☃
(☃)
☃8
(☃)8
☃88
(☃)88
☃888
...
</code>```

Alternative Length 7 ★

```<code>\n
</code>```0

Unary subtraction! Put the numbers in this order: largest smallest, like this: /0 0/ /0000000 00000

Length 8

```<code>\n
</code>```1

Yay, 8 upvotes! An eight is the number that looks the most like a snowman.

The /☃/\// part replaces every snowman with a /. So you will probably think that if I place a snowman in the code, it'll print a /. Wrong.

Since /s are used for repeated string substitution, you'll have to put a \ before the / (in this case, the ☃) if you wanna print it.

This may seem obvious, but I forgot it once and spent some minutes trying to find the bug in my code.

Length 9

```<code>\n
</code>```2

The /☃/\\\\/ part replaces every snowman with two \ (Since \\ is only one \, \\\\ is actually \\).

There's only one snowman after that, so it gets replaced by the two \.

Finally, the two \ turn into only one \ and that gets printed.

Length 10

```<code>/☃/8/☃/8/B
</code>```

If you pay attention, the second replacement is incomplete. The first replacement replaces a snowman with an eight.

The second replacement doesn't do anything, since it's incomplete. Syntax errors don't exist in ///, so nothing happens. If you don't believe me, turn on debug on TIO.

Length 11

```<code>/☃/8//8/☃/☃
</code>```

I just realized today is 11/11, I'm adding snippet length 11 and this post has 11 upvotes...

I don't think there is anything important left to showcase about this language, /// is very simple. But I'll still try to add more snippets.

This is probably obvious, but replacements can modify other replacements.

The first replacement replaces every snowman with an eight:

```<code>/8/☃/☃
/8/(☃)/(☃)
/8/8/8
</code>```

This is an infinite loop (/8/8/), since there will always be an eight to be replaced.

Length 12 ★

```<code>/☃/\/8\//☃B/
</code>```

Making replacements with replacements! /☃/\/8\// replaces ☃ with /8/:

```<code>☃B/
(☃)B/
/8/B/
</code>```

As you can see, this is now a replacement. It replaces every 8 after it with B.

A snippet with a ★ means that it requires "input" (place input on the right side of the code) and it won't do anything by itself.

Title: Showcase of Languages

Body:
///

/// is a minimalist Turing-complete esoteric programming language. The only operation is repeated string substitution, using the syntax /pattern/replacement/.

Factoid

/// was proved Turing-complete by Ørjan Johansen in 2009, who created an interpreter for the Turing-complete language Bitwise Cyclic Tag.

(from http://esolangs.org/wiki////)

You can test the snippets here, or click their header.

Length 1

☃

There's not much that can be done with one character in this language, so have a unicode snowman.

Length 2

\n

This won't print a newline. A \ in this language means that it'll print the next character, so it'll print a n. \s are used mostly for printing /s, like this: \/.

Length 3

///

This is an infinite loop that does nothing, and is also the language name. It keeps replacing nothing with nothing.

Length 4 ★

/☃//

This attempts to replace a snowman with nothing/remove every snowman. Since the entire source code, except the /☃// part, doesn't contain a snowman, it doesn't do anything.

Alternative Length 4 ★

/ //

Unary addition! Put both numbers on the right side of the snippet. (since /// can't take input) Like this: / //00000 000

Length 5

☃/☃//

This snippet is important for showing one thing: string substitution doesn't work on anything that comes before the /pattern/replacement/.

If you take a look at snippet length 4, it removes every snowman. But that won't work if there are snowmen before the /pattern/replacement/, so he stays there and get printed.

However, this snippet would remove the snowman, because the snowman comes after the /pattern/replacement/ part: /☃//☃.

Alternative Length 5 ★

/\///

This snippet completely breaks the language. It works by removing every /.

Try it here.

Length 6

/
/☃/
(newline)

Remember the second snippet? Instead of writing \n, you use a literal new line.

Because Markdown apparently doesn't like empty lines of code, you have to remove the (newline) part when trying this in Try it online! or any other /// interpreter.

You probably guessed it by now, but I'll explain it anyways. The /\n/☃/ part replaces every newline with a snowman. Since there's a trailing new line in the snippet, it gets replaced by a snowman and printed.

This is probably kinda boring, but don't worry, I have something more interesting planned for the seventh snippet :-)

Length 7

/☃/☃8/☃

This is an infinite loop. More interesting than the sixth snippet IMO.

When /// finds a /pattern/replacement/, it will keep replacing pattern with replacement until there are no more patterns to be replaced. Therefore, if replacement contains pattern, it will always end up on an infinite loop.

There will always be a snowman to get replaced with a snowman and a badly drawn snowman:

☃
(☃)
☃8
(☃)8
☃88
(☃)88
☃888
...

Alternative Length 7 ★

/0 0/ /

Unary subtraction! Put the numbers in this order: largest smallest, like this: /0 0/ /0000000 00000

Length 8

/☃/\//\☃

Yay, 8 upvotes! An eight is the number that looks the most like a snowman.

The /☃/\// part replaces every snowman with a /. So you will probably think that if I place a snowman in the code, it'll print a /. Wrong.

Since /s are used for repeated string substitution, you'll have to put a \ before the / (in this case, the ☃) if you wanna print it.

This may seem obvious, but I forgot it once and spent some minutes trying to find the bug in my code.

Length 9

/☃/\\\\/☃

The /☃/\\\\/ part replaces every snowman with two \ (Since \\ is only one \, \\\\ is actually \\).

There's only one snowman after that, so it gets replaced by the two \.

Finally, the two \ turn into only one \ and that gets printed.

Length 10

/☃/8/☃/8/B

If you pay attention, the second replacement is incomplete. The first replacement replaces a snowman with an eight.

The second replacement doesn't do anything, since it's incomplete. Syntax errors don't exist in ///, so nothing happens. If you don't believe me, turn on debug on TIO.

Length 11

/☃/8//8/☃/☃

I just realized today is 11/11, I'm adding snippet length 11 and this post has 11 upvotes...

I don't think there is anything important left to showcase about this language, /// is very simple. But I'll still try to add more snippets.

This is probably obvious, but replacements can modify other replacements.

The first replacement replaces every snowman with an eight:

/8/☃/☃
/8/(☃)/(☃)
/8/8/8

This is an infinite loop (/8/8/), since there will always be an eight to be replaced.

Length 12 ★

/☃/\/8\//☃B/

Making replacements with replacements! /☃/\/8\// replaces ☃ with /8/:

☃B/
(☃)B/
/8/B/

As you can see, this is now a replacement. It replaces every 8 after it with B.

A snippet with a ★ means that it requires "input" (place input on the right side of the code) and it won't do anything by itself.


答:
Pyth, 22 bytes

```<code>VJE.[Q*-Q2?}N,0tJ\-d\|
</code>```

A program that takes input of the width, followed  by the height, on STDIN and prints the result.

Try it online

How it works

```<code>VJE.[Q*-Q2?}N,0tJ\-d\|  Program. Inputs: Q, E
 JE                     Assign E to J
V                       For N in [0, 1, 2, ..., J-1]:
             ,0tJ        Yield [0, J-1]
           }N            N is in that list
          ?              If that:
                 \-       Yield "-"
                         Else:
                   d      Yield " "
      *-Q2               Repeat that Q-2 times
   .[Q              \|   Evenly pad that with "|" on both sides to length Q
                         Implicitly print
</code>```

Title: Draw an ASCII Rectangle

Body:
Pyth, 22 bytes

VJE.[Q*-Q2?}N,0tJ\-d\|

A program that takes input of the width, followed  by the height, on STDIN and prints the result.

Try it online

How it works

VJE.[Q*-Q2?}N,0tJ\-d\|  Program. Inputs: Q, E
 JE                     Assign E to J
V                       For N in [0, 1, 2, ..., J-1]:
             ,0tJ        Yield [0, J-1]
           }N            N is in that list
          ?              If that:
                 \-       Yield "-"
                         Else:
                   d      Yield " "
      *-Q2               Repeat that Q-2 times
   .[Q              \|   Evenly pad that with "|" on both sides to length Q
                         Implicitly print


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

答:
Clojure, 12 chars

```<code>(#(%%)#(%%))
</code>```

Running in the repl:

```<code>user=> (#(%%)#(%%))
StackOverflowError   user/eval404/fn--407 (NO_SOURCE_FILE:1)
</code>```

Body:
Clojure, 12 chars

(#(%%)#(%%))

Running in the repl:

user=> (#(%%)#(%%))
StackOverflowError   user/eval404/fn--407 (NO_SOURCE_FILE:1)


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

答:
Jelly, 2 bytes

```<code>Æc
</code>```

Thank you for the builtin, @Lynn

Title: Compute the Carmichael function

Body:
Jelly, 2 bytes

Æc

Thank you for the builtin, @Lynn


答:
Pyth - <s>19</s> <s>18</s> 17 bytes

One byte saved thanks to @TheBikingViking.

Straight up brute force.

```<code>f!sm*t.^dTQq1iQdQ
</code>```

Try it online here.

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:
Pyth - <s>19</s> <s>18</s> 17 bytes

One byte saved thanks to @TheBikingViking.

Straight up brute force.

f!sm*t.^dTQq1iQdQ

Try it online here.


答:
Mathematica, 16 bytes

```<code>CarmichaelLambda
</code>```

Well...

Title: Compute the Carmichael function

Body:
Mathematica, 16 bytes

CarmichaelLambda

Well...


答:
Vimscript, <s>93</s> <s>83</s> <s>75</s> <s>74</s> <s>73</s> <s>66</s> <s>64</s> 63 bytes

Code

```<code>fu A(...)
exe "norm ".a:1."i|\ehv0lr-YpPgvr dd".a:2."p2dd"
endf
</code>```

Example

```<code>:call A(3,3)
</code>```

Explanation

```<code>fun A(...)    " a function with unspecified params (a:1 and a:2)
exe           " exe(cute) command - to use the parameters we must concatenate :(
norm          " run in (norm) al mode
#i|           " insert # vertical bars
\e            " return (`\<Esc>`) to normal mode
hv0l          " move left, enter visual mode, go to the beginning of the line,  move right (selects inner `|`s)
r-            " (r)eplace the visual selection by `-`s
YpP           " (Y) ank the resulting line, and paste them twice
gv            " re-select the previous visual selection
r<Space>      " replace by spaces
dd            " Cut the line
#p            " Paste # times (all inner rows)
2dd           " Remove extra lines
</code>```

Note that it is not using norm! so it might interfere with vim custom mappings!

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:
Vimscript, <s>93</s> <s>83</s> <s>75</s> <s>74</s> <s>73</s> <s>66</s> <s>64</s> 63 bytes

Code

fu A(...)
exe "norm ".a:1."i|\ehv0lr-YpPgvr dd".a:2."p2dd"
endf

Example

:call A(3,3)

Explanation

fun A(...)    " a function with unspecified params (a:1 and a:2)
exe           " exe(cute) command - to use the parameters we must concatenate :(
norm          " run in (norm) al mode
#i|           " insert # vertical bars
\e            " return (`\<Esc>`) to normal mode
hv0l          " move left, enter visual mode, go to the beginning of the line,  move right (selects inner `|`s)
r-            " (r)eplace the visual selection by `-`s
YpP           " (Y) ank the resulting line, and paste them twice
gv            " re-select the previous visual selection
r<Space>      " replace by spaces
dd            " Cut the line
#p            " Paste # times (all inner rows)
2dd           " Remove extra lines

Note that it is not using norm! so it might interfere with vim custom mappings!


Title: Compute the Carmichael function

Body:
Ruby, 59 56 bytes

->x{a=1..x
a.detect{|k|a.all?{|y|x.gcd(y)>1||y**k%x<2}}}


答:
Mathematica, <s>67</s> 64 bytes

Thanks to lastresort and TuukkaX for reminding me that golfers should be sneaky and saving 3 bytes!

Straightforward implementation. Returns an array of strings.

```<code>Table[Which[j<2||j==#,"|",i<2||i==#2,"-",0<1," "],{i,#2},{j,#}]&
</code>```

Title: Draw an ASCII Rectangle

Body:
Mathematica, <s>67</s> 64 bytes

Thanks to lastresort and TuukkaX for reminding me that golfers should be sneaky and saving 3 bytes!

Straightforward implementation. Returns an array of strings.

Table[Which[j<2||j==#,"|",i<2||i==#2,"-",0<1," "],{i,#2},{j,#}]&


Title: Compute the Carmichael function

Body:
Haskell, <s>57</s> 56 bytes

f n=[k|k<-[1..],and[mod(m^k)n<2|m<-[1..n],gcd m n<2]]!!0


答:
Java 135 bytes

```<code>public String rect(int x, int y){
String o="";
for(int i=-1;++i<y;){
o+="|";
for(int j=2;++j<x)
if(i<1||i==y-1)
o+="-";
else
o+=" ";
o+="|\n";
}
return o;
}
</code>```

Golfed:

```<code>String r(int x,int y){String o="";for(int i=-1;++i<y;){o+="|";for(int j=2;++j<x;)if(i<1||i==y-1)o+="-";else o+=" ";o+="|\n";}return o;}
</code>```

Title: Draw an ASCII Rectangle

Body:
Java 135 bytes

public String rect(int x, int y){
String o="";
for(int i=-1;++i<y;){
o+="|";
for(int j=2;++j<x)
if(i<1||i==y-1)
o+="-";
else
o+=" ";
o+="|\n";
}
return o;
}

Golfed:

String r(int x,int y){String o="";for(int i=-1;++i<y;){o+="|";for(int j=2;++j<x;)if(i<1||i==y-1)o+="-";else o+=" ";o+="|\n";}return o;}


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

Please post one tip per answer.

Haxe can be run online here!

答:
String interpolation

Haxe supports string interpolation on single-quote strings. Like template strings in JavaScript ES6, you can include an expression in a string with ${...}:

```<code>trace('2 + 2 = ${2 + 2}');
</code>```

Unlike ES6, however, you can omit the curly brackets when the expression is a single variable:

```<code>var x = 2 + 2;
trace('2 + 2 = $x');
</code>```

Both of these examples print 2 + 2 = 4.

Title: Tips for golfing in Haxe

Body:
String interpolation

Haxe supports string interpolation on single-quote strings. Like template strings in JavaScript ES6, you can include an expression in a string with ${...}:

trace('2 + 2 = ${2 + 2}');

Unlike ES6, however, you can omit the curly brackets when the expression is a single variable:

var x = 2 + 2;
trace('2 + 2 = $x');

Both of these examples print 2 + 2 = 4.


答:
C++ (115)

```<code>#include <cstdio>
template<int i>void p(){printf("%d ",i);p<i+1>();}
template<>void p<101>(){}
int main(){p<1>();}
</code>```

Title: print 1 to 100 without using recursion and conditions

Body:
can we print 1 to 100 without using any if conditions and loops in c&c++?

Conditon:
main point is you must not use recursion...and doesnt hardcode code in it
for e.g

print(1 2 3..etc);

Body:
C++ (115)

#include <cstdio>
template<int i>void p(){printf("%d ",i);p<i+1>();}
template<>void p<101>(){}
int main(){p<1>();}


答:
Mathematica without built-in, <s>58</s> 57 bytes

Thanks to Martin Ender for finding an error, then saving me the bytes it took to fix it!

Thanks to miles for saving 1 byte! (which seemed like 2 to me)

Built-ins are totally fine ... but for those who want to implement it without using brute force, here's a formula for the Carmichael function:

```<code>LCM@@(EulerPhi[#^#2]/If[#==2<#2,2,1]&@@@FactorInteger@#)&
</code>```

If p is a prime, the Carmichael function λ(p^r) equals φ(p^r) = (p-1)*p^(r-1)—except when p=2 and r≥3, in which case it's half that, namely 2^(r-2).

And if the prime-power factorization of n equals p1^r1 * p2^r2 * ..., then λ(n) equals the least common multiple of { λ(p1^r1), λ(p2^r2), ...}.

Runtime is one instant more than factoring the integer in the first place.

Title: Compute the Carmichael function

Body:
Mathematica without built-in, <s>58</s> 57 bytes

Thanks to Martin Ender for finding an error, then saving me the bytes it took to fix it!

Thanks to miles for saving 1 byte! (which seemed like 2 to me)

Built-ins are totally fine ... but for those who want to implement it without using brute force, here's a formula for the Carmichael function:

LCM@@(EulerPhi[#^#2]/If[#==2<#2,2,1]&@@@FactorInteger@#)&

If p is a prime, the Carmichael function λ(p^r) equals φ(p^r) = (p-1)*p^(r-1)—except when p=2 and r≥3, in which case it's half that, namely 2^(r-2).

And if the prime-power factorization of n equals p1^r1 * p2^r2 * ..., then λ(n) equals the least common multiple of { λ(p1^r1), λ(p2^r2), ...}.

Runtime is one instant more than factoring the integer in the first place.


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

```<code>[:*./@(5&p:%2^0=8&|)2^/@p:]
</code>```

The Carmichael function is λ(n) and the totient function is φ(n).

Uses the definition where λ(pk) = φ(pk)/2 if p = 2 and k > 2 else φ(pk). Then, for general n = p1k1 p2k2 ⋯ piki, λ(n) = LCM[ λ(p1k1) λ(p2k2) ⋯ λ(piki) ].

Usage

Extra commands used to format multiple input/output.

```<code>   f =: [:*./@(5&p:%2^0=8&|)2^/@p:]
   f 530
52
   (,.f"0) 1 2 3 10 35 101 530 3010 6511 10000
    1    1
    2    1
    3    2
   10    4
   35   12
  101  100
  530   52
 3010   84
 6511 3056
10000  500
</code>```

Explanation

```<code>[:*./@(5&p:%2^0=8&|)2^/@p:]  Input: integer n
                          ]  Identity function, get n
                    2   p:   Get a table of prime/exponent values for n
                     ^/@     Raise each prime to its exponent to get the prime powers of n
[:    (            )         Operate on the prime powers
                8&|            Take each modulo 8
              0=               Test if its equal to 0, 1 if true else 0
            2^                 Raise 2 to the power of each
       5&p:                    Apply the totient function to each prime power
           %                   Divide it by the powers of 2
  *./@                       Reduce using LCM and return
</code>```

Title: Compute the Carmichael function

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

[:*./@(5&p:%2^0=8&|)2^/@p:]

The Carmichael function is λ(n) and the totient function is φ(n).

Uses the definition where λ(pk) = φ(pk)/2 if p = 2 and k > 2 else φ(pk). Then, for general n = p1k1 p2k2 ⋯ piki, λ(n) = LCM[ λ(p1k1) λ(p2k2) ⋯ λ(piki) ].

Usage

Extra commands used to format multiple input/output.

   f =: [:*./@(5&p:%2^0=8&|)2^/@p:]
   f 530
52
   (,.f"0) 1 2 3 10 35 101 530 3010 6511 10000
    1    1
    2    1
    3    2
   10    4
   35   12
  101  100
  530   52
 3010   84
 6511 3056
10000  500

Explanation

[:*./@(5&p:%2^0=8&|)2^/@p:]  Input: integer n
                          ]  Identity function, get n
                    2   p:   Get a table of prime/exponent values for n
                     ^/@     Raise each prime to its exponent to get the prime powers of n
[:    (            )         Operate on the prime powers
                8&|            Take each modulo 8
              0=               Test if its equal to 0, 1 if true else 0
            2^                 Raise 2 to the power of each
       5&p:                    Apply the totient function to each prime power
           %                   Divide it by the powers of 2
  *./@                       Reduce using LCM and return


问:
Print a layered cake

Challenge

Given an input n, print an ASCII art cake n layers tall, viewed from the side, with two candles on top. Refer to the examples below for details.

Output

```<code>>> cake(1)

 _|_|_
|     |
+-----+

>> cake(3)

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

...and so on.

Rules

Standard loopholes prohibited

Please make an attempt at a clever solution

This is code-golf, so shortest answer in bytes wins. However, the answer will not be selected.

Have fun!

答:
Pyth, 73 bytes

```<code>+K*dtyQ"_|_|_"+tK"|     |"jP.iJms[*\ yt-Qd\+*+5*4d\-\+)+StQtQmXd"+-""| "J
</code>```

A program that takes input of an integer on STDIN and prints the result.

There is probably still some golfing to be done here.

Try it online

Explanation coming later

Title: Print a layered cake

Body:
Pyth, 73 bytes

+K*dtyQ"_|_|_"+tK"|     |"jP.iJms[*\ yt-Qd\+*+5*4d\-\+)+StQtQmXd"+-""| "J

A program that takes input of an integer on STDIN and prints the result.

There is probably still some golfing to be done here.

Try it online

Explanation coming later


答:
Range operator

Haxe has a range operator ... which can be used to create ranges of integers. For example, instead of this:

```<code>var i = 0;
while (i < 10) trace(i++);
</code>```

You can do this:

```<code>for (i in 0...10) trace(i++);
</code>```

Specifics for x...y:

x and y must both be Ints.

x cannot be larger than y.

This returns an IntIterator object, which can be used in the same places as any Iterable.

Title: Tips for golfing in Haxe

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

Please post one tip per answer.

Haxe can be run online here!

Body:
Range operator

Haxe has a range operator ... which can be used to create ranges of integers. For example, instead of this:

var i = 0;
while (i < 10) trace(i++);

You can do this:

for (i in 0...10) trace(i++);

Specifics for x...y:

x and y must both be Ints.

x cannot be larger than y.

This returns an IntIterator object, which can be used in the same places as any Iterable.


答:
Array comprehensions

Haxe supports array comprehensions:

```<code>trace([for (i in 0...5) i]); // Prints 0,1,2,3,4
</code>```

Unlike many other languages, you can also use while in comprehensions:

```<code>var i = 5;
trace([while (i > 0) i--]); // Prints 5,4,3,2,1
</code>```

This can be very useful when you don't know how long of an array you need.

You can also chain for, while, and if statements:

```<code>trace([for (x in ['A','B','C','D'])
       for (y in ['x','y'])
       if (x + y != "Cx")
       x + y
]); // Prints Ax,Ay,Bx,By,Cy,Dx,Dy
</code>```

Title: Tips for golfing in Haxe

Body:
Array comprehensions

Haxe supports array comprehensions:

trace([for (i in 0...5) i]); // Prints 0,1,2,3,4

Unlike many other languages, you can also use while in comprehensions:

var i = 5;
trace([while (i > 0) i--]); // Prints 5,4,3,2,1

This can be very useful when you don't know how long of an array you need.

You can also chain for, while, and if statements:

trace([for (x in ['A','B','C','D'])
       for (y in ['x','y'])
       if (x + y != "Cx")
       x + y
]); // Prints Ax,Ay,Bx,By,Cy,Dx,Dy


答:
JavaScript (ES 2016) 149

Python reference implementation ported to JS. Some fancy Pyhton builtin is missing in js, like gcd and pow, and the array comprehension is not standard in ES 6. This works in Firefox.

n=>eval('for(g=(a,b)=>b?g(b,a%b):a,p=(a,b,c)=>eval("for(r=1;b--;)r=r*a%c"),c=[for(_ of Array(i=n))if(g(i--,n)<2)i+1],k=1;c.some(x=>p(x,k,n)-1);)++k')
```
<p><em>Less golfed</em></p>
<pre class="lang-js prettyprint-override"><code>n=>{
  g=(a,b)=>b?g(b,a%b):a
  p=(a,b,c)=>{
    for(r=1;b--;)
      r=r*a%c
    return r
  }
  c=[for(_ of Array(i=n)) if(g(i--,n)<2) i+1]
  for(k=1;c.some(x=>p(x,k,n)-1);)
    ++k
  return k
}
</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:
JavaScript (ES 2016) 149

Python reference implementation ported to JS. Some fancy Pyhton builtin is missing in js, like gcd and pow, and the array comprehension is not standard in ES 6. This works in Firefox.

n=>eval('for(g=(a,b)=>b?g(b,a%b):a,p=(a,b,c)=>eval("for(r=1;b--;)r=r*a%c"),c=[for(_ of Array(i=n))if(g(i--,n)<2)i+1],k=1;c.some(x=>p(x,k,n)-1);)++k')

Less golfed

n=>{
  g=(a,b)=>b?g(b,a%b):a
  p=(a,b,c)=>{
    for(r=1;b--;)
      r=r*a%c
    return r
  }
  c=[for(_ of Array(i=n)) if(g(i--,n)<2) i+1]
  for(k=1;c.some(x=>p(x,k,n)-1);)
    ++k
  return k
}


问:
Interpret Repetition!
This challenge is the first in a two-challenge series about Repetition. The second will be up soon.

In a language called Repetition (something I just made up), there consists an infinite string of 12345678901234567890..., with 1234567890 repeating forever.

The following syntax is available to output numbers:

+-*/: This inserts the operator into the string of repeating digits.

Examples:

+ -> 1+2 = 3 (The + inserts a + between 1 and 2)

+* -> 1+2*3 = 1+6 = 7 (Same as above, except two operators are used now)

/ -> 1/2 = 0 (Repetition uses integer division)

// -> 1/2/3 = 0/3 = 0 (Repetition uses "left association" with multiple subtractions and divisions)

Each operator is inserted so that it has one digit to its left, unless there are c's (see below).

c: Concatenates with the next digit in the string.

Examples:

c+ -> 12+3 = 15 (The c "continues" the 1 and concatenates it with the next digit, 2, to form 12)

+c -> 1+23 = 24

ccc -> 1234

(): Brackets for processing numbers.

Examples:

(c+)* -> (12+3)*4 = 15*4 = 60 (Repetition uses the order of operations)

(c+)/c -> (12+3)/45 = 15/45 = 0

(cc+c)/ -> (123+45)/6 = 168/6 = 28

s: Skip a number (removes the number from the infinite string).

s+ -> 2+3 = 5 (s skips 1)

csc -> 124 (The first c concats 1 and 2, the s skips 3, and the final c concats 12 to 4)

+s+ -> 7 (The first + adds 1 and 2 to make 3, s skips 3, and the final + adds 3 to 4 to make 7)

cs*(++) -> 12*(4+5+6) = 12*15 = 180

In the examples above, only a finite amount of digits in the infinite string are used. The number of digits used is equivalent to number of operators, concats and skips + 1.

Your task is, when given a string of Repetition code, output the result.

Examples of input and output are:

```<code>++ -> 6
- -> -1
(-)* -> -3
cscc -> 1245
(cc+c)/ -> 28
cc+c/ -> 130
cs*(++) -> 180
</code>```

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

Specs:

You are guaranteed that the result will never go above 2^31-1.

You are also guaranteed that the input will only consist of the symbols +-*/cs().

An empty program will output 1.

答:
Batch, 332 bytes

```<code>@echo off
set s=
set e=
set d=
set r=
set/ps=
:d
set/ad=-~d%%10
:l
if "%s%"=="" goto g
set c=%s:~0,1%
set s=%s:~1%
if %c%==( set e=%e%(&goto l
if %c%==) set r=%r%)&goto l
if %c%==s goto d
if %c%==c set c=
if "%r%"=="" set/ar=d,d=-~d%%10
set e=%e%%r%%c%
set/ar=d
goto d
:g
if "%r%"=="" set/ar=d
cmd/cset/a%e%%r%
</code>```

The behaviour of s makes this very awkward. (Maybe cs should evaluate to 13 and -s to -2?) Variables:

s input string (explicitly blanked out because set/p doesn't change the variable if you don't input anything)

e partial expression in normal integer arithmetic (which we can pass to set/a as a form of eval)

d next digit from the infinite string of digits

r right hand side of latest operator. We can't concatenate this immediately because ( needs to come first, but we need to store it so that s won't increment it. Fortunately it does end up making the handling of ) slightly easier.

c current character.

Title: Interpret Repetition!

Body:
Batch, 332 bytes

@echo off
set s=
set e=
set d=
set r=
set/ps=
:d
set/ad=-~d%%10
:l
if "%s%"=="" goto g
set c=%s:~0,1%
set s=%s:~1%
if %c%==( set e=%e%(&goto l
if %c%==) set r=%r%)&goto l
if %c%==s goto d
if %c%==c set c=
if "%r%"=="" set/ar=d,d=-~d%%10
set e=%e%%r%%c%
set/ar=d
goto d
:g
if "%r%"=="" set/ar=d
cmd/cset/a%e%%r%

The behaviour of s makes this very awkward. (Maybe cs should evaluate to 13 and -s to -2?) Variables:

s input string (explicitly blanked out because set/p doesn't change the variable if you don't input anything)

e partial expression in normal integer arithmetic (which we can pass to set/a as a form of eval)

d next digit from the infinite string of digits

r right hand side of latest operator. We can't concatenate this immediately because ( needs to come first, but we need to store it so that s won't increment it. Fortunately it does end up making the handling of ) slightly easier.

c current character.


答:
JavaScript (ES6), <s>143</s> 135 bytes

Edit: saved 8 bytes thanks to Neil

An implementation using functional programming.

n=>(A=[...Array(n).keys()]).find(k=>k&&!c.some(c=>A.slice(0,k).reduce(y=>y*c%n,1)-1),c=A.filter(x=>(g=(x,y)=>x?g(y%x,x):y)(x,n)==1))||1
```

<h3>Ungolfed and commented</h3>

```n =>                                          // Given a positive integer n:
  (A = [...Array(n).keys()])                  // Build A = [0 ... n-1].
  .find(k =>                                  // Try to find k in [1 ... n-1] such as
    k && !c.some(c =>                         // for each coprime c: c^k ≡ 1 (mod n).
      A.slice(0, k).reduce(y =>               // We use reduce() to compute
        y * c % n, 1                          // c^k mod n.
      ) - 1                                   // Compare it with 1.
    ),                                        // The list of coprimes is precomputed
    c = A.filter(x =>                         // before the find() loop is executed:
      (                                       // for each x in [0 ... n-1], keep
        g = (x, y) => x ? g(y % x, x) : y     // only integers that verify:
      )(x, n) == 1                            // gcd(x, n) = 1
    )                                         // (computed recursively)
  ) || 1                                      // Default result is 1 (for n = 1)
```

<h3>Demo</h3>

<p>Although it does work for <code>6511</code> and <code>10000</code>, I won't include them here as it tends to be a bit slow.</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>let f =
n=>(A=[...Array(n).keys()]).find(k=>k&&!c.some(c=>A.slice(0,k).reduce(y=>y*c%n,1)-1),c=A.filter(x=>(g=(x,y)=>x?g(y%x,x):y)(x,n)==1))||1

console.log(f(1));     // 1
console.log(f(2));     // 1
console.log(f(3));     // 2
console.log(f(10));    // 4
console.log(f(35));    // 12
console.log(f(101));   // 100
console.log(f(530));   // 52
console.log(f(3010));  // 84</code>```

Title: Compute the Carmichael function

Body:
JavaScript (ES6), <s>143</s> 135 bytes

Edit: saved 8 bytes thanks to Neil

An implementation using functional programming.

n=>(A=[...Array(n).keys()]).find(k=>k&&!c.some(c=>A.slice(0,k).reduce(y=>y*c%n,1)-1),c=A.filter(x=>(g=(x,y)=>x?g(y%x,x):y)(x,n)==1))||1

Ungolfed and commented

n =>                                          // Given a positive integer n:
  (A = [...Array(n).keys()])                  // Build A = [0 ... n-1].
  .find(k =>                                  // Try to find k in [1 ... n-1] such as
    k && !c.some(c =>                         // for each coprime c: c^k ≡ 1 (mod n).
      A.slice(0, k).reduce(y =>               // We use reduce() to compute
        y * c % n, 1                          // c^k mod n.
      ) - 1                                   // Compare it with 1.
    ),                                        // The list of coprimes is precomputed
    c = A.filter(x =>                         // before the find() loop is executed:
      (                                       // for each x in [0 ... n-1], keep
        g = (x, y) => x ? g(y % x, x) : y     // only integers that verify:
      )(x, n) == 1                            // gcd(x, n) = 1
    )                                         // (computed recursively)
  ) || 1                                      // Default result is 1 (for n = 1)

Demo

Although it does work for 6511 and 10000, I won't include them here as it tends to be a bit slow.

let f =
n=>(A=[...Array(n).keys()]).find(k=>k&&!c.some(c=>A.slice(0,k).reduce(y=>y*c%n,1)-1),c=A.filter(x=>(g=(x,y)=>x?g(y%x,x):y)(x,n)==1))||1

console.log(f(1));     // 1
console.log(f(2));     // 1
console.log(f(3));     // 2
console.log(f(10));    // 4
console.log(f(35));    // 12
console.log(f(101));   // 100
console.log(f(530));   // 52
console.log(f(3010));  // 84


答:
Templates Considered Harmful, 246 bytes

```<code>Fun<Ap<Fun<If<Eq<A<2>,T>,A<1>,And<Eq<Ap<Fun<If<A<1>,Ap<A<0>,Rem<A<2>,A<1>>,A<1>>,A<2>>>,A<1,1>,A<2>>,T>,Sub<Ap<Fun<Rem<If<A<1>,Mul<A<2,1>,Ap<A<0>,Sub<A<1>,T>>>,T>,A<1,2>>>,A<1>>,T>>,Ap<A<0>,Add<A<1>,T>,A<1,1>>,Ap<A<0>,A<1>,Sub<A<2>,T>>>>,T,A<1>>>
</code>```

An unnamed function (not that there are named functions).

This is a forgotten esolang of mine which is interpreted by a C++ compiler instantiating templates. With the default max template depth of g++, it can do λ(35), but it can't do λ(101) (the lazy evaluation makes things worse).

Title: Compute the Carmichael function

Body:
Templates Considered Harmful, 246 bytes

Fun<Ap<Fun<If<Eq<A<2>,T>,A<1>,And<Eq<Ap<Fun<If<A<1>,Ap<A<0>,Rem<A<2>,A<1>>,A<1>>,A<2>>>,A<1,1>,A<2>>,T>,Sub<Ap<Fun<Rem<If<A<1>,Mul<A<2,1>,Ap<A<0>,Sub<A<1>,T>>>,T>,A<1,2>>>,A<1>>,T>>,Ap<A<0>,Add<A<1>,T>,A<1,1>>,Ap<A<0>,A<1>,Sub<A<2>,T>>>>,T,A<1>>>

An unnamed function (not that there are named functions).

This is a forgotten esolang of mine which is interpreted by a C++ compiler instantiating templates. With the default max template depth of g++, it can do λ(35), but it can't do λ(101) (the lazy evaluation makes things worse).


问:
Tips for golfing in C
What general tips do you have for golfing in C? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to C (e.g. "remove comments" is not an answer). Please post one tip per answer. Also, please include if your tip applies to C89 and/or C99 and if it only works on certain compilers.</p>

答:
Go functional!

If you can reduce your problem to simple functions with the same signature and defined as single expressions, then you can do better than #define r return and factor-out almost all of the boilerplate for defining a function.

```<code>#define D(f,...)f(x){return __VA_ARGS__;}
D(f,x+2)
D(g,4*x-4)
D(main,g(4))
</code>```

Program result is its status value returned to the OS or controlling shell or IDE.

Using __VA_ARGS__ allows you to use the comma operator to introduce sequence points in these function-expressions. If this is not needed, the macro can be shorter.

```<code>#define D(f,b)f(x){return b;}
</code>```

Title: Tips for golfing in C

Body:
Go functional!

If you can reduce your problem to simple functions with the same signature and defined as single expressions, then you can do better than #define r return and factor-out almost all of the boilerplate for defining a function.

#define D(f,...)f(x){return __VA_ARGS__;}
D(f,x+2)
D(g,4*x-4)
D(main,g(4))

Program result is its status value returned to the OS or controlling shell or IDE.

Using __VA_ARGS__ allows you to use the comma operator to introduce sequence points in these function-expressions. If this is not needed, the macro can be shorter.

#define D(f,b)f(x){return b;}


Title: English to Alien translator

Body:
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!

Body:
C 178 bytes

char*p[256],*a="obo\0unu\0ini\0api\0iki\0Obo\0Unu\0Ini\0Api\0Iki",*b="aeiouAEIOU";main(c){for(c=0;b[c];++c)p[b[c]]=a+4*c;for(;(c=getchar())>0;)p[c]?printf("%s",p[c]):putchar(c);}


答:
Pyth, 45 bytes

```<code>AQj.i*hlH]Js.i*hlG\+m*d\-G-mjb*d]XJ"+-""| "Hk
</code>```

A program that takes input of two comma-separated lists on STDIN and prints the result.

There is probably still some golfing to be done here.

Try it online

Explanation coming later

Title: Draw some ASCII-boxes

Body:
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.

Body:
Pyth, 45 bytes

AQj.i*hlH]Js.i*hlG\+m*d\-G-mjb*d]XJ"+-""| "Hk

A program that takes input of two comma-separated lists on STDIN and prints the result.

There is probably still some golfing to be done here.

Try it online

Explanation coming later


问:
Misconstrued Monomials
There exists an equation, assuming n and x are positive,

that expresses the relationship between two monomials, one being a common misrepresentation of the other. Many people make the simple mistake of equating these (i.e. 3x^2 and (3x)^2).

Challenge

Given a positive integer, i, determine and return the solution n and x with the smallest sum as an array [n, x]. In the case of a tie, any solution set is acceptable.

Test Cases

```<code>62658722541234765
[15, 11]

202500
[4, 15]

524288
[8, 4]

33044255768277
[13, 9]
</code>```

答:
Perl, 52 bytes

Includes +2 for -ap

Give input on STDIN

```<code>mono.pl <<< 33044255768277
</code>```

mono.pl:

```<code>#!/usr/bin/perl -ap
$_=("@F"/++$.)**(1/$.)while!/\./?$\="$. $_":$_>2}{
</code>```

Took some effort to make it work for 1 too. I have no idea if floating point errors can make this return the wrong answer for some inputs.

Title: Misconstrued Monomials

Body:
Perl, 52 bytes

Includes +2 for -ap

Give input on STDIN

mono.pl <<< 33044255768277

mono.pl:

#!/usr/bin/perl -ap
$_=("@F"/++$.)**(1/$.)while!/\./?$\="$. $_":$_>2}{

Took some effort to make it work for 1 too. I have no idea if floating point errors can make this return the wrong answer for some inputs.


问:
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:
C, 73 bytes

i;f(w,h){for(i=++w*h;i--;)putchar(i%w?~-i%w%~-~-w?i/w%~-h?32:45:124:10);}


问:
Round to n Sig Figs

Challenge

Given a number x and a number n, round number x to n significant figures and output the result.

Significant figures

The significant figures of a number are digits that carry meaning contributing to its measurement resolution. This includes all numbers except leading zeroes.

Bear in mind that leading zeroes after a decimal point are still insignificant figures.

When rounding a digit, you must round away from zero if the following digit is greater or equal than five.

All trailing zeroes after a decimal point are counted as significant.

Input

The first number will be x, the number to be rounded. The second number will be n, the number of significant figures you should round x to.

x will be a number (your code should handle both integers and floating points) between -1,000,000,000 and 1,000, 000,000 inclusive. n will be a positive integer between 1 and 50 inclusive. n will never be greater than the nunber of digits in x.

The input will never be 0 or any form of 0, e.g. 0.000 or 000.

Examples

```<code>Inputs: 2.6754, 2
Output: 2.7
</code>```

An output of 2.7000 would be invalid because the trailing zeroes after the decimal point are counted as significant figures.

```<code>Inputs: 0.00034551, 4
Output: 0.0003455
</code>```

```<code>Inputs: 50237.1238, 3
Output: 50200
</code>```

Note that this must not have a decimal point.

```<code>Inputs: 2374905, 1
Output: 2000000
</code>```

```<code>Inputs: 543.0489, 4
Output: 543.0
</code>```

```<code>Inputs: 15, 1
Output: 20
</code>```

```<code>Inputs: 520.3, 3
Output: 520
</code>```

If you wish, you can output 520. instead but not 520.0.

```<code>Inputs: -53.87, 2
Output: -54
</code>```

```<code>Inputs: 0.0999, 2
Output: 0.10
</code>```

Rules

Built-in functions and libraries which allow you to round a number to n significant figures are disallowed.

Winning

The shortest code in bytes wins.

答:
Batch, <s>660</s> 652 bytes

```<code>@echo off
set m=%1.
set s=
if %m:~,1%==- set s=-&set m=%m:~1%
:m
if %m:~,1%==0 set m=%m:~1%&goto m
set d=%m:.=%
:d
if %d:~,1%==0 set d=%d:~1%&goto d
for /l %%i in (1,1,%2) do call set d=%%d%%0
call set r=%%d:~%2,1%%
call set d=%%d:~,%2%%
if %r% leq 4 goto r
set r=
:i
set/ai=1+%d:~-1%
set r=%i:~-1%%r%
set d=%d:~,-1%
if %i% leq 9 set d=%d%%r%&goto r
if not "%d%"=="" goto i
set d=1%r:~1%
set m=1%m%
set m=%m:1.0=.%
:r
if %m:~,2%==.0 set m=%m:.0=.%&set d=0%d%&goto r
set i=0
set p=.
:l
if %m:~,1%==. echo %s%%i%%p%%d%&exit/b
if %i%==0 set i=
if "%d%"=="" set d=0&set p=
set i=%i%%d:~,1%
set d=%d:~1%
set m=%m:~1%
goto l
</code>```

Explanation: Starts by suffixing a . to the parameter in case it doesn't have one already, then trims off the sign (which is saved) and any leading zeros. The resulting variable m is saved for later because it will tell us the desired magnitude of the result. Any .s are then removed, which could result in further leading zeros, so they are removed too. n zeros are suffixed to ensure that there are enough digits to round, then the nth and first n digits are extracted. If the nth digit is not 4 or less then we tediously add 1 to the string. If the string overflows then we increase the magnitude by prefixing a 1, but if it was originally less than 0.1 we do that by removing the 1 we just added and also a 0 after the decimal point. If the magnitude is still less than 1 then we copy the zeros after the decimal point to the result, however if it is 1 or more then we extract the integer portion of the answer, adding extra zeros if necessary to reach the decimal point (which is then deleted as it would show incorrect precision). Finally the sign, integer portion, decimal point and decimal portion are concatenated.

Title: Round to n Sig Figs

Body:
Batch, <s>660</s> 652 bytes

@echo off
set m=%1.
set s=
if %m:~,1%==- set s=-&set m=%m:~1%
:m
if %m:~,1%==0 set m=%m:~1%&goto m
set d=%m:.=%
:d
if %d:~,1%==0 set d=%d:~1%&goto d
for /l %%i in (1,1,%2) do call set d=%%d%%0
call set r=%%d:~%2,1%%
call set d=%%d:~,%2%%
if %r% leq 4 goto r
set r=
:i
set/ai=1+%d:~-1%
set r=%i:~-1%%r%
set d=%d:~,-1%
if %i% leq 9 set d=%d%%r%&goto r
if not "%d%"=="" goto i
set d=1%r:~1%
set m=1%m%
set m=%m:1.0=.%
:r
if %m:~,2%==.0 set m=%m:.0=.%&set d=0%d%&goto r
set i=0
set p=.
:l
if %m:~,1%==. echo %s%%i%%p%%d%&exit/b
if %i%==0 set i=
if "%d%"=="" set d=0&set p=
set i=%i%%d:~,1%
set d=%d:~1%
set m=%m:~1%
goto l

Explanation: Starts by suffixing a . to the parameter in case it doesn't have one already, then trims off the sign (which is saved) and any leading zeros. The resulting variable m is saved for later because it will tell us the desired magnitude of the result. Any .s are then removed, which could result in further leading zeros, so they are removed too. n zeros are suffixed to ensure that there are enough digits to round, then the nth and first n digits are extracted. If the nth digit is not 4 or less then we tediously add 1 to the string. If the string overflows then we increase the magnitude by prefixing a 1, but if it was originally less than 0.1 we do that by removing the 1 we just added and also a 0 after the decimal point. If the magnitude is still less than 1 then we copy the zeros after the decimal point to the result, however if it is 1 or more then we extract the integer portion of the answer, adding extra zeros if necessary to reach the decimal point (which is then deleted as it would show incorrect precision). Finally the sign, integer portion, decimal point and decimal portion are concatenated.


答:
C, 35 characters

```<code>main(){for(;;)*(int*)alloca(1)=0;}
</code>```

Title: Shortest program that throws StackOverflow Error

Body:
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.

Body:
C, 35 characters

main(){for(;;)*(int*)alloca(1)=0;}


答:
J, <s>44</s> <s>39</s> <s>38</s> 37 bytes

```<code>' _'{~0&>_&(]|.)(,:1)1&(,],.0&*,.])~|
</code>```

Uses iteration to build the next set starting with 1 (representing _) initially.

Usage

```<code>   f =: ' _'{~0&>_&(]|.)(,:1)1&(,],.0&*,.])~|
   f 0
_
   f 1
___
_ _
   f _1
_ _
___
   f 2
_________
___   ___
_ _   _ _
   f _2
_ _   _ _
___   ___
_________
   f 3
___________________________
_________         _________
___   ___         ___   ___
_ _   _ _         _ _   _ _
   f _3
_ _   _ _         _ _   _ _
___   ___         ___   ___
_________         _________
___________________________
</code>```

Explanation

```<code>' _'{~0&>_&(]|.)(,:1)1&(,],.0&*,.])~|  Input: integer n
                                    |  Absolute value of n
                (,:1)                  The array [1]
                     1&(          )~   Repeat abs(n) times starting with x = [1]
                                 ]       Identity function, gets x
                            0&*          Multiply x by 0
                               ,.        Join the rows together
                         ]               Identity function, gets x
                          ,.             Join the rows together
                     1  ,                Prepend a row of 1's and return
      0&>                              Test if n is negative, 1 if true else 0
         _&(   )                       If n is negative
             |.                          Reverse the previous result
            ]                            Return that
                                       Else pass the previous result unmodified
' _'                                   The string ' _'
    {~                                 Select from the string using the result
                                       as indices and return
</code>```

Title: Print a Cantor Set

Body:
The Challenge

Build a N-Leveled Cantor Set.

The Cantor ternary set is created by repeatedly deleting the open
  middle thirds of a set of line segments.

The program receives one parameter N (a integer number) and then prints (in console or similar way) a Cantor Set of N levels. The print can only contain undescore (_) and whithe spaces characters. The parameter can be positive or negative and the sign indicates the Cantor Set construction orientation: If N > 0 the Cantor Set is constructed downwards and if N < 0 the Cantor Set is constructed upwards. If N = 0 then the program prints a single line (_).

For example:

N = 2

```<code>_________
___   ___
_ _   _ _
</code>```

N = -2

```<code>_ _   _ _
___   ___
_________
</code>```

N = 3

```<code>___________________________
_________         _________
___   ___         ___   ___
_ _   _ _         _ _   _ _
</code>```

N = -3

```<code>_ _   _ _         _ _   _ _
___   ___         ___   ___
_________         _________
___________________________
</code>```

Winning criteria

As it is a code golf challenge, the shortest code wins.

Edited: Modify 0 input by ugoren's suggestion.

Body:
J, <s>44</s> <s>39</s> <s>38</s> 37 bytes

' _'{~0&>_&(]|.)(,:1)1&(,],.0&*,.])~|

Uses iteration to build the next set starting with 1 (representing _) initially.

Usage

   f =: ' _'{~0&>_&(]|.)(,:1)1&(,],.0&*,.])~|
   f 0
_
   f 1
___
_ _
   f _1
_ _
___
   f 2
_________
___   ___
_ _   _ _
   f _2
_ _   _ _
___   ___
_________
   f 3
___________________________
_________         _________
___   ___         ___   ___
_ _   _ _         _ _   _ _
   f _3
_ _   _ _         _ _   _ _
___   ___         ___   ___
_________         _________
___________________________

Explanation

' _'{~0&>_&(]|.)(,:1)1&(,],.0&*,.])~|  Input: integer n
                                    |  Absolute value of n
                (,:1)                  The array [1]
                     1&(          )~   Repeat abs(n) times starting with x = [1]
                                 ]       Identity function, gets x
                            0&*          Multiply x by 0
                               ,.        Join the rows together
                         ]               Identity function, gets x
                          ,.             Join the rows together
                     1  ,                Prepend a row of 1's and return
      0&>                              Test if n is negative, 1 if true else 0
         _&(   )                       If n is negative
             |.                          Reverse the previous result
            ]                            Return that
                                       Else pass the previous result unmodified
' _'                                   The string ' _'
    {~                                 Select from the string using the result
                                       as indices and return