答:
Labyrinth, 20 bytes

Thanks to Sp3000 for some help while golfing this.

```<code><""-}:?:?
"`
{
++(!@
</code>```

Try it online!

Explanation

It turns out that the 2*min(a,b)-1 approach isn't the shortest in Labyrinth. Instead it's easier to compute (a+b)-|a-b|-1.

Labyrinth primer:

Labyrinth has two stacks of arbitrary-precision integers, main and aux(iliary), which are initially filled with an (implicit) infinite amount of zeros. I will usually represent these like Main [... a b | c d ...] Aux, where Main grows to the right, Aux grows to the left and ... represents the implicit zeros at the bottom.

The source code resembles a maze, where the instruction pointer (IP) follows corridors when it can (even around corners). The code starts at the first valid character in reading order, i.e. in the top left corner in this case. When the IP comes to any form of junction (i.e. several adjacent cells in addition to the one it came from), it will pick a direction based on the top of the main stack. The basic rules are: turn left when negative, keep going ahead when zero, turn right when positive. And when one of these is not possible because there's a wall, then the IP will take the opposite direction. The IP also turns around when hitting dead ends.

The source code can be modified at runtime using <>^v which cyclically shift a row or column of the grid.

The code starts on the < which immediately modifies the source code. This is a common golfing trick in Labyrinth whenever a program starts with a long-ish bit of linear code. Afterwards, the source looks like this, with the IP still on the <:

```<code>""-}:?:?<
"`
{
++(!@
</code>```

Since the IP is now in a dead end, it has to start moving left. The linear code does the following:

```<code>Op      Explanation                    Stacks
?       Read integer a from STDIN.     Main [... a | ...] Aux
:       Duplicate.                     Main [... a a | ...] Aux
?       Read integer b from STDIN.     Main [... a a b | ...] Aux
:       Duplicate.                     Main [... a a b b | ...] Aux
}       Move b over to aux.            Main [... a a b | b ...] Aux
-       Subtract b from a on main.     Main [... a (a-b) | b ...] Aux
</code>```

The code now enters the only nonlinear part of the code which compues -abs(x), (where I'm now using < and v to indicate entry and exit points):

```<code>""<
"`
v
</code>```

The " is a no-op (i.e. it does nothing), whereas the ` multiplies the top of the main stack by -1. Let's go through the three possible cases of control flow:

If a == b, i.e. a-b is zero, the IP keeps moving west on the first ". Then it hits a corner on the the second " and has to turn south. Again, it keeps moving south on the third " and leaves this 2x2 block. All in all, nothing happens to zeros at all.

If a > b, i.e. a-b is positive, the IP turns south on the first ". The ` then switches the top of the main stack to b-a and the IP has to take a turn west. On the next " the top of the stack is now negative, and the IP turns south. Therefore, if the top of the stack is positive, its sign will be negated by this block.

If a < b, i.e. a-b is negative, then the IP also turns towards the `</code> , which now makes it positive. That means the IP turns <em>north</em> on the next no-op. It hits the corner and turns east, and turns south once more so that it reaches the <code>` a second time. At this point, the control flow is no different from a positive input, so after applying ` twice, we're back at a-b which is negative and leaves the loop. Despite doing a lot more stuff, negative inputs are also unaffected by this part of the code.

Now that we've computed -abs(a-b), the remainder of the code is all linear again:

```<code>Op      Explanation                    Stacks
                                       [... a -|a-b| | b ...]
{       Move b back to main.           [... a -|a-b| b | ...]
+       Add.                           [... a (-|a-b|+b) | ...]
+       Add.                           [... (a+b-|a-b|) | ...]
(       Decrement.                     [... (a+b-|a-b|-1) | ...]
!       Print as integer.              [... | ...]
@       Terminate program.
</code>```

Body:
Mary has given John two sticks of lengths a and b respectively, where a and b are positive integers.

John is very curious.

He would like to know how many triangles with integer perimeter can be formed, by having one additional side.

Please help him find it out.

(This is my first time composing this kind of stupid stories in coding problems, so forgive me if it is too stupid.)

Specs

Given two integers a and b, find the number of triangles with integer perimeter that can be formed, by having one additional side.

Details

Congruent triangles are congruent.

Flat triangles are flat out uncounted.

Zero-sided triangles are counted zero times.

Scoring

This is code-golf. Shortest solution in bytes wins.

Testcases

```<code>a b output
1 2 1
3 3 5
9 7 13
</code>```

Body:
Labyrinth, 20 bytes

Thanks to Sp3000 for some help while golfing this.

<""-}:?:?
"`
{
++(!@

Try it online!

Explanation

It turns out that the 2*min(a,b)-1 approach isn't the shortest in Labyrinth. Instead it's easier to compute (a+b)-|a-b|-1.

Labyrinth primer:

Labyrinth has two stacks of arbitrary-precision integers, main and aux(iliary), which are initially filled with an (implicit) infinite amount of zeros. I will usually represent these like Main [... a b | c d ...] Aux, where Main grows to the right, Aux grows to the left and ... represents the implicit zeros at the bottom.

The source code resembles a maze, where the instruction pointer (IP) follows corridors when it can (even around corners). The code starts at the first valid character in reading order, i.e. in the top left corner in this case. When the IP comes to any form of junction (i.e. several adjacent cells in addition to the one it came from), it will pick a direction based on the top of the main stack. The basic rules are: turn left when negative, keep going ahead when zero, turn right when positive. And when one of these is not possible because there's a wall, then the IP will take the opposite direction. The IP also turns around when hitting dead ends.

The source code can be modified at runtime using <>^v which cyclically shift a row or column of the grid.

The code starts on the < which immediately modifies the source code. This is a common golfing trick in Labyrinth whenever a program starts with a long-ish bit of linear code. Afterwards, the source looks like this, with the IP still on the <:

""-}:?:?<
"`
{
++(!@

Since the IP is now in a dead end, it has to start moving left. The linear code does the following:

Op      Explanation                    Stacks
?       Read integer a from STDIN.     Main [... a | ...] Aux
:       Duplicate.                     Main [... a a | ...] Aux
?       Read integer b from STDIN.     Main [... a a b | ...] Aux
:       Duplicate.                     Main [... a a b b | ...] Aux
}       Move b over to aux.            Main [... a a b | b ...] Aux
-       Subtract b from a on main.     Main [... a (a-b) | b ...] Aux

The code now enters the only nonlinear part of the code which compues -abs(x), (where I'm now using < and v to indicate entry and exit points):

""<
"`
v

The " is a no-op (i.e. it does nothing), whereas the ` multiplies the top of the main stack by -1. Let's go through the three possible cases of control flow:

If a == b, i.e. a-b is zero, the IP keeps moving west on the first ". Then it hits a corner on the the second " and has to turn south. Again, it keeps moving south on the third " and leaves this 2x2 block. All in all, nothing happens to zeros at all.

If a > b, i.e. a-b is positive, the IP turns south on the first ". The ` then switches the top of the main stack to b-a and the IP has to take a turn west. On the next " the top of the stack is now negative, and the IP turns south. Therefore, if the top of the stack is positive, its sign will be negated by this block.

If a < b, i.e. a-b is negative, then the IP also turns towards the `</code> , which now makes it positive. That means the IP turns <em>north</em> on the next no-op. It hits the corner and turns east, and turns south once more so that it reaches the <code>` a second time. At this point, the control flow is no different from a positive input, so after applying ` twice, we're back at a-b which is negative and leaves the loop. Despite doing a lot more stuff, negative inputs are also unaffected by this part of the code.

Now that we've computed -abs(a-b), the remainder of the code is all linear again:

Op      Explanation                    Stacks
                                       [... a -|a-b| | b ...]
{       Move b back to main.           [... a -|a-b| b | ...]
+       Add.                           [... a (-|a-b|+b) | ...]
+       Add.                           [... (a+b-|a-b|) | ...]
(       Decrement.                     [... (a+b-|a-b|-1) | ...]
!       Print as integer.              [... | ...]
@       Terminate program.


问:
Am I happy or sad?
You are trying to guess my emotion.

I will give you an adjective, as the input to the function/program.

Your task is to output my emotion, either :) for happy, or :( for sad.

Details

For these adjectives, you must output the happy face :)

```<code>contented
delighted
merry
overjoyed
pleased
blessed
chipper
content
convivial
gleeful
gratified
intoxicated
jolly
light
peppy
perky
playful
sparkling
sunny
</code>```

For these adjectives, you must output the sad face :(

```<code>melancholy
bitter
somber
dismal
mournful
blue
dejected
despairing
despondent
disconsolate
distressed
down
downcast
gloomy
glum
heavyhearted
lugubrious
morbid
morose
troubled
bereaved
</code>```

Other adjectives are undefined. You may output whatever you want for other adjectives.

Specs

All in lowercase. All matches regex ^[a-z]+$.

Scoring

This is code-golf. Shortest solution in bytes wins.

Tips

There is a trick.

答:
Labyrinth, 14 bytes

```<code>4
1
#$
;,98..@
</code>```

Try it online!

Explanation

Labyrinth primer:

Labyrinth has two stacks of arbitrary-precision integers, main and aux(iliary), which are initially filled with an (implicit) infinite amount of zeros.

The source code resembles a maze, where the instruction pointer (IP) follows corridors when it can (even around corners). The code starts at the first valid character in reading order, i.e. in the top left corner in this case. When the IP comes to any form of junction (i.e. several adjacent cells in addition to the one it came from), it will pick a direction based on the top of the main stack. The basic rules are: turn left when negative, keep going ahead when zero, turn right when positive. And when one of these is not possible because there's a wall, then the IP will take the opposite direction. The IP also turns around when hitting dead ends.

Digits are processed by multiplying the top of the main stack by 10 and then adding the digit. If the top of the stack is negative, the digit is subtracted instead.

The code starts in the top left corner, with the IP moving south. The 41 simply turns the top 0 on the main stack into 41, the character code of ).

We now enter a 2x2 (clockwise) loop which reads one character at a time, and toggles the top of the stack between 40 (() and 41 ()):

```<code>#   Push the stack depth, which is 1.
$   XOR the top two values on the stack, toggling between 40 and 41.
,   Read a character (positive value) or -1 at EOF. At EOF, we exit the loop.
;   Discard the character.
</code>```

At the end of the loop, the main stack has the correct character code for either ( or ) and a -1 on top of that. The rest of the code is linear.

```<code>98  Turn the -1 on top of the stack into -198.
.   Print the top of the stack, modulo 256. -198 % 256 == 58, the character
    code of ':'.
.   Print the top of the stack, i.e. the mouth of the emoticon.
@   Terminate the program.
</code>```

ContentLicense: CC BY-SA 3.0

Title: Am I happy or sad?

Body:
Labyrinth, 14 bytes

4
1
#$
;,98..@

Try it online!

Explanation

Labyrinth primer:

Labyrinth has two stacks of arbitrary-precision integers, main and aux(iliary), which are initially filled with an (implicit) infinite amount of zeros.

The source code resembles a maze, where the instruction pointer (IP) follows corridors when it can (even around corners). The code starts at the first valid character in reading order, i.e. in the top left corner in this case. When the IP comes to any form of junction (i.e. several adjacent cells in addition to the one it came from), it will pick a direction based on the top of the main stack. The basic rules are: turn left when negative, keep going ahead when zero, turn right when positive. And when one of these is not possible because there's a wall, then the IP will take the opposite direction. The IP also turns around when hitting dead ends.

Digits are processed by multiplying the top of the main stack by 10 and then adding the digit. If the top of the stack is negative, the digit is subtracted instead.

The code starts in the top left corner, with the IP moving south. The 41 simply turns the top 0 on the main stack into 41, the character code of ).

We now enter a 2x2 (clockwise) loop which reads one character at a time, and toggles the top of the stack between 40 (() and 41 ()):

#   Push the stack depth, which is 1.
$   XOR the top two values on the stack, toggling between 40 and 41.
,   Read a character (positive value) or -1 at EOF. At EOF, we exit the loop.
;   Discard the character.

At the end of the loop, the main stack has the correct character code for either ( or ) and a -1 on top of that. The rest of the code is linear.

98  Turn the -1 on top of the stack into -198.
.   Print the top of the stack, modulo 256. -198 % 256 == 58, the character
    code of ':'.
.   Print the top of the stack, i.e. the mouth of the emoticon.
@   Terminate the program.


答:
Reng v.3.3, 12 bytes

```<code>":("k2,+roo~
</code>```

This puts 58, 40 on the stack, gets the length of the input stack, 2, modulos by 2, + adds it to the (, r reverses, oo outputs two characters, and ~ terminates the program. Try it here! Input is like "somber". I don't think we need a GIF for this ;)

Title: Am I happy or sad?

Body:
You are trying to guess my emotion.

I will give you an adjective, as the input to the function/program.

Your task is to output my emotion, either :) for happy, or :( for sad.

Details

For these adjectives, you must output the happy face :)

```<code>contented
delighted
merry
overjoyed
pleased
blessed
chipper
content
convivial
gleeful
gratified
intoxicated
jolly
light
peppy
perky
playful
sparkling
sunny
</code>```

For these adjectives, you must output the sad face :(

```<code>melancholy
bitter
somber
dismal
mournful
blue
dejected
despairing
despondent
disconsolate
distressed
down
downcast
gloomy
glum
heavyhearted
lugubrious
morbid
morose
troubled
bereaved
</code>```

Other adjectives are undefined. You may output whatever you want for other adjectives.

Specs

All in lowercase. All matches regex ^[a-z]+$.

Scoring

This is code-golf. Shortest solution in bytes wins.

Tips

There is a trick.

Body:
Reng v.3.3, 12 bytes

":("k2,+roo~

This puts 58, 40 on the stack, gets the length of the input stack, 2, modulos by 2, + adds it to the (, r reverses, oo outputs two characters, and ~ terminates the program. Try it here! Input is like "somber". I don't think we need a GIF for this ;)


答:
05AB1E, 10 bytes

Code:

```<code>':žuâ`¹gÉ@
</code>```

Dammit, also 10 bytes: gÉ40+ç':sJ.

Uses CP-1252 encoding. Try it online!.

Title: Am I happy or sad?

Body:
05AB1E, 10 bytes

Code:

':žuâ`¹gÉ@

Dammit, also 10 bytes: gÉ40+ç':sJ.

Uses CP-1252 encoding. Try it online!.


答:
JavaScript ES6, 23 bytes

```<code>x=>":"+"()"[x.length%2]
</code>```

Simple anonymous function.

Test

f = x => ":" + "()" [x.length % 2];
makeRow = (x, y) => t.innerHTML += `<tr><td>${x}</td><td>${y}</td></tr>`;
`contented
delighted
merry
overjoyed
pleased
blessed
chipper
content
convivial
gleeful
gratified
intoxicated
jolly
light
peppy
perky
playful
sparkling
sunny`.split(`\n`).forEach(e => makeRow(e, f(e)));

t.innerHTML += "
Sad cases
";

`melancholy
bitter
somber
dismal
mournful
blue
dejected
despairing
despondent
disconsolate
distressed
down
downcast
gloomy
glum
heavyhearted
lugubrious
morbid
morose
troubled
bereaved`.split(`\n`).forEach(e => makeRow(e, f(e)));```
<pre class="snippet-code-css lang-css prettyprint-override"><code>html {
  font-family: Consolas, monospace;
}
table {
  border-collapse: collapse;
}
td,
th {
  padding: 10px;
  border: 1px solid;
}</code>```

    Word
    Output

    Happy cases

```

Title: Am I happy or sad?

Body:
JavaScript ES6, 23 bytes

x=>":"+"()"[x.length%2]

Simple anonymous function.

Test

f = x => ":" + "()" [x.length % 2];
makeRow = (x, y) => t.innerHTML += `<tr><td>${x}</td><td>${y}</td></tr>`;
`contented
delighted
merry
overjoyed
pleased
blessed
chipper
content
convivial
gleeful
gratified
intoxicated
jolly
light
peppy
perky
playful
sparkling
sunny`.split(`\n`).forEach(e => makeRow(e, f(e)));

t.innerHTML += "<tr><th colspan=2>Sad cases</th></tr>";

`melancholy
bitter
somber
dismal
mournful
blue
dejected
despairing
despondent
disconsolate
distressed
down
downcast
gloomy
glum
heavyhearted
lugubrious
morbid
morose
troubled
bereaved`.split(`\n`).forEach(e => makeRow(e, f(e)));

html {
  font-family: Consolas, monospace;
}
table {
  border-collapse: collapse;
}
td,
th {
  padding: 10px;
  border: 1px solid;
}

<table id="t">
  <tr>
    <th>Word</th>
    <th>Output</th>
  </tr>
  <tr>
    <th colspan=2>Happy cases</th>
  </tr>
</table>


问:
Polygonal numbers
A polygonal number is the number of dots in a k-gon of size n.

You will be given n and k, and your task is to write a program/function that outputs/prints the corresponding number.

Scoring

This is code-golf. Shortest solution in bytes wins.

Example

The 3rd hexagon number (k=6, n=3) is 28 because there are 28 dots above.

Testcases

Can be generated from this Pyth test suite.

Usage: two lines per testcase, n above, k below.

```<code>n    k  output
10   3  55
10   5  145
100  3  5050
1000 24 10990000
</code>```

Further information

In Wikipedia: https://en.wikipedia.org/wiki/Polygonal_number

In Wolfram Mathworld: http://mathworld.wolfram.com/PolygonalNumber.html

In OEIS Wiki: http://oeis.org/wiki/Polygonal_numbers

OEIS sequences for n-gonal numbers for various n: 3 (A000217), 4 (A000290), 5 (A000326), 6 (A000384), 7 (A000566), 8 (A000567), 9 (A001106), 10 (A001107), 11 (A051682), 12 (A051624), 13 (A051865), 14 (A051866), 15 (A051867), 16 (A051868), 17 (A051869), 18 (A051870), 19 (A051871), 20 (A051872), 21 (A051873), 22 (A051874), 23 (A051875), 24 (A051876)

答:
CJam, 13 bytes

```<code>q~__(*2/@2-*+
</code>```

Try it online

Title: Polygonal numbers

Body:
CJam, 13 bytes

q~__(*2/@2-*+

Try it online


答:
Jelly, 8 bytes

Code:

```<code>”:³Lị“)(
</code>```

Explanation:

```<code>”:         # The ":" character
  ³L       # Get the length of the input
    ị“)(   # Find the index of the length in the ")(" string.
           # Uses cyclic indexing for indices exceeding the length of the string.
</code>```

Uses the Jelly-encoding.

Try it online!.

Title: Am I happy or sad?

Body:
Jelly, 8 bytes

Code:

”:³Lị“)(

Explanation:

”:         # The ":" character
  ³L       # Get the length of the input
    ị“)(   # Find the index of the length in the ")(" string.
           # Uses cyclic indexing for indices exceeding the length of the string.

Uses the Jelly-encoding.

Try it online!.


问:
Find the n-th perfect power!
A perfect power is a number of the form \$a^b\$, where \$a>0\$ and \$b>1\$.

For example, \$125\$ is a perfect power because it can be expressed as \$5^3\$.

Goal

Your task is to write  a program/function that finds the \$n\$-th perfect power, given a positive integer \$n\$.

Specs

The first perfect power is \$1\$ (which is \$1^2\$).

Input/output in any reasonable format.

Built-ins are allowed.

Further information

OEIS A001597

Scoring

This is code-golf. Shortest solution in bytes wins.

Testcases

```<code>input  output
1      1
2      4
3      8
4      9
5      16
6      25
7      27
8      32
9      36
10     49
</code>```

答:
Sage (version 6.4, probably also others): <s>64</s> 63

```<code>lambda n:[k for k in range(1+n^2)if(0+k).is_perfect_power()][n]
</code>```

Creates a lambda function that returns nth perfect power. We rely on the fact that it is found within the first n^2 integers. (The 1+n^2 is necessary for n=1,2. The 0+k bit is necessary to convert int(k) to Integer(k).)

Byte off for xrange->range, thanks Dennis.

Just a fun fact: 0 is a perfect power by Sage's standards, fortunately, because then 1 is the 1st element of the list, not 0th :)

ContentLicense: CC BY-SA 4.0

Title: Find the n-th perfect power!

Body:
Sage (version 6.4, probably also others): <s>64</s> 63

lambda n:[k for k in range(1+n^2)if(0+k).is_perfect_power()][n]

Creates a lambda function that returns nth perfect power. We rely on the fact that it is found within the first n^2 integers. (The 1+n^2 is necessary for n=1,2. The 0+k bit is necessary to convert int(k) to Integer(k).)

Byte off for xrange->range, thanks Dennis.

Just a fun fact: 0 is a perfect power by Sage's standards, fortunately, because then 1 is the 1st element of the list, not 0th :)


答:
Jelly, 7 bytes

```<code>’;’;PH+
</code>```

This uses the formula

to compute the nth s-gonal number.

Try it online!

How it works

```<code>’;’;PH+  Main link. Arguments: s, n

’        Decrement; yield s - 1.
 ;       Concatenate; yield [s - 1, n].
  ’      Decrement; yield [s - 2, n - 1].
   ;     Concatenate; yield [s - 2, n - 1, n].
    P    Product; yield (s - 2)(n - 1)n.
     H   Halve; yield (s - 2)(n - 1)n ÷ 2.
      +  Add; yield (s - 2)(n - 1)n ÷ 2 + n.
</code>```

Title: Polygonal numbers

Body:
A polygonal number is the number of dots in a k-gon of size n.

You will be given n and k, and your task is to write a program/function that outputs/prints the corresponding number.

Scoring

This is code-golf. Shortest solution in bytes wins.

Example

The 3rd hexagon number (k=6, n=3) is 28 because there are 28 dots above.

Testcases

Can be generated from this Pyth test suite.

Usage: two lines per testcase, n above, k below.

```<code>n    k  output
10   3  55
10   5  145
100  3  5050
1000 24 10990000
</code>```

Further information

In Wikipedia: https://en.wikipedia.org/wiki/Polygonal_number

In Wolfram Mathworld: http://mathworld.wolfram.com/PolygonalNumber.html

In OEIS Wiki: http://oeis.org/wiki/Polygonal_numbers

OEIS sequences for n-gonal numbers for various n: 3 (A000217), 4 (A000290), 5 (A000326), 6 (A000384), 7 (A000566), 8 (A000567), 9 (A001106), 10 (A001107), 11 (A051682), 12 (A051624), 13 (A051865), 14 (A051866), 15 (A051867), 16 (A051868), 17 (A051869), 18 (A051870), 19 (A051871), 20 (A051872), 21 (A051873), 22 (A051874), 23 (A051875), 24 (A051876)

Body:
Jelly, 7 bytes

’;’;PH+

This uses the formula

to compute the nth s-gonal number.

Try it online!

How it works

’;’;PH+  Main link. Arguments: s, n

’        Decrement; yield s - 1.
 ;       Concatenate; yield [s - 1, n].
  ’      Decrement; yield [s - 2, n - 1].
   ;     Concatenate; yield [s - 2, n - 1, n].
    P    Product; yield (s - 2)(n - 1)n.
     H   Halve; yield (s - 2)(n - 1)n ÷ 2.
      +  Add; yield (s - 2)(n - 1)n ÷ 2 + n.


问:
Find the program that prints this integer sequence (Cops' thread)
This is the cops' thread. The robbers' thread goes here.

The last cops-and-robbers thread was already 4 months ago.

The cop's task

The cop's task is to write a program/function that takes a positive (or non-negative) integer and outputs/returns another integer.

The cop must state it if the program is intolerant towards zero.

The cop will provide at least 2 sample inputs/outputs.

For example, if I have decided to write the Fibonacci sequence, I would write this in my answer:

```
a(0) returns 0
a(3) returns 2
```

The number of examples is up to the cop's discretion.

However, the sequence must actually exist in the On-Line Encyclopedia of Integer Sequences®, so no pseudo-random number generator for you. :(

The cop can hide as many characters as is so wished.

For example, if my program is:

```<code>function a(n)
    if n>2 then
        return n
    else
        return a(n-1) + a(n-2)
    end
end
</code>```

Then I would hide these characters as I want:

```<code>function a(n)
    if ### then
        ########
    else
        ######################
    end
end
</code>```

The robber's task

is obviously to find the original source code.

However, any proposed source code that produces the same set of output also counts as valid, as long as it is also found in OEIS.

Tips for the cops

<s>The search function in the OEIS only works for consecutive terms, so if you want to hide your sequence, then just leave a hole anywhere.</s>

Apparently there is no way to hide the sequence. Put this in mind when you choose the sequence.

Your score is the number of bytes in your code.

The winner will be the submission with the lowest score that hasn't been cracked in 7 days.

Only submissions that are posted in 2016 April are eligible for the win. Submissions that are posted later than this are welcome, but cannot win.

In order to claim the win you need to reveal the full code and the OEIS sequence (after 7 days).

Your post should be formatted like this (NN is the number of characters):

Lua, 98 bytes

Output:

```<code>a(0) returns 0
a(3) returns 2
</code>```

Code (# marks unrevealed characters):

```<code>function a(n)
    if ### then
        ########
    else
        ######################
    end
end
</code>```

If the code is cracked, insert [Cracked](link to cracker) in the header.
If the submission is safe, insert "Safe" in the header and reveal the full code in your answer. Only answers that have revealed the full code will be eligible for the win.

Body:
Python 3, 58 Bytes, Cracked

# marks unrevealed chars.

import math;x=int(input());print(int(x/math.####(#)*#**#))

If x < 1, it will not work.

in    out
1     0
4     457
7     2578097
10    44721359549
13    1760848250285208
16    131994155879539032064
19    16810747184697114703691776


问:
Build a word generator!
Your task is to create a program/function to replicate this word generator.

Details

Your program/function take two input. One input is the categories. The other input is the syllable types.

Categories

categories will consist of classes of letters.

For example, V=aeiou means that the letters a, e, i, o, and u will be classified under the category V.

Each category will have a 1-letter name in UPPERCASE.

The letters it contains will all be in lowercase.

Syllable types

For example CV would mean that the syllable will consist of a letter in category C and then a letter in category V.

For example, if C=bcd and V=ae, then the syllable can be ba, be, ca, ce, da, or de.

Your task

Your task is to generate 100 random words, each with a random length of 1-5 syllables, each chosen randomly in the syllable types, with the letter in each category chosen also randomly.

Specs

Any reasonable input/output format. I don't care how you input the list.

All inputs will be valid.

Scoring

This is code-golf. Shortest solution in bytes wins.

Testcase

```<code>input1          input2    output
"C=st;V=aeiou"  "CV/CVC"  tasiti tese tossi tesis titi sese saset su sosastesisat sisosis sissa sata to sisas sese satetot sisuta tatote sa tetsesuti sossut ti seso tese tostutsasussi tutiset sasates tasa ta sa satso tastitta tetti sesita setetat tatsi tisetot sassu sessiso satessase sas ses totasta si tetsit titse sase totas sa ta sasesa tasa sostat sesi sissa tato tos tate sustosussatta sustas sassatote tesas sutat tatetatossos testisot tatta tissisisa sasese sesatus tito sisa satas sasisi so sasatustu sosses tetsa tese sestit sestu tisot sutastot sesu tet sotte sisute setotitsesi tita
</code>```

答:
Haskell, 95 bytes

```<code>import Test.QuickCheck
e=elements
c#s=mapM putStr=<<(generate$resize 5$listOf1$e s>>=mapM(e.c))
</code>```

The categories are passed as a function from Char to String and the syllables types as a list of strings, e.g.

```<code>cat 'C' = "st"
cat 'V' = "aeiou"
syl = ["CV","CVC"]
</code>```

Usage example: cat # syl -> tesat. Or with function/list literals: (\c->case c of 'C' -> "st"; 'V' -> "aeiou") # ["CV","CVC"]. Note: the function prints the generated word to stdout. If you try this within ghci, the return value is also printed, but that's a feature of the REPL and not of my code.

Dealing with random values in a purely functional language like Haskell is usually awkward. Luckily Test.QuickCheck provides some random generators and combinators for them that hide all the nastiness in a monad.

How it works:

```<code>input:
  s: list of syllable types
  c: categories as a function from Char to String

        e s             --  pick a random syllable type from s
           >>=mapM(e.c) --  for each letter: apply c and pick a random letter
                            from the returned string. We now have a random
                            generator for a single syllable
       listOf1          --  make a list of syllables of random length with
                            a minimum of 1
     resize 5           --  limit the maximum size to 5 (the list is not simply
                              cut if it is too long, all lengths are equally likely
   generate             --  run the generator. We now have a list of 1 to 5 syllables
mapM putStr=<<          --  print the syllables.
</code>```

I'm happy that it works at all, maybe there's room for improvement.

Some more examples:

```<code>*Main> mapM_ (\_ -> do (cat#syl) ; putStrLn "" ) [1..10]
sisatassetto
se
ti
taso
sittos
tuttuste
tottu
satutustittes
sutetsetusut
tattatosote
</code>```

Title: Build a word generator!

Body:
Haskell, 95 bytes

import Test.QuickCheck
e=elements
c#s=mapM putStr=<<(generate$resize 5$listOf1$e s>>=mapM(e.c))

The categories are passed as a function from Char to String and the syllables types as a list of strings, e.g.

cat 'C' = "st"
cat 'V' = "aeiou"
syl = ["CV","CVC"]

Usage example: cat # syl -> tesat. Or with function/list literals: (\c->case c of 'C' -> "st"; 'V' -> "aeiou") # ["CV","CVC"]. Note: the function prints the generated word to stdout. If you try this within ghci, the return value is also printed, but that's a feature of the REPL and not of my code.

Dealing with random values in a purely functional language like Haskell is usually awkward. Luckily Test.QuickCheck provides some random generators and combinators for them that hide all the nastiness in a monad.

How it works:

input:
  s: list of syllable types
  c: categories as a function from Char to String

        e s             --  pick a random syllable type from s
           >>=mapM(e.c) --  for each letter: apply c and pick a random letter
                            from the returned string. We now have a random
                            generator for a single syllable
       listOf1          --  make a list of syllables of random length with
                            a minimum of 1
     resize 5           --  limit the maximum size to 5 (the list is not simply
                              cut if it is too long, all lengths are equally likely
   generate             --  run the generator. We now have a list of 1 to 5 syllables
mapM putStr=<<          --  print the syllables.

I'm happy that it works at all, maybe there's room for improvement.

Some more examples:

*Main> mapM_ (\_ -> do (cat#syl) ; putStrLn "" ) [1..10]
sisatassetto
se
ti
taso
sittos
tuttuste
tottu
satutustittes
sutetsetusut
tattatosote


问:
Decompose a number!
Your task is to decompose a number using the format below.

This is similar to base conversion, except that instead of listing the digits in the base, you list the values, such that the list adds up to the input.

If the given base is \$n\$, then each number in the list must be in the form of \$k\times n^m\$, where \$0\le k<n\$ and \$m\$ is unique throughout the list.

Specs

Any reasonable input/output format. Your program/function takes 2 inputs and outputs a list.

Output list can be in any order.

0 can be excluded or included.

Leading 0s are allowed.

Built-ins are allowed.

Testcases

```<code>number base   converted list
input1 input2 output
123456 10     [100000,20000,3000,400,50,6] or [6,50,400,3000,20000,100000]
11     2      [8,2,1] or [0,0,0,0,8,0,2,1]
727    20     [400,320,7]
101    10     [100,1] or [100,0,1]
</code>```

Scoring

This is code-golf. Shortest solution in bytes wins.

答:
O, 17 bytes

```<code>jQb`S/l{#Qn^*p}d
</code>```

Two notes:

The third test case does not work due to a bug with base conversion. See phase/o#68.

This does not work in the online interpreter. b hadn't been implemented yet.

Title: Decompose a number!

Body:
O, 17 bytes

jQb`S/l{#Qn^*p}d

Two notes:

The third test case does not work due to a bug with base conversion. See phase/o#68.

This does not work in the online interpreter. b hadn't been implemented yet.


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

答:
HQ9+

Factoid:

HQ9+ is a joke programming language, invented by Cliff L. Biffle in 2001. It is a golfing language, that has a very small source code for the most common programming exercises, due to its small set of strategic built-ins.

Length 1

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

HQ9+ has a very short quine. The Q built-in prints the source code of the entire program.

Length 2

```<code>9+
</code>```

Speaking about crazy built-ins, HQ9+ is almost comparable to Mathematica. This program prints the entire lyrics of "99 bottles of beer on the wall", before it increments the accumulator and terminates.

Length 3

```<code>9H9
</code>```

Commands can be mixed and matched in any order you want. This program, for instance, takes a break and greats the world between two passes through the already mentioned song "99 bottles of beer on the wall."

Length 4

```<code>HQ9+
</code>```

Yup, The name of the language is actually a syntactically valid program by itself. One thing to notice here is how Q behaves when there are other characters in the program as well. In between hello world and 99 bottles of beer, it prints "HQ9+". While not a quine, the source code is at least part of the output.

Length 5

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

There are no other operations than + that can be applied to the accumulator. Thus, if we want to increase it by five, this is the shortest way to do it. While backwards compatible with HQ9+, the popular object-oriented extension of the language by David Morgan-Mar, HQ9++, is also going to create two new subclasses of the generic superclass if this code is executed. The output is the same though.

Length 6

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

We have seen that HQ9+ is capable of only a limited number of outputs, however, it can still output any information. Using the highest density of information per command (e.g. avoid to increase the accumulator), the flow rate of information is log2(3) bits per command. For many languages, this is not known exactly, but for English text it is assumed to be around 1.3 bits per character, a little less than HQ9+. I have here as an example chosen a tertiary encoding, where the output of the H command here represents a 0, Q represents 1 and 9 represents 2. Using that, the output of the program can be interpreted as "SE" for Stack Exchange.

Length 7

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

Surprisingly many get this one wrong, they think Q prints just a Q. But Each Q actually prints the whole source code of the program, here resulting in

QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ

  (49 of them)

That is a great tool for demonstrating quadratic growth, and make it possible for HQ9+ to be used in surprising ways, like in this answer printing twice the length of the program to STDOUT.

Length 8

```<code>+++Q++++
</code>```

As the + command is effectively a NOP regarding output, a single Q placed anywhere in a string of + can be used to produce a quine of arbitrary length.

Length 9

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

Is this a quine or not? That depends on the interpreter used. It is not very clear in the specification if invalid characters should be ignored or not. In the interpreters that do ignore such characters, this is proper quine. Others just throw an error. That is not necessarily more correct either, as error management is not accurately specified either. (Ehm.. It is not mentioned...)

Length 10

```<code>H+H+H+H+H+
</code>```

Many people will probably have some concerns about to language because of the very permissive specification potentially leading to spaghetti code or bad programming practises. This example is an attempt to disprove this myth by adapting principles from structured programming, by carefully incrementing the accumulator after each successfully executed statement. Each and every instruction is thus properly clarified.

Length 12

```<code>9+
</code>```0

Is it still possible to find interesting long programs in HQ9+? Well, we can take a look at iterating programs. If the above snippet is run through an interpreter ignoring non-existing commands, the 9 triggers our familiar song. The output, if you analyse it, contains exactly 60 9's. Suppose we feed that back as an input, we end up with 60 new runs of the song. The number grows exponentially, so after three iterations, we have reached a total of 219661. Also worth mentioning is the growth of "Hello, world!". Each run of the song spawns 101 new ones (2 per verse, one extra in "tHe store"), and each one produces one child in the next iterations. That should give us 369761 in total on the third iteration.

Title: Showcase of Languages

Body:
HQ9+

Factoid:

HQ9+ is a joke programming language, invented by Cliff L. Biffle in 2001. It is a golfing language, that has a very small source code for the most common programming exercises, due to its small set of strategic built-ins.

Length 1

Q

HQ9+ has a very short quine. The Q built-in prints the source code of the entire program.

Length 2

9+

Speaking about crazy built-ins, HQ9+ is almost comparable to Mathematica. This program prints the entire lyrics of "99 bottles of beer on the wall", before it increments the accumulator and terminates.

Length 3

9H9

Commands can be mixed and matched in any order you want. This program, for instance, takes a break and greats the world between two passes through the already mentioned song "99 bottles of beer on the wall."

Length 4

HQ9+

Yup, The name of the language is actually a syntactically valid program by itself. One thing to notice here is how Q behaves when there are other characters in the program as well. In between hello world and 99 bottles of beer, it prints "HQ9+". While not a quine, the source code is at least part of the output.

Length 5

+++++

There are no other operations than + that can be applied to the accumulator. Thus, if we want to increase it by five, this is the shortest way to do it. While backwards compatible with HQ9+, the popular object-oriented extension of the language by David Morgan-Mar, HQ9++, is also going to create two new subclasses of the generic superclass if this code is executed. The output is the same though.

Length 6

QH99QH

We have seen that HQ9+ is capable of only a limited number of outputs, however, it can still output any information. Using the highest density of information per command (e.g. avoid to increase the accumulator), the flow rate of information is log2(3) bits per command. For many languages, this is not known exactly, but for English text it is assumed to be around 1.3 bits per character, a little less than HQ9+. I have here as an example chosen a tertiary encoding, where the output of the H command here represents a 0, Q represents 1 and 9 represents 2. Using that, the output of the program can be interpreted as "SE" for Stack Exchange.

Length 7

QQQQQQQ

Surprisingly many get this one wrong, they think Q prints just a Q. But Each Q actually prints the whole source code of the program, here resulting in

QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ

  (49 of them)

That is a great tool for demonstrating quadratic growth, and make it possible for HQ9+ to be used in surprising ways, like in this answer printing twice the length of the program to STDOUT.

Length 8

+++Q++++

As the + command is effectively a NOP regarding output, a single Q placed anywhere in a string of + can be used to produce a quine of arbitrary length.

Length 9

BURLESQUE

Is this a quine or not? That depends on the interpreter used. It is not very clear in the specification if invalid characters should be ignored or not. In the interpreters that do ignore such characters, this is proper quine. Others just throw an error. That is not necessarily more correct either, as error management is not accurately specified either. (Ehm.. It is not mentioned...)

Length 10

H+H+H+H+H+

Many people will probably have some concerns about to language because of the very permissive specification potentially leading to spaghetti code or bad programming practises. This example is an attempt to disprove this myth by adapting principles from structured programming, by carefully incrementing the accumulator after each successfully executed statement. Each and every instruction is thus properly clarified.

Length 12

219661 beers

Is it still possible to find interesting long programs in HQ9+? Well, we can take a look at iterating programs. If the above snippet is run through an interpreter ignoring non-existing commands, the 9 triggers our familiar song. The output, if you analyse it, contains exactly 60 9's. Suppose we feed that back as an input, we end up with 60 new runs of the song. The number grows exponentially, so after three iterations, we have reached a total of 219661. Also worth mentioning is the growth of "Hello, world!". Each run of the song spawns 101 new ones (2 per verse, one extra in "tHe store"), and each one produces one child in the next iterations. That should give us 369761 in total on the third iteration.


答:
JavaScript (ES7), 104 bytes

```<code>n=>(a=[...Array(n)]).map(_=>a.every(_=>(p=i**++j)>n*n?0:r[p]=p,i+=j=1),r=[i=1])&&r.sort((a,b)=>a-b)[n-1]
</code>```

Works by computing all powers not greater than n², sorting the resulting list and taking the nth element.

Title: Find the n-th perfect power!

Body:
A perfect power is a number of the form \$a^b\$, where \$a>0\$ and \$b>1\$.

For example, \$125\$ is a perfect power because it can be expressed as \$5^3\$.

Goal

Your task is to write  a program/function that finds the \$n\$-th perfect power, given a positive integer \$n\$.

Specs

The first perfect power is \$1\$ (which is \$1^2\$).

Input/output in any reasonable format.

Built-ins are allowed.

Further information

OEIS A001597

Scoring

This is code-golf. Shortest solution in bytes wins.

Testcases

```<code>input  output
1      1
2      4
3      8
4      9
5      16
6      25
7      27
8      32
9      36
10     49
</code>```

Body:
JavaScript (ES7), 104 bytes

n=>(a=[...Array(n)]).map(_=>a.every(_=>(p=i**++j)>n*n?0:r[p]=p,i+=j=1),r=[i=1])&&r.sort((a,b)=>a-b)[n-1]

Works by computing all powers not greater than n², sorting the resulting list and taking the nth element.


问:
Find the program that prints this integer sequence (Robbers' thread)
This is the robbers' thread. The cops' thread goes here.

In the cops thread, the task was to write a program/function that takes a positive (or non-negative) integer and outputs/returns another number (not necessarily integer). The robbers task is to unscramble the code the cops used to produce this output.

The cracked code doesn't have to be identical, as long as it has the same length and any revealed characters are in the correct positions. The language must also be the same (version numbers can be different). The output must of course be identical.

No-ops can be used in robber's solution.

The winner of the robbers thread will be the user who has cracked the
most submissions by May 7th 2016. If there's a tie, the user who has cracked submissions with the longest combined code will win.

The submission should be formatted like this:

Language, nn characters (including link to answer), Cop's username

Code:

```<code>function a(n)
    if n<2 then
        return n
    else
        return a(n-1) + a(n-2)
    end
end
</code>```

Output

```<code>a(0) returns 0
a(3) returns 2
</code>```

Optional explanation and comments.

答:
Python 3, 58 bytes, Mega Man

```<code>import math;x=int(input());print(int(x/math.sqrt(5)*x**x))
</code>```

The sequence is:

```<code>(x/√5)*(x**x)
</code>```

Body:
Python 3, 58 bytes, Mega Man

import math;x=int(input());print(int(x/math.sqrt(5)*x**x))

The sequence is:

(x/√5)*(x**x)


答:
Pyth - <s>12</s> 11 bytes

Obvious approach, just goes through and checks all numbers.

```<code>e.ffsI@ZTr2
</code>```

Test Suite.

Title: Find the n-th perfect power!

Body:
Pyth - <s>12</s> 11 bytes

Obvious approach, just goes through and checks all numbers.

e.ffsI@ZTr2

Test Suite.


问:
Are my eyes open or closed?
You are trying to guess my emotion.

I will give you an adjective, as the input to the function/program.

Your task is to output the state of my eyes, either O_O for open, or ._. for closed.

Details

For these adjectives, you must output open eyes O_O

```<code>animated
breezy
brisk
driving
enterprising
fresh
indefatigable
industrious
snappy
spirited
sprightly
spry
stalwart
strenuous
strong
sturdy
unflagging
untiring
</code>```

For these adjectives, you must output closed eyes ._.

```<code>beat
bored
collapsing
consumed
distressed
empty
fagged
faint
fatigued
finished
jaded
wasted
worn
</code>```

Other adjectives are undefined. You may output whatever you want for other adjectives.

Specs

All in lowercase. All matches regex ^[a-z]+$.

Scoring

This is code-golf. Shortest solution in bytes wins.

Tips

There is a trick. The adjectives that correspond to closed eyes are all related to "tired". The adjectives that correspond to open eyes are all related to "active".

Title: Are my eyes open or closed?

Body:
rs, 45 bytes

^(.*[^t]ed|[cbwef](?![rn]).*)$/._.
[^_.]+/0_0

Live demo.


问:
Tips for golfing in Pyth
Pyth is a Python-inspired procedural programming language, created by PPCG user isaacg.

What general tips do you have for golfing in Pyth? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Pyth.

One tip per answer, please.

答:
Telling if a Number is a Whole Number

A neat trick is using Invariant to tell if a number is a whole number as such:

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

This checks if the number doesn't change when you truncate it, which it won't if it's a whole number.

For example, you can use this as a perfect square check:

```<code>sI@Q2
</code>```

Title: Tips for golfing in Pyth

Body:
Telling if a Number is a Whole Number

A neat trick is using Invariant to tell if a number is a whole number as such:

sI

This checks if the number doesn't change when you truncate it, which it won't if it's a whole number.

For example, you can use this as a perfect square check:

sI@Q2


答:
Python (2.x), <s>95</s> 94 bytes

```<code>import re
print('O_O','._.')[len(re.findall('^a|(br)|(dr)|(en)|(fr)|i|s|u.*',raw_input()))==0]
</code>```

Regex! If it starts with:

a
br
dr
en
fr
i
s
u

then it is on the eyes-open list.

EDIT: Removed 1 byte because I didn't know how wc worked on bash. :P

Title: Are my eyes open or closed?

Body:
You are trying to guess my emotion.

I will give you an adjective, as the input to the function/program.

Your task is to output the state of my eyes, either O_O for open, or ._. for closed.

Details

For these adjectives, you must output open eyes O_O

```<code>animated
breezy
brisk
driving
enterprising
fresh
indefatigable
industrious
snappy
spirited
sprightly
spry
stalwart
strenuous
strong
sturdy
unflagging
untiring
</code>```

For these adjectives, you must output closed eyes ._.

```<code>beat
bored
collapsing
consumed
distressed
empty
fagged
faint
fatigued
finished
jaded
wasted
worn
</code>```

Other adjectives are undefined. You may output whatever you want for other adjectives.

Specs

All in lowercase. All matches regex ^[a-z]+$.

Scoring

This is code-golf. Shortest solution in bytes wins.

Tips

There is a trick. The adjectives that correspond to closed eyes are all related to "tired". The adjectives that correspond to open eyes are all related to "active".

Body:
Python (2.x), <s>95</s> 94 bytes

import re
print('O_O','._.')[len(re.findall('^a|(br)|(dr)|(en)|(fr)|i|s|u.*',raw_input()))==0]

Regex! If it starts with:

a
br
dr
en
fr
i
s
u

then it is on the eyes-open list.

EDIT: Removed 1 byte because I didn't know how wc worked on bash. :P


答:
JavaScript, <s>151</s> <s>123</s> <s>113</s> <s>54</s> <s>50</s> <s>47</s> 45 bytes

<s>

```<code>a=>["beat","bored","collapsing","consumed","distressed","empty","fagged","faint","fatigued","finished","jaded","wasted","worn"].includes(a)?"._.":"O_O"
</code>```

</s>
Long, but it's a good start.
<s>

```<code>a=>/(beat|bored|collapsing|consumed|distressed|empty|fagged|faint|fatigued|finished|jaded|wasted|worn)/.test(a)?"._.":"O_O"
</code>```

</s>
Still pretty long.
<s>

```<code>a=>(/beat|(bor|consum|distress|finish|jad|wast)ed|collapsing|empty|fa(gged|int|tigued)|worn/).test(a)?"._.":"O_O"
</code>```

</s>
Eliminated some redundancy.
<s>

```<code>a=>/^(be|bo|c|di|en|fa|fi|j|w)\w+/.test(a)?"._.":"O_O"
</code>```

</s>
Shorter.
<s>

```<code>a=>/^(a|br|dr|en|fr|i|s|u)\w+/.test(a)?"O_O":"._."
</code>```

</s>
Switched to the other(even shorter) regex for open eyes, instead of closed ones.
<s>

```<code>a=>/^(a|br|dr|en|fr|i|s|u)/.test(a)?"O_O":"._."
</code>```

</s>
Better.

```<code>a=>/^(a|[bdf]r|en|i|s|u)/.test(a)?"O_O":"._."
</code>```

Title: Are my eyes open or closed?

Body:
JavaScript, <s>151</s> <s>123</s> <s>113</s> <s>54</s> <s>50</s> <s>47</s> 45 bytes

<s>

a=>["beat","bored","collapsing","consumed","distressed","empty","fagged","faint","fatigued","finished","jaded","wasted","worn"].includes(a)?"._.":"O_O"

</s>
Long, but it's a good start.
<s>

a=>/(beat|bored|collapsing|consumed|distressed|empty|fagged|faint|fatigued|finished|jaded|wasted|worn)/.test(a)?"._.":"O_O"

</s>
Still pretty long.
<s>

a=>(/beat|(bor|consum|distress|finish|jad|wast)ed|collapsing|empty|fa(gged|int|tigued)|worn/).test(a)?"._.":"O_O"

</s>
Eliminated some redundancy.
<s>

a=>/^(be|bo|c|di|en|fa|fi|j|w)\w+/.test(a)?"._.":"O_O"

</s>
Shorter.
<s>

a=>/^(a|br|dr|en|fr|i|s|u)\w+/.test(a)?"O_O":"._."

</s>
Switched to the other(even shorter) regex for open eyes, instead of closed ones.
<s>

a=>/^(a|br|dr|en|fr|i|s|u)/.test(a)?"O_O":"._."

</s>
Better.

a=>/^(a|[bdf]r|en|i|s|u)/.test(a)?"O_O":"._."


问:
Compute CRC32 Hash

Credits

This challenge originated from @miles.

Create a function that computes the CRC32 hash of an input string. The input will be an ASCII string of any length. The output will be the CRC32 hash of that input string.

Explanation

The algorithm of CRC32 and other CRC are essentially the same, so only CRC3 will be demonstrated here.

Firstly, you have the generator polynomial, which is actually a 4-bit [n+1] integer (would be 33-bit in CRC32).

In this example, the generator polynomial is 1101.

Then, you will have the string to be hashed, which in this example would be 00010010111100101011001101.

```<code>00010010111100101011001101|000 (1)    append three [n] "0"s
   1101                        (2)    align with highest bit
00001000111100101011001101|000 (3)    XOR (1) and (2)
    1101                       (4)    align with highest bit
00000101111100101011001101|000 (5)    XOR (3) and (4)
     1101                      (6)    align with highest bit
00000011011100101011001101|000 (7)    XOR (5) and (6)
      1101                     (8)    align with highest bit
00000000001100101011001101|000 (9)    XOR (7) and (8)
          1101                 (10)   align with highest bit
00000000000001101011001101|000 (11)   XOR (9) and (10)
             1101              (12)   align with highest bit
00000000000000000011001101|000 (13)   XOR (11) and (12)
                  1101         (14)   align with highest bit
00000000000000000000011101|000 (15)   XOR (13) and (14)
                     1101      (16)   align with highest bit
00000000000000000000000111|000 (17)   XOR (15) and (16)
                       110 1   (18)   align with highest bit
00000000000000000000000001|100 (19)   XOR (17) and (18)
                         1 101 (20)   align with highest bit
00000000000000000000000000|001 (21)   XOR (19) and (20)
^--------REGION 1--------^ ^2^
</code>```

The remainder obtained at (21), when region 1 is zero, which is 001, would be the result of the CRC3 hash.

Specs

The generator polynomial is 0x104C11DB7, or 0b100000100110000010001110110110111, or 4374732215.

Input can be a string or a list of integers, or any other reasonable format.

Output be a hex string or just an integer, or any other reasonable format.

Built-ins that compute the CRC32 hash are not allowed.

Goal

Standard rules for code-golf apply.

The shortest code wins.

Test cases

```<code>input         output      (hex)
"code-golf"   147743960   08CE64D8
"jelly"       1699969158  65537886
""            0           00000000
</code>```

答:
JavaScript (ES6), 180 bytes

```<code>f=(s,t=(s+`\0\0\0\0`).replace(/[^]/g,(c,i)=>(c.charCodeAt()+256*!!i).toString(2).slice(!!i)))=>t[32]?f(s,t.replace(/.(.{32})/,(_,m)=>(('0b'+m^79764919)>>>0).toString(2))):+('0b'+t)
</code>```

The lack of a 33-bit XOR operator, or even an unsigned 32-bit XOR operator, is unhelpful.

Title: Compute CRC32 Hash

Body:
JavaScript (ES6), 180 bytes

f=(s,t=(s+`\0\0\0\0`).replace(/[^]/g,(c,i)=>(c.charCodeAt()+256*!!i).toString(2).slice(!!i)))=>t[32]?f(s,t.replace(/.(.{32})/,(_,m)=>(('0b'+m^79764919)>>>0).toString(2))):+('0b'+t)

The lack of a 33-bit XOR operator, or even an unsigned 32-bit XOR operator, is unhelpful.


问:
Shortest infinite loop producing no output
Your task is to create the shortest infinite loop!

The point of this challenge is to create an infinite loop producing no output, unlike its possible duplicate. The reason to this is because the code might be shorter if no output is given.

Rules

Each submission must be a full program.

You must create the shortest infinite loop.

Even if your program runs out of memory eventually, it is still accepted as long as it is running the whole time from the start to when it runs out of memory. Also when it runs out of memory, it should still not print anything to STDERR.

The program must take no input (however, reading from a file is allowed), and should not print anything to STDOUT. Output to a file is also forbidden.

The program must not write anything to STDERR.

Feel free to use a language (or language version) even if it's newer than this challenge.
-Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language. :D

Submissions are scored in bytes, in an appropriate (pre-existing) encoding, usually (but not necessarily) UTF-8. Some languages, like Folders, are a bit tricky to score - if in doubt, please ask on Meta.

This is not about finding the language with the shortest infinite loop program. This is about finding the shortest infinite loop program in every language. Therefore, I will not accept an answer.

If your language of choice is a trivial variant of another (potentially more popular) language which already has an answer (think BASIC or SQL dialects, Unix shells or trivial Brainf**k-derivatives like Alphuck), consider adding a note to the existing answer that the same or a very similar solution is also the shortest in the other language.

There should be a website such as Wikipedia, Esolangs, or GitHub for the language. For example, if the language is CJam, then one could link to the site in the header like #[CJam](http://sourceforge.net/p/cjam/wiki/Home/), X bytes.

Standard loopholes are not allowed.

(I have taken some of these rules from Martin Büttner's "Hello World" challenge)

Please feel free to post in the comments to tell me how this challenge could be  improved.

Catalogue

This is a Stack Snippet which generates both an alphabetical catalogue of the used languages, and an overall leaderboard. To make sure your answer shows up, please start it with this Markdown header:

```<code># Language name, X bytes
</code>```

Obviously replacing Language name and X bytes with the proper items. If you want to link to the languages' website, use this template, as posted above:

```<code>#[Language name](http://link.to/the/language), X bytes
</code>```

Now, finally, here's the snippet: (Try pressing "Full page" for a better view.)

var QUESTION_ID=59347;var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";var COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk";var OVERRIDE_USER=41805;var answers=[],answers_hash,answer_ids,answer_page=1,more_answers=true,comment_page;function answersUrl(index){return"//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"//api.stackexchange.com/2.2/answers/"+answers.join(';')+"/comments?page="+index+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:true,success:function(data){answers.push.apply(answers,data.items);answers_hash=[];answer_ids=[];data.items.forEach(function(a){a.comments=[];var id=+a.share_link.match(/\d+/);answer_ids.push(id);answers_hash[id]=a});if(!data.has_more)more_answers=false;comment_page=1;getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:true,success:function(data){data.items.forEach(function(c){if(c.owner.user_id===OVERRIDE_USER)answers_hash[c.post_id].comments.push(c)});if(data.has_more)getComments();else if(more_answers)getAnswers();else process()}})}getAnswers();var SCORE_REG=/<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;var OVERRIDE_REG=/^Override\s*header:\s*/i;function getAuthorName(a){return a.owner.display_name}function process(){var valid=[];answers.forEach(function(a){var body=a.body;a.comments.forEach(function(c){if(OVERRIDE_REG.test(c.body))body='
'+c.body.replace(OVERRIDE_REG,'')+'
'});var match=body.match(SCORE_REG);if(match)valid.push({user:getAuthorName(a),size:+match[2],language:match[1],link:a.share_link,});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,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.toLowerCase()>b.lang_raw.toLowerCase())return 1;if(a.lang_raw.toLowerCase()<b.lang_raw.toLowerCase())return-1;return 0});for(var i=0;i<langs.length;++i){var language=jQuery("#language-template").html();var lang=langs[i];language=language.replace("{{LANGUAGE}}",lang.lang).replace("{{NAME}}",lang.user).replace("{{SIZE}}",lang.size).replace("{{LINK}}",lang.link);language=jQuery(language);jQuery("#languages").append(language)}}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list{padding:10px;width:500px;float:left}#language-list{padding:10px;padding-right:40px;width:500px;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">

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
GPRX 3000, 1 byte

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

Sets the IP to the value of register A (which is initially 0).

Body:
GPRX 3000, 1 byte

g

Sets the IP to the value of register A (which is initially 0).


问:
Find the positive divisors!

Definition

A number is positive if it is greater than zero.

A number (A) is the divisor of another number (B) if A can divide B with no remainder.

For example, 2 is a divisor of 6 because 2 can divide 6 with no remainder.

Goal

Your task is to write a program/function that takes a positive number and then find all of its divisors.

Restriction

You may not use any built-in related to prime or factorization.

The complexity of your algorithm must not exceed O(sqrt(n)).

Freedom

The output list may contain duplicates.

The output list does not need to be sorted.

Scoring

This is code-golf. Shortest solution in bytes wins.

Testcases

```<code>input    output
1        1
2        1,2
6        1,2,3,6
9        1,3,9
</code>```

答:
Perl 6, 40 bytes

{|(my@a=grep $_%%*,^.sqrt+1),|($_ X/@a)}
```

<h3>Explanation:</h3>

<pre class="lang-perl6 prettyprint-override"><code>{
  # this block has an implicit parameter named $_

  # slip this list into outer list:
  |(

    my @a = grep
                 # Whatever lambda:
                 # checks if the block's parameter ($_)
                 # is divisible by (%%) this lambda's parameter (*)

                 $_ %% *,

                 # upto and exclude the sqrt of the argument
                 # then shift the Range up by one
                 ^.sqrt+1
                 # (0 ..^ $_.sqrt) + 1

                 # would be clearer if written as:
                 # 1 .. $_.sqrt+1
  ),
  # slip this list into outer list
  |(

    # take the argument and divide it by each value in @a
    $_ X/ @a

    # should use X[div] instead of X[/] so that it would return
    # Ints instead of Rats
  )
}
</code>```

Usage:

my &divisors = {|(my@a=grep $_%%*,^.sqrt+1),|($_ X/@a)}

.say for (1,2,6,9,10,50,99)».&divisors
```

<pre class="lang-none prettyprint-override"><code>(1 1)
(1 2 2 1)
(1 2 3 6 3 2)
(1 3 9 3)
(1 2 10 5)
(1 2 5 50 25 10)
(1 3 9 99 33 11)
</code>```

Title: Find the positive divisors!

Body:
Perl 6, 40 bytes

{|(my@a=grep $_%%*,^.sqrt+1),|($_ X/@a)}

Explanation:

{
  # this block has an implicit parameter named $_

  # slip this list into outer list:
  |(

    my @a = grep
                 # Whatever lambda:
                 # checks if the block's parameter ($_)
                 # is divisible by (%%) this lambda's parameter (*)

                 $_ %% *,

                 # upto and exclude the sqrt of the argument
                 # then shift the Range up by one
                 ^.sqrt+1
                 # (0 ..^ $_.sqrt) + 1

                 # would be clearer if written as:
                 # 1 .. $_.sqrt+1
  ),
  # slip this list into outer list
  |(

    # take the argument and divide it by each value in @a
    $_ X/ @a

    # should use X[div] instead of X[/] so that it would return
    # Ints instead of Rats
  )
}

Usage:

my &divisors = {|(my@a=grep $_%%*,^.sqrt+1),|($_ X/@a)}

.say for (1,2,6,9,10,50,99)».&divisors

(1 1)
(1 2 2 1)
(1 2 3 6 3 2)
(1 3 9 3)
(1 2 10 5)
(1 2 5 50 25 10)
(1 3 9 99 33 11)


问:
Smallest groups in an array

Introduction

Let's observe the following array:

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

A group consists of the same digits next to each other. In the above array, there are 5 different groups:

```<code>[1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1]

 1, 1, 1
          2, 2
                1, 1, 1, 1
                            2, 2, 2
                                     1, 1, 1
</code>```

The smallest group of these is [2, 2], so we output [2, 2].

Let's take another example:

```<code>[3, 3, 3, 4, 4, 4, 4, 5, 5, 4, 4, 3, 3, 4, 4]

 3, 3, 3
          4, 4, 4, 4
                      5, 5
                            4, 4
                                  3, 3
                                        4, 4
</code>```

You can see that there are multiple groups with the same length. The smallest groups are:

```<code>[3, 3], [4, 4], [4, 4] and [5, 5].
</code>```

So we just output [3, 3], [4, 4], [4, 4], [5, 5] in any reasonable format. You may output these in any order.

The Task

Given an array consisting of only positive integers, output the smallest group(s) from the array. You can assume that the array will contain at least 1 integer.

Test cases

```<code>Input: [1, 1, 2, 2, 3, 3, 4]
Output: [4]

Input: [1]
Output: [1]

Input: [1, 1, 10, 10, 10, 100, 100]
Output: [1, 1], [100, 100]
</code>```

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

答:
Haskell, 38 bytes

```<code>import Data.Lists
argmins length.group
</code>```

Usage example: argmins length.group $ [3,3,3,4,4,4,4,5,5,4,4,3,3,4,4] -> [[4,4],[3,3],[4,4],[5,5]].

Build groups of equal elements and find those with minimal length.

Title: Smallest groups in an array

Body:
Haskell, 38 bytes

import Data.Lists
argmins length.group

Usage example: argmins length.group $ [3,3,3,4,4,4,4,5,5,4,4,3,3,4,4] -> [[4,4],[3,3],[4,4],[5,5]].

Build groups of equal elements and find those with minimal length.


答:
C#, 204 bytes

```<code>void f(string o){var r=Regex.Matches(o,@"([0-9])\1{0,}").Cast<Match>().OrderBy(x=>x.Groups[0].Value.Length);foreach(var s in r){foreach(var z in r)if(s.Length>z.Length)return;Console.WriteLine(s.Value);}}
</code>```

I don't know if using a string is fair considering all the golfing esolangs get their input in the same way but he requested array input.

ungolfed:

```<code>    public static void f(string inp)
    {

        var r = Regex.Matches(inp, @"([0-9])\1{0,}").Cast<Match>().OrderBy(x => x.Groups[0].Value.Length);

        foreach (Match s in r)
        {
            foreach (Match z in r)
                if (s.Length > z.Length)
                    return;

        Console.WriteLine(s.Value);
        }

    }
</code>```

I need a way to get the smallest matches for the match array, most of my bytes are wasted there, help appreciated. I'm trying to get into LINQ and lambda stuff.

Title: Smallest groups in an array

Body:
Introduction

Let's observe the following array:

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

A group consists of the same digits next to each other. In the above array, there are 5 different groups:

```<code>[1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1]

 1, 1, 1
          2, 2
                1, 1, 1, 1
                            2, 2, 2
                                     1, 1, 1
</code>```

The smallest group of these is [2, 2], so we output [2, 2].

Let's take another example:

```<code>[3, 3, 3, 4, 4, 4, 4, 5, 5, 4, 4, 3, 3, 4, 4]

 3, 3, 3
          4, 4, 4, 4
                      5, 5
                            4, 4
                                  3, 3
                                        4, 4
</code>```

You can see that there are multiple groups with the same length. The smallest groups are:

```<code>[3, 3], [4, 4], [4, 4] and [5, 5].
</code>```

So we just output [3, 3], [4, 4], [4, 4], [5, 5] in any reasonable format. You may output these in any order.

The Task

Given an array consisting of only positive integers, output the smallest group(s) from the array. You can assume that the array will contain at least 1 integer.

Test cases

```<code>Input: [1, 1, 2, 2, 3, 3, 4]
Output: [4]

Input: [1]
Output: [1]

Input: [1, 1, 10, 10, 10, 100, 100]
Output: [1, 1], [100, 100]
</code>```

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

Body:
C#, 204 bytes

void f(string o){var r=Regex.Matches(o,@"([0-9])\1{0,}").Cast<Match>().OrderBy(x=>x.Groups[0].Value.Length);foreach(var s in r){foreach(var z in r)if(s.Length>z.Length)return;Console.WriteLine(s.Value);}}

I don't know if using a string is fair considering all the golfing esolangs get their input in the same way but he requested array input.

ungolfed:

    public static void f(string inp)
    {

        var r = Regex.Matches(inp, @"([0-9])\1{0,}").Cast<Match>().OrderBy(x => x.Groups[0].Value.Length);

        foreach (Match s in r)
        {
            foreach (Match z in r)
                if (s.Length > z.Length)
                    return;

        Console.WriteLine(s.Value);
        }

    }

I need a way to get the smallest matches for the match array, most of my bytes are wasted there, help appreciated. I'm trying to get into LINQ and lambda stuff.


Title: Polygonal numbers

Body:
A polygonal number is the number of dots in a k-gon of size n.

You will be given n and k, and your task is to write a program/function that outputs/prints the corresponding number.

Scoring

This is code-golf. Shortest solution in bytes wins.

Example

The 3rd hexagon number (k=6, n=3) is 28 because there are 28 dots above.

Testcases

Can be generated from this Pyth test suite.

Usage: two lines per testcase, n above, k below.

```<code>n    k  output
10   3  55
10   5  145
100  3  5050
1000 24 10990000
</code>```

Further information

In Wikipedia: https://en.wikipedia.org/wiki/Polygonal_number

In Wolfram Mathworld: http://mathworld.wolfram.com/PolygonalNumber.html

In OEIS Wiki: http://oeis.org/wiki/Polygonal_numbers

OEIS sequences for n-gonal numbers for various n: 3 (A000217), 4 (A000290), 5 (A000326), 6 (A000384), 7 (A000566), 8 (A000567), 9 (A001106), 10 (A001107), 11 (A051682), 12 (A051624), 13 (A051865), 14 (A051866), 15 (A051867), 16 (A051868), 17 (A051869), 18 (A051870), 19 (A051871), 20 (A051872), 21 (A051873), 22 (A051874), 23 (A051875), 24 (A051876)

Body:
Mathematica, 17 bytes

(#2-2)#(#-1)/2+#&

Straight-forward application of the formula.

Usage

  f = (#2-2)#(#-1)/2+#&
  f[10, 3]
55
  f[10, 5]
145
  f[100, 3]
5050
  f[1000, 24]
10990000


答:
05AB1E, 8 bytes

Code:

```<code>D<LOIÍ*+
</code>```

Explanation:

```<code>D         # Duplicate the input
 <LO      # Compute n × (n - 1) / 2
    IÍ    # Compute k - 2
      *   # Multiply, resulting into (k - 2)(n - 1)(n) / 2
       +  # Add, resulting into n + (k - 2)(n - 1)(n) / 2
</code>```

Uses CP-1252 encoding. Try it online!.

Title: Polygonal numbers

Body:
05AB1E, 8 bytes

Code:

D<LOIÍ*+

Explanation:

D         # Duplicate the input
 <LO      # Compute n × (n - 1) / 2
    IÍ    # Compute k - 2
      *   # Multiply, resulting into (k - 2)(n - 1)(n) / 2
       +  # Add, resulting into n + (k - 2)(n - 1)(n) / 2

Uses CP-1252 encoding. Try it online!.


答:
J, 14 bytes

```<code>]++/@i.@]*[-2:
</code>```

Based on the formula.

```<code>P(k, n) = (k - 2) * T(n - 1) + n where T(n) = n * (n + 1) / 2
        = (k - 2) * n * (n - 1) / 2 + n
</code>```

Usage

```<code>   f =: ]++/@i.@]*[-2:
   3 f 10
55
   5 f 10
145
   3 f 100
5050
   24 f 1000
10990000
</code>```

Explanation

```<code>]++/@i.@]*[-2:
            2:  The constant function 2
          [     Get k
           -    Subtract to get k-2
        ]       Get n
     i.@        Make a range from 0 to n-1
  +/@           Sum the range to get the (n-1) Triangle number = n*(n-1)/2
                The nth Triangle number is also the sum of the first n numbers
         *      Multiply n*(n-1)/2 with (k-2)
]               Get n
 +              Add n to (k-2)*n*(n-1)/2
</code>```

Title: Polygonal numbers

Body:
J, 14 bytes

]++/@i.@]*[-2:

Based on the formula.

P(k, n) = (k - 2) * T(n - 1) + n where T(n) = n * (n + 1) / 2
        = (k - 2) * n * (n - 1) / 2 + n

Usage

   f =: ]++/@i.@]*[-2:
   3 f 10
55
   5 f 10
145
   3 f 100
5050
   24 f 1000
10990000

Explanation

]++/@i.@]*[-2:
            2:  The constant function 2
          [     Get k
           -    Subtract to get k-2
        ]       Get n
     i.@        Make a range from 0 to n-1
  +/@           Sum the range to get the (n-1) Triangle number = n*(n-1)/2
                The nth Triangle number is also the sum of the first n numbers
         *      Multiply n*(n-1)/2 with (k-2)
]               Get n
 +              Add n to (k-2)*n*(n-1)/2


答:
Labyrinth, 13 bytes

```<code>?::(*?((*#/+!
</code>```

Try it online!

Explanation

Due to its single-character commands (which are merely a necessity of the 2D-ness of the language), Labyrinth can be surprisingly golfy for linear programs.

This uses the same formula as several other answers:

```<code>Op  Explanation                 Stack
?   Read n.                     [n]
::  Make two copies.            [n n n]
(   Decrement.                  [n n (n-1)]
*   Multiply.                   [n (n*(n-1))]
?   Read s.                     [n (n*(n-1)) s]
((  Decrement twice.            [n (n*(n-1)) (s-2)]
*   Multiply.                   [n (n*(n-1)*(s-2))]
#   Push stack depth, 2.        [n (n*(n-1)*(s-2)) 2]
/   Divide.                     [n (n*(n-1)*(s-2))/2]
+   Add.                        [(n+(n*(n-1)*(s-2))/2)]
!   Print.                      []
</code>```

At this point, the instruction pointer hits a dead end and turns around. Now + is executed again, which is a no-op (since the bottom of the stack is implicitly filled with an infinite amount of zeros), and then / attempts a division-by-zero which terminates the program with an error.

Title: Polygonal numbers

Body:
Labyrinth, 13 bytes

?::(*?((*#/+!

Try it online!

Explanation

Due to its single-character commands (which are merely a necessity of the 2D-ness of the language), Labyrinth can be surprisingly golfy for linear programs.

This uses the same formula as several other answers:

Op  Explanation                 Stack
?   Read n.                     [n]
::  Make two copies.            [n n n]
(   Decrement.                  [n n (n-1)]
*   Multiply.                   [n (n*(n-1))]
?   Read s.                     [n (n*(n-1)) s]
((  Decrement twice.            [n (n*(n-1)) (s-2)]
*   Multiply.                   [n (n*(n-1)*(s-2))]
#   Push stack depth, 2.        [n (n*(n-1)*(s-2)) 2]
/   Divide.                     [n (n*(n-1)*(s-2))/2]
+   Add.                        [(n+(n*(n-1)*(s-2))/2)]
!   Print.                      []

At this point, the instruction pointer hits a dead end and turns around. Now + is executed again, which is a no-op (since the bottom of the stack is implicitly filled with an infinite amount of zeros), and then / attempts a division-by-zero which terminates the program with an error.


答:
Python 2.x, 303 bytes

```<code>x=input()
r=[q[2]for q in filter(lambda l:(len(l[2])>0)&((l[0]<1)or(x[l[0]-1]!=x[l[0]]))&((l[1]>len(x)-1)or(x[l[1]]!=x[l[1]-1]))&(len(filter(lambda k:k==l[2][0],l[2]))==len(l[2])),[(a,b,x[a:b])for a in range(0,len(x))for b in range(0,len(x)+1)])]
print filter(lambda k:len(k)==min([len(s)for s in r]),r)
</code>```

Ugliest. Code. Ever.

Input: An array in the format r'\[(\d,)*(\d,?)?\]'

In other words, a python array of numbers

Output: An array of arrays (the smallest groups), in the order that they appear in the input array

Additional Coincidental Features (Features that I did not intend to make):

The input can be an empty array; the output will be an empty array.

By changing min to max, it will return an array of the largest groups.

If you just do print r, it will print all of the groups in order.

Title: Smallest groups in an array

Body:
Python 2.x, 303 bytes

x=input()
r=[q[2]for q in filter(lambda l:(len(l[2])>0)&((l[0]<1)or(x[l[0]-1]!=x[l[0]]))&((l[1]>len(x)-1)or(x[l[1]]!=x[l[1]-1]))&(len(filter(lambda k:k==l[2][0],l[2]))==len(l[2])),[(a,b,x[a:b])for a in range(0,len(x))for b in range(0,len(x)+1)])]
print filter(lambda k:len(k)==min([len(s)for s in r]),r)

Ugliest. Code. Ever.

Input: An array in the format r'\[(\d,)*(\d,?)?\]'

In other words, a python array of numbers

Output: An array of arrays (the smallest groups), in the order that they appear in the input array

Additional Coincidental Features (Features that I did not intend to make):

The input can be an empty array; the output will be an empty array.

By changing min to max, it will return an array of the largest groups.

If you just do print r, it will print all of the groups in order.


答:
CJam, 17 bytes

```<code>q1=1^'n>".O"='_1$
</code>```

Second letters. This would have been much more fun without any "tricks" in the test cases :/

Try it online.

Title: Are my eyes open or closed?

Body:
CJam, 17 bytes

q1=1^'n>".O"='_1$

Second letters. This would have been much more fun without any "tricks" in the test cases :/

Try it online.


答:
TI-Basic, 34 bytes

```<code>"._.
If inString("nrpt",sub(Ans,2,1:"O-O
Ans
</code>```

39-byte oneliner:

```<code>sub("._.O-O",1+3inString("nrpt",sub(Ans,2,1)),3
</code>```

Title: Are my eyes open or closed?

Body:
TI-Basic, 34 bytes

"._.
If inString("nrpt",sub(Ans,2,1:"O-O
Ans

39-byte oneliner:

sub("._.O-O",1+3inString("nrpt",sub(Ans,2,1)),3


答:
GameMaker Language, 72 bytes

```<code>a="._."if string_count(string_copy(argument0,2,1),"nrpt")a="O_O"return a
</code>```

Title: Are my eyes open or closed?

Body:
You are trying to guess my emotion.

I will give you an adjective, as the input to the function/program.

Your task is to output the state of my eyes, either O_O for open, or ._. for closed.

Details

For these adjectives, you must output open eyes O_O

```<code>animated
breezy
brisk
driving
enterprising
fresh
indefatigable
industrious
snappy
spirited
sprightly
spry
stalwart
strenuous
strong
sturdy
unflagging
untiring
</code>```

For these adjectives, you must output closed eyes ._.

```<code>beat
bored
collapsing
consumed
distressed
empty
fagged
faint
fatigued
finished
jaded
wasted
worn
</code>```

Other adjectives are undefined. You may output whatever you want for other adjectives.

Specs

All in lowercase. All matches regex ^[a-z]+$.

Scoring

This is code-golf. Shortest solution in bytes wins.

Tips

There is a trick. The adjectives that correspond to closed eyes are all related to "tired". The adjectives that correspond to open eyes are all related to "active".

Body:
GameMaker Language, 72 bytes

a="._."if string_count(string_copy(argument0,2,1),"nrpt")a="O_O"return a


答:
TI-Basic, 20 bytes

```<code>Prompt K,N:(K-2)N(N-1)/2+N
</code>```

Title: Polygonal numbers

Body:
TI-Basic, 20 bytes

Prompt K,N:(K-2)N(N-1)/2+N


答:
GameMaker Language, 44 bytes

```<code>n=argument1;return (argument0-2)*n*(n-1)/2+n
</code>```

Title: Polygonal numbers

Body:
GameMaker Language, 44 bytes

n=argument1;return (argument0-2)*n*(n-1)/2+n


答:
Python 3.5, 227 223 210 206 201 bytes:

```<code>def k(u,*p):
 import itertools as i,random as r;y=[]
 for z in p:y+=[''.join(i)for i in i.product(*[u[i]for o in z for i in o])]
 for q in'1'*100:print(''.join([r.choice(y)for i in'1'*r.randint(1,5)]))
</code>```

Takes the categories in as a Python dictionary (e.g {'C':'hello','K':'hoop'}) and the syllable types in as normal strings, with each separated by a comma (e.g. 'CK','CKC'). Output is in the form of 100 lines, with 1 word per line. Will add detailed explanation later.

Try it online! (repl.it)

Title: Build a word generator!

Body:
Your task is to create a program/function to replicate this word generator.

Details

Your program/function take two input. One input is the categories. The other input is the syllable types.

Categories

categories will consist of classes of letters.

For example, V=aeiou means that the letters a, e, i, o, and u will be classified under the category V.

Each category will have a 1-letter name in UPPERCASE.

The letters it contains will all be in lowercase.

Syllable types

For example CV would mean that the syllable will consist of a letter in category C and then a letter in category V.

For example, if C=bcd and V=ae, then the syllable can be ba, be, ca, ce, da, or de.

Your task

Your task is to generate 100 random words, each with a random length of 1-5 syllables, each chosen randomly in the syllable types, with the letter in each category chosen also randomly.

Specs

Any reasonable input/output format. I don't care how you input the list.

All inputs will be valid.

Scoring

This is code-golf. Shortest solution in bytes wins.

Testcase

```<code>input1          input2    output
"C=st;V=aeiou"  "CV/CVC"  tasiti tese tossi tesis titi sese saset su sosastesisat sisosis sissa sata to sisas sese satetot sisuta tatote sa tetsesuti sossut ti seso tese tostutsasussi tutiset sasates tasa ta sa satso tastitta tetti sesita setetat tatsi tisetot sassu sessiso satessase sas ses totasta si tetsit titse sase totas sa ta sasesa tasa sostat sesi sissa tato tos tate sustosussatta sustas sassatote tesas sutat tatetatossos testisot tatta tissisisa sasese sesatus tito sisa satas sasisi so sasatustu sosses tetsa tese sestit sestu tisot sutastot sesu tet sotte sisute setotitsesi tita
</code>```

Body:
Python 3.5, 227 223 210 206 201 bytes:

def k(u,*p):
 import itertools as i,random as r;y=[]
 for z in p:y+=[''.join(i)for i in i.product(*[u[i]for o in z for i in o])]
 for q in'1'*100:print(''.join([r.choice(y)for i in'1'*r.randint(1,5)]))

Takes the categories in as a Python dictionary (e.g {'C':'hello','K':'hoop'}) and the syllable types in as normal strings, with each separated by a comma (e.g. 'CK','CKC'). Output is in the form of 100 lines, with 1 word per line. Will add detailed explanation later.

Try it online! (repl.it)


答:
MATL, 15 bytes

```<code>Y'tX<tb=bw)wTX"
</code>```

Try it online

Input is a vector, like [1 2 3 4], and output is a matrix where each column is one of the smallest groups, e.g.:

```<code>1 100
1 100
</code>```

for the third test case.

Explanation:

```<code>Y'    %// Run length encoding, gives 2 vectors of group-lengths and values
t     %// Duplicate group lengths
X<    %// Minimum group length
tb    %// Duplicate and get vector of group lengths to the top
=     %// Find which group lengths are equal to the minimum
bw)   %// And get the values of those groups
wTX"  %// Repeats the matrix of minimum-length-group values by the minimum group length
</code>```

Title: Smallest groups in an array

Body:
MATL, 15 bytes

Y'tX<tb=bw)wTX"

Try it online

Input is a vector, like [1 2 3 4], and output is a matrix where each column is one of the smallest groups, e.g.:

1 100
1 100

for the third test case.

Explanation:

Y'    %// Run length encoding, gives 2 vectors of group-lengths and values
t     %// Duplicate group lengths
X<    %// Minimum group length
tb    %// Duplicate and get vector of group lengths to the top
=     %// Find which group lengths are equal to the minimum
bw)   %// And get the values of those groups
wTX"  %// Repeats the matrix of minimum-length-group values by the minimum group length


问:
Draw a phi triangle
Clarification: Basically, you need to make this

Euler's totient function has the name phi.

Let's try to calculate phi(8)

First, list all numbers 8 and under backwards, not including 0 or under

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

Now find which numbers don't share a factor with 8 (1 doesn't count), and place a # in their place.

```<code>8
#
6
#
4
#
2
#
</code>```

Remove the numbers.

```<code>#

#

#

#
                                                 -
</code>```

Now do this, but string the outputs together in a triangle

```<code>        9
       88
      777
     6666
    55555
   444444
  3333333
 22222222
111111111
---------
123456789
</code>```

# out non-factor sharing numbers

```<code>        9
       8#
      7##
     6#66
    5####
   4#4#4#
  3##3##3
 2#2#2#2#
#########
</code>```

Remove numbers:

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

This would be the output for input 9 (since 9 columns.)

Leading + trailing newlines allowed.

答:
Jelly, <s>20</s> 18 bytes

```<code>RR⁶”#g’¥?€"Rz⁶U'j⁷
</code>```

Try it online!

Title: Draw a phi triangle

Body:
Jelly, <s>20</s> 18 bytes

RR⁶”#g’¥?€"Rz⁶U'j⁷

Try it online!


答:
MATL, 9 bytes

```<code>:tQ!^uSG)
</code>```

Try it online

This is a port of Flawr's Octave solution to MATL, make the matrix of powers up to n^(n+1), and get the n-th one.

Title: Find the n-th perfect power!

Body:
A perfect power is a number of the form \$a^b\$, where \$a>0\$ and \$b>1\$.

For example, \$125\$ is a perfect power because it can be expressed as \$5^3\$.

Goal

Your task is to write  a program/function that finds the \$n\$-th perfect power, given a positive integer \$n\$.

Specs

The first perfect power is \$1\$ (which is \$1^2\$).

Input/output in any reasonable format.

Built-ins are allowed.

Further information

OEIS A001597

Scoring

This is code-golf. Shortest solution in bytes wins.

Testcases

```<code>input  output
1      1
2      4
3      8
4      9
5      16
6      25
7      27
8      32
9      36
10     49
</code>```

Body:
MATL, 9 bytes

:tQ!^uSG)

Try it online

This is a port of Flawr's Octave solution to MATL, make the matrix of powers up to n^(n+1), and get the n-th one.


答:
Pyth - 22 bytes

Will try to golf further.

```<code>j_.tmsm@"# "n1idkSdSQd
</code>```

Try it online here.

Title: Draw a phi triangle

Body:
Clarification: Basically, you need to make this

Euler's totient function has the name phi.

Let's try to calculate phi(8)

First, list all numbers 8 and under backwards, not including 0 or under

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

Now find which numbers don't share a factor with 8 (1 doesn't count), and place a # in their place.

```<code>8
#
6
#
4
#
2
#
</code>```

Remove the numbers.

```<code>#

#

#

#
                                                 -
</code>```

Now do this, but string the outputs together in a triangle

```<code>        9
       88
      777
     6666
    55555
   444444
  3333333
 22222222
111111111
---------
123456789
</code>```

# out non-factor sharing numbers

```<code>        9
       8#
      7##
     6#66
    5####
   4#4#4#
  3##3##3
 2#2#2#2#
#########
</code>```

Remove numbers:

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

This would be the output for input 9 (since 9 columns.)

Leading + trailing newlines allowed.

Body:
Pyth - 22 bytes

Will try to golf further.

j_.tmsm@"# "n1idkSdSQd

Try it online here.


问:
A simple TCP server
Write a program or function that listens for incoming TCP traffic on port N. It offers a simple service: it calculates sum of IP address fields of incoming connection and returns.

Program or function reads integer N from arguments or stdin. It listens to incoming TCP connections on port N. When someone connects to that port, the program calculates sum of its IP address fields and sends it back to the client with trailing newline and closes connection.

Port number N is a valid port, and 210 < N < 215

Trailing newline can be either \nor \r\n

You can use either IPv4 or IPv6. Since IPv6 addresses are written in hexadecimal form, you must also provide result in same format, for example 2001:0db8:0000:0042:0000:8a2e:0370:7334 => 12ecd.

This is code-golf. Standard rules and loopholes apply.

Example

You run your server with ./server 1234. The server is now running and waiting for connections on port 1234. Then a client from 127.0.0.1 connects to your server. Your server performs a simple calculation: 127+0+0+1 => 128 and sends the result to the client (with trailing newline): 128\n. Then server closes connection and waits for next client.

Leaderboard

var QUESTION_ID=76379,OVERRIDE_USER=20569;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

```

答:
k (55 characters)

This is essentially a translation of @h.j.k. solution in q with a couple of modifications.

```<code>."\\p ",*.z.x
.z.pg:{$+/0x0\:.z.a}
.z.ph:.h.hy[`].z.pg@
</code>```

Usage: q filename.k PORT

Title: A simple TCP server

Body:
k (55 characters)

This is essentially a translation of @h.j.k. solution in q with a couple of modifications.

."\\p ",*.z.x
.z.pg:{$+/0x0\:.z.a}
.z.ph:.h.hy[`].z.pg@

Usage: q filename.k PORT