问:
Golf yourself a beer
It's friday! Which means it's time for beer!

Sadly though, today we will be golfing beer instead of drinking it. :(

Challenge

Output a beer and drink it. The amount of sips you take changes your output.

Sips

Your program should take one input string. This string can solely consist out of concatenated sips.

If the input is an empty string, you should output a full beer glass, including foam.

The more sips you take, the emptier your beer glass will be.

If you take 0 sips, your beer still has foam. The output of this foam is always the same (see examples).

If you take 1 sip, you should output the beer glass, followed by a new line and the string Yuck, foam..

If you take 1 or more sips, your beerglass should not contain anymore foam, but should show the top of your glass. Drinking the foam counts as one sip.

If you take 6 or more sips, you should output an empty beer glass, followed by a new line and the string Burp.

For each sip you take, your beer glass should become emptier. How full your beerglass is depends on the amount of bubbles ° (°) in your beer. For each sip you take after the foam, a line of bubbles should be removed. Each line of beer can contain a minimum of 1 and a maximum of 5 bubbles. The position of these bubbles should be 100% random.

Examples

input

empty input string, or no input at all

output

```<code>  oo  o oo
 oooooooooooo
o|  °     ° |\
 |     °    | \
 | °°    °  |} |
 |  °    °  | /
 |     °   °|/
 \__________/
</code>```

input

sip sip sip

output

```<code> ____________
 |          |\
 |          | \
 |     °    |} |
 |° °     ° | /
 | °    °   |/
 \__________/
</code>```

input

sip sip sip sip sip sip sip sip sip sip

output

```<code> ____________
 |          |\
 |          | \
 |          |} |
 |          | /
 |          |/
 \__________/
Burp
</code>```

This pastebin contains a list of inputs and outputs. Remember that the bubbles in the beerglass should be random!

Scoring

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

Happy <s>drinking</s> golfing!

Title: Golf yourself a beer

Body:
PHP, <s>277</s> <s>265</s> 263 bytes

Assuming 1-byte-linebreak. Add one to 14 and 17 on Windows.

$r=str_pad(($i=$argc-1)?"":"  oo  o oo",16).str_pad("
 ",14,_o[!$i])."   ".($s="
 |          |")."\\  $s \\ $s} |$s / $s/
 \__________/
 ".($i<6?$i-1?"":"Yuck, foam.":burp)if(!$i){$r[34]=o;$i=1;}for(;$i++<6;)for($n=rand(1,5);$n--;)$r[17*$i+rand(2,11)]="°";echo$r;

Run with -r. line breaks may need escaping.

breakdown

// draw beer glass
$r=
    // first line: empty or foam
    str_pad(($i=$argc-1)?"":"  oo  o oo",16)
    // second line: top or foam
    .str_pad("\n ",14,_o[!$i])
    // other lines: empty glass+bottom
    ."   ".($s="\n |          |")."\\  $s \\ $s} |$s / $s/\n \__________/\n"
    // lyrics
    .($i<6?$i-1?"":"Yuck, foam.":burp)
;

// add foam left to the glass
if(!$i){$r[34]=o;$i=1;}

// add bubbles
for(;$i++<6;)
    for($n=rand(1,5);$n--;)
        $r[17*$i+rand(2,11)]="°";

// output
echo$r;


问:
Compute the Eulerian number
The Eulerian number A(n, m) is the number of permutations of [1, 2, ..., n] in which exactly m elements are greater than the previous element. These are also called rises. For example, if n = 3, there are 3! = 6 permutations of [1, 2, 3]

```<code>1 2 3
 < <  2 elements are greater than the previous

1 3 2
 < >  1 ...

2 1 3
 > <  1 ...

2 3 1
 < >  1 ...

3 1 2
 > <  1 ...

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

So the outputs for A(3, m) for m in [0, 1, 2, 3] will be

```<code>A(3, 0) = 1
A(3, 1) = 4
A(3, 2) = 1
A(3, 3) = 0
</code>```

Also, this is the OEIS sequence A173018.

Rules

This is code-golf so the shortest code wins.

The input n will be a nonnegative integer and m will be a integer in the range [0, 1, ..., n].

Test Cases

```<code>n   m   A(n, m)
0   0   1
1   0   1
1   1   0
2   0   1
2   1   1
2   2   0
3   0   1
3   1   4
3   2   1
3   3   0
4   0   1
4   1   11
4   2   11
4   3   1
4   4   0
5   1   26
7   4   1191
9   5   88234
10  5   1310354
10  7   47840
10  10  0
12  2   478271
15  6   311387598411
17  1   131054
20  16  1026509354985
42  42  0
</code>```

答:
GameMaker Language, 62 bytes

This is a recursive script A based on @Arnauld's formula.

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

ContentLicense: CC BY-SA 3.0

Title: Compute the Eulerian number

Body:
GameMaker Language, 62 bytes

This is a recursive script A based on @Arnauld's formula.

n=argument0;m=argument1;return (n-m)*A(n-1,m-1)+(m+1)*A(n-1,m)


问:
Sieve of Eratosthenes, Step by Step
Given a number N, draw a left aligned NxN board of numbers, leaving 1 blank (as a space) (I will show diagrams with N=5)

```<code>   2  3  4  5
6  7  8  9  10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
</code>```

Your job is to construct the Sieve of Eratosthenes, step by step. First, start with 2. It's prime, so leave it there, and replace all other numbers divisible by 2 with the proper number of spaces.

```<code>   2  3     5
   7     9
11    13    15
   17    19
21    23    25
</code>```

Next, go to the next unprinted number (3 in this case) and do the same.

```<code>   2  3     5
   7
11    13
   17    19
      23    25
</code>```

And so on, until you reach N.

You need to first print the complete grid, and every time you go to a new number, print the board with the multiples removed. Make sure you print a blank line in between!

Examples

Text in parenthesis () are just for reference, you don't need to print it

N = 2:

```<code>  2 (complete grid)
3 4

  2 (remove multiples of 2)
3
</code>```

N = 3:

```<code>  2 3 (complete grid)
4 5 6
7 8 9

  2 3 (remove multiples of 2)
  5
7   9

  2 3 (remove multiples of 3)
  5
7
</code>```

Remember, this is code-golf, so the code with the smallest number of bytes wins.

Title: Sieve of Eratosthenes, Step by Step

Body:
R, <s>195</s> <s>191</s> <s>185</s> 204 bytes

f=function(N){a=b=1:N^2;i=1;a[1]="";S=sprintf;while(i<=N){for(j in b)cat(a[j]<-S(S("%%-%is",nchar(N^2)),if(j==i|j%%i|i<2)a[j]else ""),if(j%%N)"" else"\n");cat("\n");i=(grep("\\d",a[-(1:i)],v=T)[1]:1)[1]}}

Thanks to @Billywob for 6 extra bytes saved!

Indented, with newlines:

f=function(N){
   a=b=1:N^2 #Initial array
   i=1 #Turn counter
   a[1]="" #1 never shown
   S=sprintf
   while(i<=N){
      for(j in b)
         cat(a[j]<-S(S("%%-%is",nchar(N^2)),if(j==i|j%%i|i<2)a[j]else ""),
             if(j%%N)"" else"\n") #Newline at end of row
      cat("\n") #Newline between turns
      i=(grep("\\d",a[-(1:i)],v=T)[1]:1)[1] #Select next prime as next i
   }
}

Usage:

> f(2)
  2
3 4

  2
3

> f(3)
  2 3
4 5 6
7 8 9

  2 3
  5
7   9

  2 3
  5
7

> f(9)
   2  3  4  5  6  7  8  9
10 11 12 13 14 15 16 17 18
19 20 21 22 23 24 25 26 27
28 29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54
55 56 57 58 59 60 61 62 63
64 65 66 67 68 69 70 71 72
73 74 75 76 77 78 79 80 81

   2  3     5     7     9
   11    13    15    17
19    21    23    25    27
   29    31    33    35
37    39    41    43    45
   47    49    51    53
55    57    59    61    63
   65    67    69    71
73    75    77    79    81

   2  3     5     7
   11    13          17
19          23    25
   29    31          35
37          41    43
   47    49          53
55          59    61
   65    67          71
73          77    79

   2  3     5     7
   11    13          17
19          23
   29    31
37          41    43
   47    49          53
            59    61
         67          71
73          77    79

   2  3     5     7
   11    13          17
19          23
   29    31
37          41    43
   47                53
            59    61
         67          71
73                79

> f(12)
    2   3   4   5   6   7   8   9   10  11  12
13  14  15  16  17  18  19  20  21  22  23  24
25  26  27  28  29  30  31  32  33  34  35  36
37  38  39  40  41  42  43  44  45  46  47  48
49  50  51  52  53  54  55  56  57  58  59  60
61  62  63  64  65  66  67  68  69  70  71  72
73  74  75  76  77  78  79  80  81  82  83  84
85  86  87  88  89  90  91  92  93  94  95  96
97  98  99  100 101 102 103 104 105 106 107 108
109 110 111 112 113 114 115 116 117 118 119 120
121 122 123 124 125 126 127 128 129 130 131 132
133 134 135 136 137 138 139 140 141 142 143 144

    2   3       5       7       9       11
13      15      17      19      21      23
25      27      29      31      33      35
37      39      41      43      45      47
49      51      53      55      57      59
61      63      65      67      69      71
73      75      77      79      81      83
85      87      89      91      93      95
97      99      101     103     105     107
109     111     113     115     117     119
121     123     125     127     129     131
133     135     137     139     141     143

    2   3       5       7               11
13              17      19              23
25              29      31              35
37              41      43              47
49              53      55              59
61              65      67              71
73              77      79              83
85              89      91              95
97              101     103             107
109             113     115             119
121             125     127             131
133             137     139             143

    2   3       5       7               11
13              17      19              23
                29      31
37              41      43              47
49              53                      59
61                      67              71
73              77      79              83
                89      91
97              101     103             107
109             113                     119
121                     127             131
133             137     139             143

    2   3       5       7               11
13              17      19              23
                29      31
37              41      43              47
                53                      59
61                      67              71
73                      79              83
                89
97              101     103             107
109             113
121                     127             131
                137     139             143

    2   3       5       7               11
13              17      19              23
                29      31
37              41      43              47
                53                      59
61                      67              71
73                      79              83
                89
97              101     103             107
109             113
                        127             131
                137     139


问:
List of first n prime numbers most efficiently and in shortest code
Rules are simple:

First n primes (not primes below n), should be printed to standard output separated by newlines (primes should be generated within the code)

primes cannot be generated by an inbuilt function or through a library, i.e. use of a inbuilt or library function such as, prime = get_nth_prime(n), is_a_prime(number), or factorlist = list_all_factors(number) won't be very creative.

Scoring - Say, we define Score = f([number of chars in the code]), O(f(n)) being the complexity of your algorithm where n is the number of primes it finds. So for example, if you have a 300 char code with O(n^2) complexity, score is 300^2 = 90000, for 300 chars with O(n*ln(n)), score becomes 300*5.7 = 1711.13 (let's assume all logs to be natural logs for simplicity)

Use any existing programming language, lowest score wins

Edit: Problem has been changed from finding 'first 1000000 primes' to 'first n primes' because of a confusion about what 'n' in O(f(n)) is, n is the number of primes you find (finding primes is the problem here and so complexity of the problem depends on the number of primes found)

Note: to clarify some confusions on complexity, if 'n' is the number of primes you find and 'N' is the nth prime found, complexity in terms of n is and N are not equivalent i.e. O(f(n)) != O(f(N)) as , f(N) != constant * f(n) and N != constant * n, because we know that nth prime function is not linear, I though since we were finding 'n' primes complexity should be easily expressible in terms of 'n'.

As pointed out by Kibbee, you can visit this site to verify your solutions (here, is the old google docs list)

Please Include these in your solution -

what complexity your program has (include basic analysis if not trivial)

character length of code

the final calculated score

This is my first CodeGolf Question so, if there is a mistake or loophole in above rules please do point them out.

答:
Racket 155 bytes

```<code>(let p((o'(2))(c 3))(cond[(>=(length o)n)(reverse o)][(ormap(λ(x)(= 0(modulo c x)))
(filter(λ(x)(<= x(sqrt c)))o))(p o(add1 c))][(p(cons c o)(add1 c))]))
</code>```

It keeps a list of prime numbers found and checks divisibility of each next number by primes already found. Moreover, it checks only upto the square root of number being tested since that is enough.

Ungolfed:

```<code>(define(nprimes n)
  (let loop ((outl '(2))                   ; outlist having primes being created
             (current 3))                  ; current number being tested
  (cond
    [(>= (length outl) n) (reverse outl)]  ; if n primes found, print outlist.
    [(ormap (λ(x) (= 0 (modulo current x))) ; test if divisible by any previously found prime
            (filter                         ; filter outlist till sqrt of current number
             (λ(x) (<= x (sqrt current)))
             outl))
     (loop outl (add1 current)) ]           ; goto next number without adding to prime list
    [else (loop (cons current outl) (add1 current))] ; add to prime list and go to next number
    )))
</code>```

Testing:

```<code>(nprimes 35)
</code>```

Output:

```<code>'(2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149)
</code>```

Body:
Racket 155 bytes

(let p((o'(2))(c 3))(cond[(>=(length o)n)(reverse o)][(ormap(λ(x)(= 0(modulo c x)))
(filter(λ(x)(<= x(sqrt c)))o))(p o(add1 c))][(p(cons c o)(add1 c))]))

It keeps a list of prime numbers found and checks divisibility of each next number by primes already found. Moreover, it checks only upto the square root of number being tested since that is enough.

Ungolfed:

(define(nprimes n)
  (let loop ((outl '(2))                   ; outlist having primes being created
             (current 3))                  ; current number being tested
  (cond
    [(>= (length outl) n) (reverse outl)]  ; if n primes found, print outlist.
    [(ormap (λ(x) (= 0 (modulo current x))) ; test if divisible by any previously found prime
            (filter                         ; filter outlist till sqrt of current number
             (λ(x) (<= x (sqrt current)))
             outl))
     (loop outl (add1 current)) ]           ; goto next number without adding to prime list
    [else (loop (cons current outl) (add1 current))] ; add to prime list and go to next number
    )))

Testing:

(nprimes 35)

Output:

'(2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149)


答:
JavaScript (ES6), <s>190</s> 189 bytes

Directly prints to the console.

f=(w,k=1,a=[...Array(w*w)].map((_,n)=>n&&n+1))=>k++<=w&&(k==2|a[k-2]&&console.log(a.map((n,x)=>`${n||''}    `.slice(0,`_${w*w}`.length)+(++x%w?'':`
`)).join``),f(w,k,a.map(n=>n==k|n%k&&n)))
```

<h3>Demo</h3>

<p><div class="snippet" data-lang="js" data-hide="true" data-console="true" data-babel="false">
<div class="snippet-code snippet-currently-hidden">
<pre class="snippet-code-js lang-js prettyprint-override"><code>f=(w,k=1,a=[...Array(w*w)].map((_,n)=>n&&n+1))=>k++<=w&&(k==2|a[k-2]&&console.log(a.map((n,x)=>`${n||''}    `.slice(0,`_${w*w}`.length)+(++x%w?'':`
`)).join``),f(w,k,a.map(n=>n==k|n%k&&n)))

f(5)</code>```

Title: Sieve of Eratosthenes, Step by Step

Body:
Given a number N, draw a left aligned NxN board of numbers, leaving 1 blank (as a space) (I will show diagrams with N=5)

```<code>   2  3  4  5
6  7  8  9  10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
</code>```

Your job is to construct the Sieve of Eratosthenes, step by step. First, start with 2. It's prime, so leave it there, and replace all other numbers divisible by 2 with the proper number of spaces.

```<code>   2  3     5
   7     9
11    13    15
   17    19
21    23    25
</code>```

Next, go to the next unprinted number (3 in this case) and do the same.

```<code>   2  3     5
   7
11    13
   17    19
      23    25
</code>```

And so on, until you reach N.

You need to first print the complete grid, and every time you go to a new number, print the board with the multiples removed. Make sure you print a blank line in between!

Examples

Text in parenthesis () are just for reference, you don't need to print it

N = 2:

```<code>  2 (complete grid)
3 4

  2 (remove multiples of 2)
3
</code>```

N = 3:

```<code>  2 3 (complete grid)
4 5 6
7 8 9

  2 3 (remove multiples of 2)
  5
7   9

  2 3 (remove multiples of 3)
  5
7
</code>```

Remember, this is code-golf, so the code with the smallest number of bytes wins.

Body:
JavaScript (ES6), <s>190</s> 189 bytes

Directly prints to the console.

f=(w,k=1,a=[...Array(w*w)].map((_,n)=>n&&n+1))=>k++<=w&&(k==2|a[k-2]&&console.log(a.map((n,x)=>`${n||''}    `.slice(0,`_${w*w}`.length)+(++x%w?'':`
`)).join``),f(w,k,a.map(n=>n==k|n%k&&n)))

Demo

f=(w,k=1,a=[...Array(w*w)].map((_,n)=>n&&n+1))=>k++<=w&&(k==2|a[k-2]&&console.log(a.map((n,x)=>`${n||''}    `.slice(0,`_${w*w}`.length)+(++x%w?'':`
`)).join``),f(w,k,a.map(n=>n==k|n%k&&n)))

f(5)


问:
Take a ride on the Reading, If you pass Go, collect $200

Monopoly Board

For this code-golf challenge we will be building the board game Monopoly.

Rules:

Take no input.

Output a 11x11 board where each ASCII character forming the board is the first letter of each space of the U.S. version of the Monopoly board.

The characters must be separated by spaces.

Go should start in the bottom right.

The exact string to produce is

```<code>F K C I I B A V W M G
N                   P
T                   N
C                   C
S                   P
P                   S
V                   C
S                   P
E                   L
S                   B
J C V C O R I B C M G
</code>```

Note that from bottom right to bottom left the squares are as follows:

```<code>G --> Go
M --> Mediterranean Avenue
C --> Community Chest
B --> Baltic Avenue
I --> Income Tax
...
J --> Jail
</code>```

Edit
Wow! you guys sure liked this one! :)

答:
C#6, <s>192</s> 190 Bytes

```<code>using System.Linq;
string f()=>string.Join("\n","FKCIIBAVWMG~N!P~T!N~C!C~S!P~P!S~V!C~S!P~E!L~S!B~JCVCORIBCMG".Replace("!","         ").Split('~').Select(s=>string.Join(" ",s.Select(c=>c))));
</code>```

Without trailing space; without trailing newline.

A straightforward solution. Start with the literal string. Replace ! by 9 spaces. Then Split into 11 strings by ~, and further to chars (inner Select). Append a space to each character, then Join back to 11 strings. Finally another Join by newline character.

Body:
C#6, <s>192</s> 190 Bytes

using System.Linq;
string f()=>string.Join("\n","FKCIIBAVWMG~N!P~T!N~C!C~S!P~P!S~V!C~S!P~E!L~S!B~JCVCORIBCMG".Replace("!","         ").Split('~').Select(s=>string.Join(" ",s.Select(c=>c))));

Without trailing space; without trailing newline.

A straightforward solution. Start with the literal string. Replace ! by 9 spaces. Then Split into 11 strings by ~, and further to chars (inner Select). Append a space to each character, then Join back to 11 strings. Finally another Join by newline character.


答:
Python 2, 139 bytes

from itertools import*
def p(a):c=complex;r=range(len(a));return sum(reduce(c.__mul__,[a[j][p[j]]for j in r],c(1))for p in permutations(r))
```

repl.it

Implements the naïve algorithm which blindly follows the definition.

ContentLicense: CC BY-SA 4.0

Title: Codegolf the permanent

Body:
The challenge is to write codegolf for the permanent of a matrix.

The permanent of an \$n\times n\$ matrix \$A = a_{i,j}\$) is defined as

$$\text{perm}(A) = \sum_{\sigma \in S_n} \prod^n_{i=1} a_{i,\sigma(i)}$$

Here \$S_n\$ represents the set of all permutations of \$[1, n]\$.

As an example (from the wiki):

$$\text{perm} \left( \begin{matrix}
a & b & c \\
d & e & f \\
g & h & i \\
\end{matrix} \right) = aei + bfg + cdh + ceg + bdi + afh$$

Your code can take input however it wishes and give output in any sensible format but please include in your answer a full worked example including clear instructions for how to supply input to your code. To make the challenge a little more interesting, the matrix may include complex numbers.

The input matrix is always square and will be at most 6 by 6.  You will also need to be able to handle the empty matrix which has permanent 1. There is no need to be able to handle the empty matrix (it was causing too many problems).

Examples

Input:

```<code>[[ 0.36697048+0.02459455j,  0.81148991+0.75269667j,  0.62568185+0.95950937j],
 [ 0.67985923+0.11419187j,  0.50131790+0.13067928j,  0.10330161+0.83532727j],
 [ 0.71085747+0.86199765j,  0.68902048+0.50886302j,  0.52729463+0.5974208j ]]
</code>```

Output:

```<code>-1.7421952844303492+2.2476833142265793j
</code>```

Input:

```<code>[[ 0.83702504+0.05801749j,  0.03912260+0.25027115j,  0.95507961+0.59109069j],
 [ 0.07330546+0.8569899j ,  0.47845015+0.45077079j,  0.80317410+0.5820795j ],
 [ 0.38306447+0.76444045j,  0.54067092+0.90206306j,  0.40001631+0.43832931j]]
</code>```

Output:

```<code>-1.972117936608412+1.6081325306004794j
</code>```

Input:

```<code> [[ 0.61164611+0.42958732j,  0.69306292+0.94856925j,
     0.43860930+0.04104116j,  0.92232338+0.32857505j,
     0.40964318+0.59225476j,  0.69109847+0.32620144j],
   [ 0.57851263+0.69458731j,  0.21746623+0.38778693j,
     0.83334638+0.25805241j,  0.64855830+0.36137045j,
     0.65890840+0.06557287j,  0.25411493+0.37812483j],
   [ 0.11114704+0.44631335j,  0.32068031+0.52023283j,
     0.43360984+0.87037973j,  0.42752697+0.75343656j,
     0.23848512+0.96334466j,  0.28165516+0.13257001j],
   [ 0.66386467+0.21002292j,  0.11781236+0.00967473j,
     0.75491373+0.44880959j,  0.66749636+0.90076845j,
     0.00939420+0.06484633j,  0.21316223+0.4538433j ],
   [ 0.40175631+0.89340763j,  0.26849809+0.82500173j,
     0.84124107+0.23030393j,  0.62689175+0.61870543j,
     0.92430209+0.11914288j,  0.90655023+0.63096257j],
   [ 0.85830178+0.16441943j,  0.91144755+0.49943801j,
     0.51010550+0.60590678j,  0.51439995+0.37354955j,
     0.79986742+0.87723514j,  0.43231194+0.54571625j]]
</code>```

Output:

```<code>-22.92354821347135-90.74278997288275j
</code>```

You may not use any pre-existing functions to compute the permanent.

Body:
Python 2, 139 bytes

from itertools import*
def p(a):c=complex;r=range(len(a));return sum(reduce(c.__mul__,[a[j][p[j]]for j in r],c(1))for p in permutations(r))

repl.it

Implements the naïve algorithm which blindly follows the definition.


问:
Find the Centroid of a Polygon
From Wikipedia:

The centroid of a non-self-intersecting closed polygon
  defined by n vertices (x0,y0),
  (x1,y1), ...,
  (xn−1,yn−1) is the point (Cx,
  Cy), where

and where A is the polygon's signed area,

In these formulas, the vertices are assumed to be numbered in order of
  their occurrence along the polygon's perimeter. Furthermore, the
  vertex ( xn, yn ) is assumed to be the same as
  ( x0, y0 ), meaning i + 1 on the last case
  must loop around to i = 0. Note that if the points are numbered in
  clockwise order the area A, computed as above, will have a negative
  sign; but the centroid coordinates will be correct even in this case.

Given a list of vertices in order (either clockwise, or counter-clockwise), find the centroid of the non-self-intersecting closed polygon represented by the vertices.

If it helps, you may assume input to be only CW, or only CCW. Say so in your answer if you require this.

The coordinates are not required to be integers, and may contain negative numbers.

Input will always be valid and contain at least three vertices.

Inputs only need to be handled that fit in your language's native floating point data type.

You may assume that input numbers will always contain a decimal point.

You may assume that input integers end in . or .0.

You may use complex numbers for input.

Output should be accurate to the nearest thousandth.

Examples

```<code>[(0.,0.), (1.,0.), (1.,1.), (0.,1.)]        -> (0.5, 0.5)
[(-15.21,0.8), (10.1,-0.3), (-0.07,23.55)]  -> -1.727 8.017
[(-39.00,-55.94), (-56.08,-4.73), (-72.64,12.12), (-31.04,53.58), (-30.36,28.29), (17.96,59.17), (0.00,0.00), (10.00,0.00), (20.00,0.00), (148.63,114.32), (8.06,-41.04), (-41.25,34.43)]   -> 5.80104769975, 15.0673812762
</code>```

Too see each polygon on a coordinate plane, paste the coordinates without the square brackets in the "Edit" menu of this page.

I confirmed my results using this Polygon Centroid Point Calculator, which is awful. I couldn't find one that you can input all vertices at once, or that didn't try to erase your - sign when you type it first. I'll post my Python solution for your use after people have had a chance to answer.

答:
Python 2, 153 bytes

Uses no complex numbers.

```<code>P=input()
A=x=y=0;n=len(P)
for i in range(n):m=-~i%n;a=P[i][0];b=P[i][1];c=P[m][0];d=P[m][1];t=a*d-b*c;A+=t;x+=t*(a+c);y+=t*(b+d)
k=1/(3*A);print x*k,y*k
</code>```

Try it online

Ungolfed:

```<code>def centroid(P):
    A=x=y=0
    n=len(P)
    for i in range(n):
        m=-~i%n
        x0=P[i][0];y0=P[i][1]
        x1=P[m][0];y1=P[m][1]
        t = x0*y1 - y0*x1
        A += t/2.
        x += t * (x0 + x1)
        y += t * (y0 + y1)
    k = 1/(6*A)
    x *= k
    y *= k
    return x,y
</code>```

Title: Find the Centroid of a Polygon

Body:
Python 2, 153 bytes

Uses no complex numbers.

P=input()
A=x=y=0;n=len(P)
for i in range(n):m=-~i%n;a=P[i][0];b=P[i][1];c=P[m][0];d=P[m][1];t=a*d-b*c;A+=t;x+=t*(a+c);y+=t*(b+d)
k=1/(3*A);print x*k,y*k

Try it online

Ungolfed:

def centroid(P):
    A=x=y=0
    n=len(P)
    for i in range(n):
        m=-~i%n
        x0=P[i][0];y0=P[i][1]
        x1=P[m][0];y1=P[m][1]
        t = x0*y1 - y0*x1
        A += t/2.
        x += t * (x0 + x1)
        y += t * (y0 + y1)
    k = 1/(6*A)
    x *= k
    y *= k
    return x,y


答:
05AB1E, <s>19</s> <s>14</s> 13 bytes

```<code>œvyvyNè}Pˆ}¯O
</code>```

Try it online!

Explanation

```<code>œ              # get all permutations of rows
 v        }    # for each permutation
  yv   }       # for each row in the permutation
    yNè        # get the element at index row-index
        P      # product of elements
         ˆ     # add product to global array
           ¯O  # sum the products from the global array
</code>```

Title: Codegolf the permanent

Body:
05AB1E, <s>19</s> <s>14</s> 13 bytes

œvyvyNè}Pˆ}¯O

<a href="http://05ab1e.tryitonline.net/#code=xZN2eXZ5TsOofVDLhn3Cr08&input=W1swLjYxMTY0NjExKzAuNDI5NTg3MzJqLDAuNjkzMDYyOTIrMC45NDg1NjkyNWosMC40Mzg2MDkzMCswLjA0MTA0MTE2aiwwLjkyMjMyMzM4KzAuMzI4NTc1MDVqLDAuNDA5NjQzMTgrMC41OTIyNTQ3NmosMC42OTEwOTg0NyswLjMyNjIwMTQ0al0sWzAuNTc4NTEyNjMrMC42OTQ1ODczMWosMC4yMTc0NjYyMyswLjM4Nzc4NjkzaiwwLjgzMzM0NjM4KzAuMjU4MDUyNDFqLDAuNjQ4NTU4MzArMC4zNjEzNzA0NWosMC42NTg5MDg0MCswLjA2NTU3Mjg3aiwwLjI1NDExNDkzKzAuMzc4MTI0ODNqXSxbMC4xMTExNDcwNCswLjQ0NjMxMzM1aiwwLjMyMDY4MDMxKzAuNTIwMjMyODNqLDAuNDMzNjA5ODQrMC44NzAzNzk3M2osMC40Mjc1MjY5NyswLjc1MzQzNjU2aiwwLjIzODQ4NTEyKzAuOTYzMzQ0NjZqLDAuMjgxNjU1MTYrMC4xMzI1NzAwMWpdLFswLjY2Mzg2NDY3KzAuMjEwMDIyOTJqLDAuMTE3ODEyMzYrMC4wMDk2NzQ3M2osMC43NTQ5MTM3MyswLjQ0ODgwOTU5aiwwLjY2NzQ5NjM2KzAuOTAwNzY4NDVqLDAuMDA5Mzk0MjArMC4wNjQ4NDYzM2osMC4yMTMxNjIyMyswLjQ1Mzg0MzNqXSxbMC40MDE3NTYzMSswLjg5MzQwNzYzaiwwLjI2ODQ5ODA5KzAuODI1MDAxNzNqLDAuODQxMjQxMDcrMC4yMzAzMDM5M2osMC42MjY4OTE3NSswLjYxODcwNTQzaiwwLjkyNDMwMjA5KzAuMTE5MTQyODhqLDAuOTA2NTUwMjMrMC42MzA5NjI1N2pdLFswLjg1ODMwMTc4KzAuMTY0NDE5NDNqLDAuOTExNDQ3NTUrMC40OTk0MzgwMWosMC41MTAxMDU1MCswLjYwNTkwNjc4aiwwLjUxNDM5OTk1KzAuMzczNTQ5NTVqLDAuNzk5ODY3NDIrMC44NzcyMzUxNGosMC40MzIzMTE5NCswLjU0NTcxNjI1al1d" rel="nofollow">Try it online!

Explanation

œ              # get all permutations of rows
 v        }    # for each permutation
  yv   }       # for each row in the permutation
    yNè        # get the element at index row-index
        P      # product of elements
         ˆ     # add product to global array
           ¯O  # sum the products from the global array


答:
Jelly, <s>10</s> 9 bytes

```<code>Œ!ŒDḢ€P€S
</code>```

Try it online!

How it works

```<code>Œ!ŒDḢ€P€S  Main link. Argument: M (matrix / 2D array)

Œ!         Generate all permutations of M's rows.
  ŒD       Compute the permutations' diagonals, starting with the main diagonal.
    Ḣ€     Head each; extract the main diagonal of each permutation.
      P€   Product each; compute the products of the main diagonals.
        S  Compute the sum of the products.
</code>```

Title: Codegolf the permanent

Body:
Jelly, <s>10</s> 9 bytes

Œ!ŒDḢ€P€S

<a href="http://jelly.tryitonline.net/#code=xZIhxZJE4bii4oKsUOKCrFM&input=&args=W1sgMC42MTE2NDYxMSswLjQyOTU4NzMyaiwgIDAuNjkzMDYyOTIrMC45NDg1NjkyNWosCiAgICAgMC40Mzg2MDkzMCswLjA0MTA0MTE2aiwgIDAuOTIyMzIzMzgrMC4zMjg1NzUwNWosCiAgICAgMC40MDk2NDMxOCswLjU5MjI1NDc2aiwgIDAuNjkxMDk4NDcrMC4zMjYyMDE0NGpdLAogICBbIDAuNTc4NTEyNjMrMC42OTQ1ODczMWosICAwLjIxNzQ2NjIzKzAuMzg3Nzg2OTNqLAogICAgIDAuODMzMzQ2MzgrMC4yNTgwNTI0MWosICAwLjY0ODU1ODMwKzAuMzYxMzcwNDVqLAogICAgIDAuNjU4OTA4NDArMC4wNjU1NzI4N2osICAwLjI1NDExNDkzKzAuMzc4MTI0ODNqXSwKICAgWyAwLjExMTE0NzA0KzAuNDQ2MzEzMzVqLCAgMC4zMjA2ODAzMSswLjUyMDIzMjgzaiwKICAgICAwLjQzMzYwOTg0KzAuODcwMzc5NzNqLCAgMC40Mjc1MjY5NyswLjc1MzQzNjU2aiwKICAgICAwLjIzODQ4NTEyKzAuOTYzMzQ0NjZqLCAgMC4yODE2NTUxNiswLjEzMjU3MDAxal0sCiAgIFsgMC42NjM4NjQ2NyswLjIxMDAyMjkyaiwgIDAuMTE3ODEyMzYrMC4wMDk2NzQ3M2osCiAgICAgMC43NTQ5MTM3MyswLjQ0ODgwOTU5aiwgIDAuNjY3NDk2MzYrMC45MDA3Njg0NWosCiAgICAgMC4wMDkzOTQyMCswLjA2NDg0NjMzaiwgIDAuMjEzMTYyMjMrMC40NTM4NDMzaiBdLAogICBbIDAuNDAxNzU2MzErMC44OTM0MDc2M2osICAwLjI2ODQ5ODA5KzAuODI1MDAxNzNqLAogICAgIDAuODQxMjQxMDcrMC4yMzAzMDM5M2osICAwLjYyNjg5MTc1KzAuNjE4NzA1NDNqLAogICAgIDAuOTI0MzAyMDkrMC4xMTkxNDI4OGosICAwLjkwNjU1MDIzKzAuNjMwOTYyNTdqXSwKICAgWyAwLjg1ODMwMTc4KzAuMTY0NDE5NDNqLCAgMC45MTE0NDc1NSswLjQ5OTQzODAxaiwKICAgICAwLjUxMDEwNTUwKzAuNjA1OTA2NzhqLCAgMC41MTQzOTk5NSswLjM3MzU0OTU1aiwKICAgICAwLjc5OTg2NzQyKzAuODc3MjM1MTRqLCAgMC40MzIzMTE5NCswLjU0NTcxNjI1al1d" rel="nofollow">Try it online!

How it works

Œ!ŒDḢ€P€S  Main link. Argument: M (matrix / 2D array)

Œ!         Generate all permutations of M's rows.
  ŒD       Compute the permutations' diagonals, starting with the main diagonal.
    Ḣ€     Head each; extract the main diagonal of each permutation.
      P€   Product each; compute the products of the main diagonals.
        S  Compute the sum of the products.


答:
Python 2, 75 bytes

Seems clunky... should be beatable.

P=lambda m,i=0:sum([r[i]*P(m[:j]+m[j+1:],i+1)for j,r in enumerate(m)]or[1])
```

Title: Codegolf the permanent


答:
Perl 5, 92 86 bytes

saved 6 bytes thanks to Dada

```<code>$a="%s "x11;printf"$a
"."%s%20s
"x9 .$a,FKCIIBAVWMGNPTNCCSPPSVCSPELSBJCVCORIBCMG=~/./g
</code>```

Uses sprintf, padding and the string repeat operator x.

Title: Take a ride on the Reading, If you pass Go, collect $200

Body:
Monopoly Board

For this code-golf challenge we will be building the board game Monopoly.

Rules:

Take no input.

Output a 11x11 board where each ASCII character forming the board is the first letter of each space of the U.S. version of the Monopoly board.

The characters must be separated by spaces.

Go should start in the bottom right.

The exact string to produce is

```<code>F K C I I B A V W M G
N                   P
T                   N
C                   C
S                   P
P                   S
V                   C
S                   P
E                   L
S                   B
J C V C O R I B C M G
</code>```

Note that from bottom right to bottom left the squares are as follows:

```<code>G --> Go
M --> Mediterranean Avenue
C --> Community Chest
B --> Baltic Avenue
I --> Income Tax
...
J --> Jail
</code>```

Edit
Wow! you guys sure liked this one! :)

Body:
Perl 5, 92 86 bytes

saved 6 bytes thanks to Dada

$a="%s "x11;printf"$a
"."%s%20s
"x9 .$a,FKCIIBAVWMGNPTNCCSPPSVCSPELSBJCVCORIBCMG=~/./g

Uses sprintf, padding and the string repeat operator x.


答:
Ruby, 74 63 bytes

```<code>->a{p=0;a.permutation{|b|n=1;i=-1;a.map{n*=b[i+=1][i]};p+=n};p}
</code>```

A straightforward translation of the formula. Several bytes saved thanks to ezrast.

Explanation

```<code>->a{
    # Initialize the permanent to 0
    p=0
    # For each permutation of a's rows...
    a.permutation{|b|
        # ... initialize the product to 1,
        n=1
        # initialize the index to -1; we'll use this to go down the main diagonal
        # (i starts at -1 because at each step, the first thing we do is increment i),
        i=-1
        # iteratively calculate the product,
        a.map{
            n*=b[i+=1][i]
        }
        # increase p by the main diagonal's product.
        p+=n
    }
    p
}
</code>```

Title: Codegolf the permanent

Body:
Ruby, 74 63 bytes

->a{p=0;a.permutation{|b|n=1;i=-1;a.map{n*=b[i+=1][i]};p+=n};p}

A straightforward translation of the formula. Several bytes saved thanks to ezrast.

Explanation

->a{
    # Initialize the permanent to 0
    p=0
    # For each permutation of a's rows...
    a.permutation{|b|
        # ... initialize the product to 1,
        n=1
        # initialize the index to -1; we'll use this to go down the main diagonal
        # (i starts at -1 because at each step, the first thing we do is increment i),
        i=-1
        # iteratively calculate the product,
        a.map{
            n*=b[i+=1][i]
        }
        # increase p by the main diagonal's product.
        p+=n
    }
    p
}


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

```<code>tZyt:tY@X])!ps
</code>```

Try it Online

Explanation

```<code>t       % Implicitly grab input and duplicate
Zy      % Compute the size of the input. Yields [rows, columns]
t:      % Compute an array from [1...rows]
tY@     % Duplicate this array and compute all permutations (these are the columns)
X]      % Convert row/column to linear indices into the input matrix
)       % Index into the input matrix where each combination is a row
!p      % Take the product of each row
s       % Sum the result and implicitly display
</code>```

Title: Codegolf the permanent

Body:
MATL, <s>17</s>14 bytes

tZyt:tY@X])!ps

Try it Online

Explanation

t       % Implicitly grab input and duplicate
Zy      % Compute the size of the input. Yields [rows, columns]
t:      % Compute an array from [1...rows]
tY@     % Duplicate this array and compute all permutations (these are the columns)
X]      % Convert row/column to linear indices into the input matrix
)       % Index into the input matrix where each combination is a row
!p      % Take the product of each row
s       % Sum the result and implicitly display


问:
Draw an asterisk triangle
Inspired by a task for Programming 101, here's a challenge that hopefully isn't too easy (or a duplicate).

Input:

A positive integer n >= 1.

Output:

n lines of asterisks, where every new line has one asterisk more than the line before, and starting with one asterisk in the first line.

Test case (n=5):

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

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

答:
05AB1E, 8 bytes

```<code>TžQè×.p»
</code>```

Explanation coming soon

Title: Draw an asterisk triangle

Body:
05AB1E, 8 bytes

TžQè×.p»

Explanation coming soon


问:
Add two numbers
Input: Two integers. Preferably decimal integers, but other forms of numbers can be used. These can be given to the code in standard input, as arguments to the program or function, or as a list.

Output: Their sum. Use the same format for output integers as input integers. For example, the input 5 16 would lead to the output 21.

Restrictions: No standard loopholes please. This is code-golf, answer in lowest amount of bytes wins.

Notes: This should be fairly trivial, however I'm interested to see how it can be implemented. The answer can be a complete program or a function, but please identify which one it is.

Test cases:

```<code>1 2 -> 3
14 15 -> 29
7 9 -> 16
-1 8 -> 7
8 -9 -> -1
-8 -9 -> -17
</code>```

Or as CSV:

```<code>a,b,c
1,2,3
14,15,29
7,9,16
-1,8,7
8,-9,-1
-8,-9,-17
</code>```

Leaderboard

var QUESTION_ID=84260,OVERRIDE_USER=8478;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

```

答:
JavaScript, 27 bytes

```<code>function s(a,b){return a+b}
</code>```

I thought this needed a semi-colon after the return statement, but when typing it into the Chrome Console, it works fine without.

Title: Add two numbers

Body:
JavaScript, 27 bytes

function s(a,b){return a+b}

I thought this needed a semi-colon after the return statement, but when typing it into the Chrome Console, it works fine without.


答:
Haskell, 59 bytes

```<code>a#((b:c):r)=b*p(a++map tail r)+(c:a)#r
_#_=0
p[]=1
p l=[]#l
</code>```

This does a Laplace-like development along the first column, and uses that the order of the rows doesn't matter. It works for any numeric type.

Input is as list of lists:

```<code>Prelude> p [[1,2],[3,4]]
10
</code>```

Title: Codegolf the permanent

Body:
Haskell, 59 bytes

a#((b:c):r)=b*p(a++map tail r)+(c:a)#r
_#_=0
p[]=1
p l=[]#l

This does a Laplace-like development along the first column, and uses that the order of the rows doesn't matter. It works for any numeric type.

Input is as list of lists:

Prelude> p [[1,2],[3,4]]
10


问:
Compute the histogram entropy estimation of a string
Write a program or function that estimates the Shannon entropy of a given string.

If a string has n characters, d distinct characters, xi is the i th distinct character, and P(xi) is the probability of that character occuring in the string, then our Shannon entropy estimate for that string is given by:

For the estimation in this challenge we assume that the probability of a character occurring in a string is simply the number of times it occurs divided by the total number of characters.

Your answer must be accurate to at least 3 digits after the period.

Test cases:

```<code>"This is a test.", 45.094
"00001111", 8.000
"cwmfjordbankglyphsvextquiz", 122.211
"             ", 0.0
</code>```

答:
C#, 159 bytes

Golfed:

```<code>string f(string s){var l=s.Length;double sum=0;foreach(var item in s.GroupBy(o=>o)){double p=(double)item.Count()/l;sum+=p*Math.Log(p,2);}return(sum*=-l)+"";}}
</code>```

Ungolfed:

```<code>string f(string s)
{
  var l = s.Length;
  double sum = 0;
  foreach (var item in s.GroupBy(o => o))
  {
    double p = (double)item.Count() / l;
    sum += p * Math.Log(p, 2);
  }
  return (sum *= -l) + "";
}
</code>```

Test:

```<code>var codeGolf = new StringHistogramEntropyEstimation();
    Console.WriteLine(codeGolf.f("This is a test.")); //45.0935839298008
    Console.WriteLine(codeGolf.f("00001111")); //8
    Console.WriteLine(codeGolf.f("cwmfjordbankglyphsvextquiz")); //122.211432671668
    Console.WriteLine(codeGolf.f("             ")); //0
</code>```

Body:
C#, 159 bytes

Golfed:

string f(string s){var l=s.Length;double sum=0;foreach(var item in s.GroupBy(o=>o)){double p=(double)item.Count()/l;sum+=p*Math.Log(p,2);}return(sum*=-l)+"";}}

Ungolfed:

string f(string s)
{
  var l = s.Length;
  double sum = 0;
  foreach (var item in s.GroupBy(o => o))
  {
    double p = (double)item.Count() / l;
    sum += p * Math.Log(p, 2);
  }
  return (sum *= -l) + "";
}

Test:

var codeGolf = new StringHistogramEntropyEstimation();
    Console.WriteLine(codeGolf.f("This is a test.")); //45.0935839298008
    Console.WriteLine(codeGolf.f("00001111")); //8
    Console.WriteLine(codeGolf.f("cwmfjordbankglyphsvextquiz")); //122.211432671668
    Console.WriteLine(codeGolf.f("             ")); //0


答:
Ruby, 17 bytes

** Edit: Big thank you to @steenbergh and @TùxCräftîñg for their help **

```<code>def c(a,b)a+b end
</code>```

Title: Add two numbers

Body:
Input: Two integers. Preferably decimal integers, but other forms of numbers can be used. These can be given to the code in standard input, as arguments to the program or function, or as a list.

Output: Their sum. Use the same format for output integers as input integers. For example, the input 5 16 would lead to the output 21.

Restrictions: No standard loopholes please. This is code-golf, answer in lowest amount of bytes wins.

Notes: This should be fairly trivial, however I'm interested to see how it can be implemented. The answer can be a complete program or a function, but please identify which one it is.

Test cases:

```<code>1 2 -> 3
14 15 -> 29
7 9 -> 16
-1 8 -> 7
8 -9 -> -1
-8 -9 -> -17
</code>```

Or as CSV:

```<code>a,b,c
1,2,3
14,15,29
7,9,16
-1,8,7
8,-9,-1
-8,-9,-17
</code>```

Leaderboard

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Body:
Ruby, 17 bytes

** Edit: Big thank you to @steenbergh and @TùxCräftîñg for their help **

def c(a,b)a+b end


问:
A regex to satisfy the grammar police (there vs. their vs they're)
We've all been burned by the grammar police on the internet. What we need is a regex that can be used in place of "there", "their", and "they're". This would shift burden of grammar parsing from the writer to the reader (a sort of "client-side" grammar, if we you will). So, here's what I have to start with:

the([re]|[ir]|[y're]).

...but I'm positive there's room for optimization.

What's the shortest regex that could be used in place of any variation or the aforementioned homohpones?

答:
There isn't a lot of room for optimisation here. This seems to be optimal:

```<code>the(y're|re|ir)
</code>```

The only alternative I can think of avoids the duplication of re but ends up at the same byte count (and it's potentially worse in flavours where meta characters need to be escaped to work):

```<code>the((y')?re|ir)
</code>```

Body:
There isn't a lot of room for optimisation here. This seems to be optimal:

the(y're|re|ir)

The only alternative I can think of avoids the duplication of re but ends up at the same byte count (and it's potentially worse in flavours where meta characters need to be escaped to work):

the((y')?re|ir)


问:
Calculate A190810
Your task is pretty simple, calculate the n-th element of A190810.

Elements of A190810 are calculated according to these rules:

The first element is 1

The sequence is increasing

If x occurs in the sequence, then 2x+1 and 3x-1 also do

You can use 1-based or 0-based indexing, but if you use 0-based indexing, please say it in the answer.

Test cases

```<code>a(1) = 1
a(2) = 2
a(3) = 3
a(4) = 5
a(5) = 7
a(10) = 17
a(20) = 50
a(30) = 95
a(55) = 255
</code>```

Since this is code-golf, the shortest answer in bytes wins!

答:
Ruby, 70 bytes

```<code>->n{a=*1
n.times{a<<a.map{|i|([2*i+1,3*i-1]-a).min||1.0/0}.min}
a[-2]}
</code>```

Explanation

```<code>->n{
    # Magical, golfy way of initializing an array. Equivalent to a = [1].
    a=*1
    n.times{
        # Generate the next element in the sequence, by...
        a<<
            # ... finding the minimal term that will appear at some point.
            a.map{|i|
                ([2*i+1,3*i-1]-a).min||1.0/0
            }.min
    }
    # We generated n+1 elements, so we'll take the *second* to last one.
    a[-2]
}
</code>```

Title: Calculate A190810

Body:
Ruby, 70 bytes

->n{a=*1
n.times{a<<a.map{|i|([2*i+1,3*i-1]-a).min||1.0/0}.min}
a[-2]}

Explanation

->n{
    # Magical, golfy way of initializing an array. Equivalent to a = [1].
    a=*1
    n.times{
        # Generate the next element in the sequence, by...
        a<<
            # ... finding the minimal term that will appear at some point.
            a.map{|i|
                ([2*i+1,3*i-1]-a).min||1.0/0
            }.min
    }
    # We generated n+1 elements, so we'll take the *second* to last one.
    a[-2]
}


答:
C, 49 bytes

```<code>main(a,b){scanf("%d %d",&a,&b);printf("%d",a+b);}
</code>```

Can't really do much to golf it down.

For fun:

The following works only if 0 <= sum < 256 (it's 59 bytes long):

```<code>a;main(c,v)char**v;{return a++&2?c-3:main(c+atoi(*++v),v);}
</code>```

Use gcc to compile, and ./a.out [your 2 nums]; echo $? to run it.

Here's the ungolfed version of that program:

```<code>/* Global int auto-initialized to 0 */
a;

/* The main method with two int params */
/* 'c' is argc, and 'v' is argv */
main(c, v)

/* Yes, this is valid. It defines 'v' as a char** */
char** v;

{
    /* Checks to see if a == 2, and increments a.
     * I only want recursion to happen twice. */
    if (a++ & 2)
    {
        /* Since "argc" is 3, we need to subtract it from the final answer */
        return c - 3;
    }
    else
    {
        /* Get the next int value of "argv" and add it to 'c'.
         * Then call main() again with the updated value */
        return main(c + atoi(*++v), v);
    }
}
</code>```

So, main() returns the value of the sum of the two numbers (essentially, I'm forcing it to return a custom exit code). The program won't output the exit code, so calling echo $?, in the same command as running the program, outputs the return value of that program.

The range of exit codes only exist between 0 and 255, so if you run the program trying to sum 255 and 1, it will wrap around and output 0.

Title: Add two numbers

Body:
C, 49 bytes

main(a,b){scanf("%d %d",&a,&b);printf("%d",a+b);}

Can't really do much to golf it down.

For fun:

The following works only if 0 <= sum < 256 (it's 59 bytes long):

a;main(c,v)char**v;{return a++&2?c-3:main(c+atoi(*++v),v);}

Use gcc to compile, and ./a.out [your 2 nums]; echo $? to run it.

Here's the ungolfed version of that program:

/* Global int auto-initialized to 0 */
a;

/* The main method with two int params */
/* 'c' is argc, and 'v' is argv */
main(c, v)

/* Yes, this is valid. It defines 'v' as a char** */
char** v;

{
    /* Checks to see if a == 2, and increments a.
     * I only want recursion to happen twice. */
    if (a++ & 2)
    {
        /* Since "argc" is 3, we need to subtract it from the final answer */
        return c - 3;
    }
    else
    {
        /* Get the next int value of "argv" and add it to 'c'.
         * Then call main() again with the updated value */
        return main(c + atoi(*++v), v);
    }
}

So, main() returns the value of the sum of the two numbers (essentially, I'm forcing it to return a custom exit code). The program won't output the exit code, so calling echo $?, in the same command as running the program, outputs the return value of that program.

The range of exit codes only exist between 0 and 255, so if you run the program trying to sum 255 and 1, it will wrap around and output 0.


答:
J, 5 bytes

```<code>+/ .*
</code>```

J does not offer builtins for the permanent or determinant but instead offers a conjunction u . v y which recursively expands y along the minors and calculates dyadic u . v between the cofactors and the output of the recursive call on the minors. The choices of u and v can vary. For example, using u =: -/ and v =: * is -/ .* which is the determinant. Choices can even by %/ .! where u=: %/, reduce by division, and v =: ! which is binomial coefficient. I'm not sure what that output signifies but you're free to choose your verbs.

An alternative implementation for 47 bytes using the same method in my Mathematica answer.

```<code>_1{[:($@]$[:+//.*/)/0,.;@(<@(,0#~<:)"+2^i.@#)"{
</code>```

This simulates a polynomial with n variables by creating a polynomial with one variable raised to powers of 2. This is held as a coefficient list and polynomial multiplication is performed using convolution, and the index at 2n will contain the result.

Another implementation for 31 bytes is

```<code>+/@({.*1$:\.|:@}.)`(0{,)@.(1=#)
</code>```

which is a slightly golfed version based on Laplace expansion taken from the J essay on determinants.

Usage

```<code>   f =: +/ .*
   f 0 0 $ 0 NB. the empty matrix, create a shape with dimensions 0 x 0
1
   f 0.36697048j0.02459455 0.81148991j0.75269667 0.62568185j0.95950937 , 0.67985923j0.11419187  0.50131790j0.13067928 0.10330161j0.83532727 ,: 0.71085747j0.86199765 0.68902048j0.50886302 0.52729463j0.5974208
_1.7422j2.24768
   f 0.83702504j0.05801749 0.03912260j0.25027115 0.95507961j0.59109069 , 0.07330546j0.8569899 0.47845015j0.45077079 0.80317410j0.5820795 ,: 0.38306447j0.76444045 0.54067092j0.90206306 0.40001631j0.43832931
_1.97212j1.60813
   f 0.61164611j0.42958732 0.69306292j0.94856925 0.4386093j0.04104116 0.92232338j0.32857505 0.40964318j0.59225476 0.69109847j0.32620144 , 0.57851263j0.69458731 0.21746623j0.38778693 0.83334638j0.25805241 0.6485583j0.36137045 0.6589084j0.06557287 0.25411493j0.37812483 , 0.11114704j0.44631335 0.32068031j0.52023283 0.43360984j0.87037973 0.42752697j0.75343656 0.23848512j0.96334466 0.28165516j0.13257001 , 0.66386467j0.21002292 0.11781236j0.00967473 0.75491373j0.44880959 0.66749636j0.90076845 0.0093942j0.06484633 0.21316223j0.4538433 , 0.40175631j0.89340763 0.26849809j0.82500173 0.84124107j0.23030393 0.62689175j0.61870543 0.92430209j0.11914288 0.90655023j0.63096257 ,: 0.85830178j0.16441943 0.91144755j0.49943801 0.5101055j0.60590678 0.51439995j0.37354955 0.79986742j0.87723514 0.43231194j0.54571625
_22.9235j_90.7428
</code>```

Title: Codegolf the permanent

Body:
The challenge is to write codegolf for the permanent of a matrix.

The permanent of an \$n\times n\$ matrix \$A = a_{i,j}\$) is defined as

$$\text{perm}(A) = \sum_{\sigma \in S_n} \prod^n_{i=1} a_{i,\sigma(i)}$$

Here \$S_n\$ represents the set of all permutations of \$[1, n]\$.

As an example (from the wiki):

$$\text{perm} \left( \begin{matrix}
a & b & c \\
d & e & f \\
g & h & i \\
\end{matrix} \right) = aei + bfg + cdh + ceg + bdi + afh$$

Your code can take input however it wishes and give output in any sensible format but please include in your answer a full worked example including clear instructions for how to supply input to your code. To make the challenge a little more interesting, the matrix may include complex numbers.

The input matrix is always square and will be at most 6 by 6.  You will also need to be able to handle the empty matrix which has permanent 1. There is no need to be able to handle the empty matrix (it was causing too many problems).

Examples

Input:

```<code>[[ 0.36697048+0.02459455j,  0.81148991+0.75269667j,  0.62568185+0.95950937j],
 [ 0.67985923+0.11419187j,  0.50131790+0.13067928j,  0.10330161+0.83532727j],
 [ 0.71085747+0.86199765j,  0.68902048+0.50886302j,  0.52729463+0.5974208j ]]
</code>```

Output:

```<code>-1.7421952844303492+2.2476833142265793j
</code>```

Input:

```<code>[[ 0.83702504+0.05801749j,  0.03912260+0.25027115j,  0.95507961+0.59109069j],
 [ 0.07330546+0.8569899j ,  0.47845015+0.45077079j,  0.80317410+0.5820795j ],
 [ 0.38306447+0.76444045j,  0.54067092+0.90206306j,  0.40001631+0.43832931j]]
</code>```

Output:

```<code>-1.972117936608412+1.6081325306004794j
</code>```

Input:

```<code> [[ 0.61164611+0.42958732j,  0.69306292+0.94856925j,
     0.43860930+0.04104116j,  0.92232338+0.32857505j,
     0.40964318+0.59225476j,  0.69109847+0.32620144j],
   [ 0.57851263+0.69458731j,  0.21746623+0.38778693j,
     0.83334638+0.25805241j,  0.64855830+0.36137045j,
     0.65890840+0.06557287j,  0.25411493+0.37812483j],
   [ 0.11114704+0.44631335j,  0.32068031+0.52023283j,
     0.43360984+0.87037973j,  0.42752697+0.75343656j,
     0.23848512+0.96334466j,  0.28165516+0.13257001j],
   [ 0.66386467+0.21002292j,  0.11781236+0.00967473j,
     0.75491373+0.44880959j,  0.66749636+0.90076845j,
     0.00939420+0.06484633j,  0.21316223+0.4538433j ],
   [ 0.40175631+0.89340763j,  0.26849809+0.82500173j,
     0.84124107+0.23030393j,  0.62689175+0.61870543j,
     0.92430209+0.11914288j,  0.90655023+0.63096257j],
   [ 0.85830178+0.16441943j,  0.91144755+0.49943801j,
     0.51010550+0.60590678j,  0.51439995+0.37354955j,
     0.79986742+0.87723514j,  0.43231194+0.54571625j]]
</code>```

Output:

```<code>-22.92354821347135-90.74278997288275j
</code>```

You may not use any pre-existing functions to compute the permanent.

Body:
J, 5 bytes

+/ .*

J does not offer builtins for the permanent or determinant but instead offers a conjunction u . v y which recursively expands y along the minors and calculates dyadic u . v between the cofactors and the output of the recursive call on the minors. The choices of u and v can vary. For example, using u =: -/ and v =: * is -/ .* which is the determinant. Choices can even by %/ .! where u=: %/, reduce by division, and v =: ! which is binomial coefficient. I'm not sure what that output signifies but you're free to choose your verbs.

An alternative implementation for 47 bytes using the same method in my Mathematica answer.

_1{[:($@]$[:+//.*/)/0,.;@(<@(,0#~<:)"+2^i.@#)"{

This simulates a polynomial with n variables by creating a polynomial with one variable raised to powers of 2. This is held as a coefficient list and polynomial multiplication is performed using convolution, and the index at 2n will contain the result.

Another implementation for 31 bytes is

+/@({.*1$:\.|:@}.)`(0{,)@.(1=#)

which is a slightly golfed version based on Laplace expansion taken from the J essay on determinants.

Usage

   f =: +/ .*
   f 0 0 $ 0 NB. the empty matrix, create a shape with dimensions 0 x 0
1
   f 0.36697048j0.02459455 0.81148991j0.75269667 0.62568185j0.95950937 , 0.67985923j0.11419187  0.50131790j0.13067928 0.10330161j0.83532727 ,: 0.71085747j0.86199765 0.68902048j0.50886302 0.52729463j0.5974208
_1.7422j2.24768
   f 0.83702504j0.05801749 0.03912260j0.25027115 0.95507961j0.59109069 , 0.07330546j0.8569899 0.47845015j0.45077079 0.80317410j0.5820795 ,: 0.38306447j0.76444045 0.54067092j0.90206306 0.40001631j0.43832931
_1.97212j1.60813
   f 0.61164611j0.42958732 0.69306292j0.94856925 0.4386093j0.04104116 0.92232338j0.32857505 0.40964318j0.59225476 0.69109847j0.32620144 , 0.57851263j0.69458731 0.21746623j0.38778693 0.83334638j0.25805241 0.6485583j0.36137045 0.6589084j0.06557287 0.25411493j0.37812483 , 0.11114704j0.44631335 0.32068031j0.52023283 0.43360984j0.87037973 0.42752697j0.75343656 0.23848512j0.96334466 0.28165516j0.13257001 , 0.66386467j0.21002292 0.11781236j0.00967473 0.75491373j0.44880959 0.66749636j0.90076845 0.0093942j0.06484633 0.21316223j0.4538433 , 0.40175631j0.89340763 0.26849809j0.82500173 0.84124107j0.23030393 0.62689175j0.61870543 0.92430209j0.11914288 0.90655023j0.63096257 ,: 0.85830178j0.16441943 0.91144755j0.49943801 0.5101055j0.60590678 0.51439995j0.37354955 0.79986742j0.87723514 0.43231194j0.54571625
_22.9235j_90.7428


答:
Brainfuck, 129 bytes

I know there's already a shorter answer in brainfuck, however I wanted to create a program which could handle a multi-digit number input rather than either a single-digit input or a single ascii character input unlike the previous one posted.

```<code>,[>+++[->++++[-<<---->>]<]+>,]<-<<[<<]>>[<[->>++++++++++<<]>>>]+>>++++++++++>>++++++[-<+++++++>]<<<<<[>[->+>>.<<<]>>.<[-<+>]<+<-]
</code>```

This is my first ever brainfuck program and it will work for any input between 0 and the maximum size of a single cell (traditionally 8 bits or 255) entered using the characters '0' to '9' (corresponding to ascii-values 048-057)

Explanation

The first part of this program,  ,[>+++[->++++[-<<---->>]<]+>,], takes the input numbers as char values and removes 48 from each to make them equal to the numbers 0 to 9 rather than the char values of the numbers 0 to 9. It stores these in separate cells with a 1 in between each of them so that the start and end points can be found again.

The second part, <-<<[<<]>>[<[->>++++++++++<<]>>>], consolidates the separate values into one cell. This is why the maximum size of a cell controls how high a number can be.

The third section, +>>++++++++++>>++++++[-<+++++++>]<<<<<, is used to set up the other cells needed: one with the number of asterisks per line, one with the code for a linefeed and one with the code for an asterisk. There is also a blank cell left for working with later.

The remainder of the code, [>[->+>>.<<<]>>.<[-<+>]<+<-], is used to:

Output as many asterisks as necessary

Output a linefeed

Reset the value of the cell controlling the asterisks

Increment the control cell

Decrement the cell with the number until it equals 0

Title: Draw an asterisk triangle

Body:
Inspired by a task for Programming 101, here's a challenge that hopefully isn't too easy (or a duplicate).

Input:

A positive integer n >= 1.

Output:

n lines of asterisks, where every new line has one asterisk more than the line before, and starting with one asterisk in the first line.

Test case (n=5):

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

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

Body:
Brainfuck, 129 bytes

I know there's already a shorter answer in brainfuck, however I wanted to create a program which could handle a multi-digit number input rather than either a single-digit input or a single ascii character input unlike the previous one posted.

,[>+++[->++++[-<<---->>]<]+>,]<-<<[<<]>>[<[->>++++++++++<<]>>>]+>>++++++++++>>++++++[-<+++++++>]<<<<<[>[->+>>.<<<]>>.<[-<+>]<+<-]

This is my first ever brainfuck program and it will work for any input between 0 and the maximum size of a single cell (traditionally 8 bits or 255) entered using the characters '0' to '9' (corresponding to ascii-values 048-057)

Explanation

The first part of this program,  ,[>+++[->++++[-<<---->>]<]+>,], takes the input numbers as char values and removes 48 from each to make them equal to the numbers 0 to 9 rather than the char values of the numbers 0 to 9. It stores these in separate cells with a 1 in between each of them so that the start and end points can be found again.

The second part, <-<<[<<]>>[<[->>++++++++++<<]>>>], consolidates the separate values into one cell. This is why the maximum size of a cell controls how high a number can be.

The third section, +>>++++++++++>>++++++[-<+++++++>]<<<<<, is used to set up the other cells needed: one with the number of asterisks per line, one with the code for a linefeed and one with the code for an asterisk. There is also a blank cell left for working with later.

The remainder of the code, [>[->+>>.<<<]>>.<[-<+>]<+<-], is used to:

Output as many asterisks as necessary

Output a linefeed

Reset the value of the cell controlling the asterisks

Increment the control cell

Decrement the cell with the number until it equals 0


问:
Obfuscated Hello World
Create the shortest possible obfuscated program that displays the text "Hello World".

In order to be considered an obfuscated program, it must meet at least two of the following requirements:

Does not contain the characters: h, l, w and d in any case

Does not contain the characters: e, o, r, 0, and 1 in any case

Does not contain the characters: 2 or 7

Input:

none

Output:

Hello World

Leaderboard

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

/* Configuration */

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

/* App */

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

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

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

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

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

getAnswers();

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

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

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

function process() {
  var valid = [];

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

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

  });

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

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

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

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

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

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

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

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

table thead {
  font-weight: bold;
}

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
C 61 Bytes

```<code>main(){printf("%ce%c%co %cor%c%c",9*8,108,108,86+1,108,100);}
</code>```

Went as small as possible on this guy. Hopefully y'all can see that. This breaks rule 2.

Title: Obfuscated Hello World

Body:
C 61 Bytes

main(){printf("%ce%c%co %cor%c%c",9*8,108,108,86+1,108,100);}

Went as small as possible on this guy. Hopefully y'all can see that. This breaks rule 2.


问:
N(e(s(t))) a string
To "function nest" a string, you must:

Treat the first character as a function, and the following characters as the arguments to that function. For example, if the input string was Hello, then the first step would be:

```<code>H(ello)
</code>```

Then, repeat this same step for every substring. So we get:

```<code>H(ello)
H(e(llo))
H(e(l(lo)))
H(e(l(l(o))))
</code>```

Your task is to write a program or function that "function nests" a string. For example, if the input string was Hello world!, then you should output:

```<code>H(e(l(l(o( (w(o(r(l(d(!)))))))))))
</code>```

The input will only ever contain printable ASCII, and you may take the input and the output in any reasonable format. For example, STDIN/STDOUT, function arguments and return value, reading and writing to a file, etc.

For simplicity's sake, you may also assume the input will not contain parentheses, and will not be empty.

```<code>Input:
Nest a string
Output:
N(e(s(t( (a( (s(t(r(i(n(g))))))))))))

Input:
foobar
Output:
f(o(o(b(a(r)))))

Input:
1234567890
Output:
1(2(3(4(5(6(7(8(9(0)))))))))

Input:
code-golf
Output:
c(o(d(e(-(g(o(l(f))))))))

Input:
a
Output:
a

Input:
42
Output:
4(2)
</code>```

As usual, all of our default rules and loopholes apply, and the shortest answer scored in bytes wins!

Title: N(e(s(t))) a string

Body:
C, <s>84</s> <s>82</s> <s>76</s> <s>70</s> <s>68</s> 66 Bytes

i;f(char*s){for(i=1;*s+~i;putchar(*s?i&1?*s++:40:41),i+=*s?1:-2);}

Now using just one for loop and one putchar...

Test is like this

main(c,v)char**v;
{
    f(v[1]);puts("");
    f("foobar");puts("");
    f("code-golf");puts("");
}

output

H(e(l(l(o( (W(o(r(l(d))))))))))
f(o(o(b(a(r)))))
c(o(d(e(-(g(o(l(f))))))))


答:
JavaScript (ES6), 82 bytes

```<code>f=a=>a[0]?a.reduce((t,b,i)=>t+b[0]*f(a.filter((_,j)=>i-j).map(c=>c.slice(1))),0):1
</code>```

Works with the empty matrix too, of course.

Title: Codegolf the permanent

Body:
JavaScript (ES6), 82 bytes

f=a=>a[0]?a.reduce((t,b,i)=>t+b[0]*f(a.filter((_,j)=>i-j).map(c=>c.slice(1))),0):1

Works with the empty matrix too, of course.


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

答:
Brain-Flak

Factoid:

In Brain-Flak a one is shorter than zero and multiplying by seven takes more characters than multiplying by eight.

Since Brain-Flak programs must have an even number of characters I have added some programs with extra spaces for the odd length snippets.  These are not well golfed intentionally but rather put there in an attempt to give you a little more for your kind upvotes.

Length 2 snippet

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

It switches to the offstack.  As a single program this will always output nothing regardless of the inputs.

Length 3 snippet

```<code>{ }
</code>```

This is the {} nilad it pops top item on the stack and returns its value.  As a full program it just removes the last item input.

Length 4 snippet

```<code>(())
</code>```

This program pushes one to the top of the stack.  This is the shortest way to express 1 in Brain-Flak.

Length 5 snippet

```<code>([ ])
</code>```

This program pushes the stack height to the top of the stack.  At the start of a program it acts like argc.

Length 6 snippet

```<code>({}{})
</code>```

This program adds two numbers.

It pops the top two elements and pushes the sum.

Length 7 snippet

This one requires a -d flag to run so +3 bytes

(This one also doesn't work on try it online)

```<code>@ij
</code>```

This is the injection flag! (With a space after it because it needs to be length 7)

This halts the program takes a Brain-Flak program from STDIN and runs it as part of the code.  Its my favorite flag and (arguably) Brain-Flak's shortest self interpreter.  @ij flags can be nested

Length 8 snippet

```<code>({}<>)<>
</code>```

This snippet moves the top of the current stack to the other stack.  It is a useful component of many programs.  It starts by opening a push with ( pops the first value with {}, moves to the other stack using <> and puts the popped value down using ).  When that is done it moves back to the original stack with a <>.

Length 9 snippet

```<code>({}[()])
</code>```

(One space after the program makes it 9 characters)

This snippet decrements the top of the stack by one.  It works by popping the top of the stack with {} and adding it to the negative of () (-1) and then pushing the result back on the stack.

Length 10 snippet

```<code>{({}<>)<>}
</code>```

This snippet will move values from one stack to another until it encounters a zero.  In many programs where it is known that the stack does not contain a zero this is used as a cheap stack reverse.

Length 12 snippet

```<code>({}<({}())>)
</code>```

We've finally gotten long enough snippets that we can show off the usefulness of the <...> monad. This program increments the number underneath the top of the stack, while leaving the TOS intact. This approach can be extended. For example, this will increment the number second from the top of the stack:

```<code>{ }
</code>```0

In general, you can do:

```<code>{ }
</code>```1

to run  on the number that's n from the top without affecting the rest of the stack.

Title: Showcase of Languages

Body:
Brain-Flak

Factoid:

In Brain-Flak a one is shorter than zero and multiplying by seven takes more characters than multiplying by eight.

Since Brain-Flak programs must have an even number of characters I have added some programs with extra spaces for the odd length snippets.  These are not well golfed intentionally but rather put there in an attempt to give you a little more for your kind upvotes.

Length 2 snippet

<>

It switches to the offstack.  As a single program this will always output nothing regardless of the inputs.

Length 3 snippet

{ }

This is the {} nilad it pops top item on the stack and returns its value.  As a full program it just removes the last item input.

Length 4 snippet

(())

This program pushes one to the top of the stack.  This is the shortest way to express 1 in Brain-Flak.

Length 5 snippet

([ ])

This program pushes the stack height to the top of the stack.  At the start of a program it acts like argc.

Length 6 snippet

({}{})

This program adds two numbers.

It pops the top two elements and pushes the sum.

Length 7 snippet

This one requires a -d flag to run so +3 bytes

(This one also doesn't work on try it online)

@ij

This is the injection flag! (With a space after it because it needs to be length 7)

This halts the program takes a Brain-Flak program from STDIN and runs it as part of the code.  Its my favorite flag and (arguably) Brain-Flak's shortest self interpreter.  @ij flags can be nested

Length 8 snippet

({}<>)<>

This snippet moves the top of the current stack to the other stack.  It is a useful component of many programs.  It starts by opening a push with ( pops the first value with {}, moves to the other stack using <> and puts the popped value down using ).  When that is done it moves back to the original stack with a <>.

Length 9 snippet

({}[()])

(One space after the program makes it 9 characters)

This snippet decrements the top of the stack by one.  It works by popping the top of the stack with {} and adding it to the negative of () (-1) and then pushing the result back on the stack.

Length 10 snippet

{({}<>)<>}

This snippet will move values from one stack to another until it encounters a zero.  In many programs where it is known that the stack does not contain a zero this is used as a cheap stack reverse.

Length 12 snippet

({}<({}())>)

We've finally gotten long enough snippets that we can show off the usefulness of the <...> monad. This program increments the number underneath the top of the stack, while leaving the TOS intact. This approach can be extended. For example, this will increment the number second from the top of the stack:

({}<({}<({}())>)>)

In general, you can do:

'({}<' * n + <code> + '>)' * n

to run <code> on the number that's n from the top without affecting the rest of the stack.


问:
Summation from a to b
The program has an input of a and b, and outputs the sum of numbers from a to b, inclusive. Score is in bytes. As always, standard loopholes are disallowed.

If your input is in the format [a,b], +3 bytes

答:
J, 11 bytes

```<code>-:@<:@-*-@+
</code>```

This is a tacit verb. Example usage:

```<code>    v =: -:@<:@-*-@+
    5 v 10
45
</code>```

This verb is a fork of three verbs: -:@<:@-, *, and -@+. A fork x (f g h) y is equivalent to (x f y) g (x h y). Thus, x (-:@<:@-*-@+) y = (x(-:@<:@-)y) * (x (-@+) y). Likewise, the composition of two verbs x (f @ g) y equals f (x g y). Using this rule, given that <: decrements, and -: divides its argument by two, x(-:@<:@-)y = (x - y - 1)/2 and x(-@+)y = -(x+y). Therefore x(-:@<:@-*-@+)y = (x - y - 1) / 2 * -(x+y), and by moving the sign from -(x+y) to (x-y-1), we get (y - x + 1) / 2 * (x + y).

Title: Summation from a to b

Body:
J, 11 bytes

-:@<:@-*-@+

This is a tacit verb. Example usage:

    v =: -:@<:@-*-@+
    5 v 10
45

This verb is a fork of three verbs: -:@<:@-, *, and -@+. A fork x (f g h) y is equivalent to (x f y) g (x h y). Thus, x (-:@<:@-*-@+) y = (x(-:@<:@-)y) * (x (-@+) y). Likewise, the composition of two verbs x (f @ g) y equals f (x g y). Using this rule, given that <: decrements, and -: divides its argument by two, x(-:@<:@-)y = (x - y - 1)/2 and x(-@+)y = -(x+y). Therefore x(-:@<:@-*-@+)y = (x - y - 1) / 2 * -(x+y), and by moving the sign from -(x+y) to (x-y-1), we get (y - x + 1) / 2 * (x + y).


答:
Brain-Flak, <s>32</s> 30 bytes

```<code>([{({}[()])}{}]{()({}[()])}{})
</code>```

Try it online!

Explanation

This uses the triangulation algorithm to calculate T(a-1) and T(b) then pushes the difference.  I actually golfed 2 bytes off the existing world record triangulation algorithm while making this solution.

To push T(a-1) it uses a modified version of the original algorithm.  Instead of the simple:

```<code>({}[()])({()({}[()])}{})
</code>```

I removed both the first ({}[()]) and the ().

The reason () was there in the first place was that ({({}[()])}{}) quite conveniently calculates T(n-1) for us so there is no need to decrement if we remove the ()

This first portion is made negative and put next to the second portion which performs standard triangulation inside of the outer push.

```<code>([{({}[()])}{}]{()({}[()])}{})
</code>```

Title: Summation from a to b

Body:
The program has an input of a and b, and outputs the sum of numbers from a to b, inclusive. Score is in bytes. As always, standard loopholes are disallowed.

If your input is in the format [a,b], +3 bytes

Body:
Brain-Flak, <s>32</s> 30 bytes

([{({}[()])}{}]{()({}[()])}{})

Try it online!

Explanation

This uses the triangulation algorithm to calculate T(a-1) and T(b) then pushes the difference.  I actually golfed 2 bytes off the existing world record triangulation algorithm while making this solution.

To push T(a-1) it uses a modified version of the original algorithm.  Instead of the simple:

({}[()])({()({}[()])}{})

I removed both the first ({}[()]) and the ().

The reason () was there in the first place was that ({({}[()])}{}) quite conveniently calculates T(n-1) for us so there is no need to decrement if we remove the ()

This first portion is made negative and put next to the second portion which performs standard triangulation inside of the outer push.

([{({}[()])}{}]{()({}[()])}{})


答:
Mathematica, 54 bytes

```<code>Coefficient[Times@@(#.(v=x~Array~Length@#)),Times@@v]&
</code>```

Now that the empty matrices are no longer considered, this solution is valid. It originates from the MathWorld page on permanents.

Title: Codegolf the permanent

Body:
Mathematica, 54 bytes

Coefficient[Times@@(#.(v=x~Array~Length@#)),Times@@v]&

Now that the empty matrices are no longer considered, this solution is valid. It originates from the MathWorld page on permanents.


答:
Groovy, 19 Bytes

```<code>{a,b->(a..b).sum()}
</code>```

Title: Summation from a to b

Body:
Groovy, 19 Bytes

{a,b->(a..b).sum()}


问:
A penny saved is a penny

...counted!

You will pass your program a variable which represents a quantity of money in dollars and/or cents and an array of coin values.  Your challenge is to output the number of possible combinations of the given array of coin values that would add up to the amount passed to the code.  If it is not possible with the coins named, the program should return 0.

Note on American numismatic terminology:

1-cent coin: penny

5-cent coin: nickel

10-cent coin: dime

25-cent coin: quarter (quarter dollar)

Example 1:

Program is passed:

```<code>12, [1, 5, 10]
</code>```

(12 cents)

Output:

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

There are 4 possible ways of combining the coins named to produce 12 cents:

12 pennies

1 nickel and 7 pennies

2 nickels and 2 pennies

1 dime and 2 pennies

Example 2:

Program is passed:

```<code>26, [1, 5, 10, 25]
</code>```

(26 cents)

Output:

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

There are 13 possible ways of combining the coins named to produce 26 cents:

26 pennies

21 pennies and 1 nickel

16 pennies and 2 nickels

11 pennies and 3 nickels

6 pennies and 4 nickels

1 penny and 5 nickels

16 pennies and 1 dime

6 pennies and 2 dimes

11 pennies, 1 dime, and 1 nickel

6 pennies, 1 dime, and 2 nickels

1 penny, 1 dime, and 3 nickels

1 penny, 2 dimes, and 1 nickel

1 quarter and 1 penny

Example 3:

Program is passed:

```<code>19, [2, 7, 12]
</code>```

Output:

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

There are 2 possible ways of combining the coins named to produce 19 cents:

1 12-cent coin and 1 7-cent coin

1 7-cent coin and 6 2-cent coins

Example 4:

Program is passed:

```<code>13, [2, 8, 25]
</code>```

Output:

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

There are no possible ways of combining the coins named to produce 13 cents.

This has been through the Sandbox.  Standard loopholes apply.  This is code golf, so the answer with the fewest bytes wins.

答:
Mathematica, <s>35</s> 22 bytes

Thanks to miles for suggesting FrobeniusSolve and saving 13 bytes.

```<code>Length@*FrobeniusSolve
</code>```

Evaluates to an unnamed function, which takes the list of coins as the first argument and the target value as the second. FrobeniusSolve is a shorthand for solving Diophantine equations of the form

```<code>a<sub>1</sub>x<sub>1</sub> + a<sub>2</sub>x<sub>2</sub> + ... + a<sub>n</sub>x<sub>n</sub> = b</code>```

for the xi over the non-negative integers and gives us all the solutions.

Title: A penny saved is a penny

Body:
Mathematica, <s>35</s> 22 bytes

Thanks to miles for suggesting FrobeniusSolve and saving 13 bytes.

Length@*FrobeniusSolve

Evaluates to an unnamed function, which takes the list of coins as the first argument and the target value as the second. FrobeniusSolve is a shorthand for solving Diophantine equations of the form

a1x1 + a2x2 + ... + anxn = b

for the xi over the non-negative integers and gives us all the solutions.


答:
Haskell, <s>37</s> 34 bytes

```<code>s#l@(c:d)|s>=c=(s-c)#l+s#d
s#_=0^s
</code>```

Usage example: 26 # [1,5,10,25] -> 13.

Simple recursive approach: try both the next number in the list (as long as it is less or equal to the amount) and skip it. If subtracting the number leads to an amount of zero, take a 1 else (or if the list runs out of elements) take a 0. Sum those 1s and 0s.

Edit: @Damien: saved 3 bytes by pointing to a shorter base case for the recursion (which also can be found in @xnors answer).

Title: A penny saved is a penny

Body:
...counted!

You will pass your program a variable which represents a quantity of money in dollars and/or cents and an array of coin values.  Your challenge is to output the number of possible combinations of the given array of coin values that would add up to the amount passed to the code.  If it is not possible with the coins named, the program should return 0.

Note on American numismatic terminology:

1-cent coin: penny

5-cent coin: nickel

10-cent coin: dime

25-cent coin: quarter (quarter dollar)

Example 1:

Program is passed:

```<code>12, [1, 5, 10]
</code>```

(12 cents)

Output:

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

There are 4 possible ways of combining the coins named to produce 12 cents:

12 pennies

1 nickel and 7 pennies

2 nickels and 2 pennies

1 dime and 2 pennies

Example 2:

Program is passed:

```<code>26, [1, 5, 10, 25]
</code>```

(26 cents)

Output:

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

There are 13 possible ways of combining the coins named to produce 26 cents:

26 pennies

21 pennies and 1 nickel

16 pennies and 2 nickels

11 pennies and 3 nickels

6 pennies and 4 nickels

1 penny and 5 nickels

16 pennies and 1 dime

6 pennies and 2 dimes

11 pennies, 1 dime, and 1 nickel

6 pennies, 1 dime, and 2 nickels

1 penny, 1 dime, and 3 nickels

1 penny, 2 dimes, and 1 nickel

1 quarter and 1 penny

Example 3:

Program is passed:

```<code>19, [2, 7, 12]
</code>```

Output:

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

There are 2 possible ways of combining the coins named to produce 19 cents:

1 12-cent coin and 1 7-cent coin

1 7-cent coin and 6 2-cent coins

Example 4:

Program is passed:

```<code>13, [2, 8, 25]
</code>```

Output:

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

There are no possible ways of combining the coins named to produce 13 cents.

This has been through the Sandbox.  Standard loopholes apply.  This is code golf, so the answer with the fewest bytes wins.

Body:
Haskell, <s>37</s> 34 bytes

s#l@(c:d)|s>=c=(s-c)#l+s#d
s#_=0^s

Usage example: 26 # [1,5,10,25] -> 13.

Simple recursive approach: try both the next number in the list (as long as it is less or equal to the amount) and skip it. If subtracting the number leads to an amount of zero, take a 1 else (or if the list runs out of elements) take a 0. Sum those 1s and 0s.

Edit: @Damien: saved 3 bytes by pointing to a shorter base case for the recursion (which also can be found in @xnors answer).


Title: A penny saved is a penny

Body:
PHP, 327 Bytes

function c($f,$z=0){global$p,$d;if($z){foreach($p as$m){for($j=0;$j<=$f/$d[$z];){$n=$m;$n[$d[$z]]=$j++;$p[]=$n;}}}else for($p=[],$j=0;$j<=$f/$d[$z];$j++)$p[]=[$d[$z]=>$j];if($d[++$z])c($f,$z);}$d=$_GET[a];c($e=$_GET[b]);foreach($p as$u){$s=0;foreach($u as$k=>$v)$s+=$v*$k;if($s==$e&count($u)==count($d))$t[]=$u;}echo count($t);

Try it


问:
Shortest possible JS (ES5) code to get ids of all elements of a given tag
Using the shortest JS (ES5) code possible, as measured in number of characters, gather all the ids on a page for foobar elements into a comma-delimited string.  For example:

```<code><div>
  <foobar id="456"></foobar>
  <foobar id="aaa"></foobar>
  <foobar id="987"></foobar>
<div>
</code>```

Should give "456,aaa,987"

You cannot use ES6 or any libraries. The foobar elements will not ever be nested.

My current shortest solution is

```<code>[].map.call(document.querySelectorAll("foobar"),function(a){return a.id}).join()
</code>```

Can anyone beat it?

答:
I don't think it's going to get shorter than this:

```<code>[].map.call(document.querySelectorAll("foobar"),function(a){return a.id})+""
</code>```

Hopefully someone can prove me wrong!

Body:
I don't think it's going to get shorter than this:

[].map.call(document.querySelectorAll("foobar"),function(a){return a.id})+""

Hopefully someone can prove me wrong!


答:
JavaScript (ES6), 59 bytes

```<code>f=(n,c)=>n?c.reduce((x,y,i)=>y>n?x:x+f(n-y,c.slice(i)),0):1
</code>```

Coins are input from highest to lowest, e.g. f(26,[100,25,10,5,1]). If you have a penny, remove it and use this much faster version instead:

```<code>f=(n,c)=>n?c.reduce((x,y,i)=>y>n?x:x+f(n-y,c.slice(i)),1):1
</code>```

This uses a recursive formula much like @nimi's. I originally wrote this a few days ago when the challenge was still in the sandbox; it looked like this:

```<code>f=(n,c=[100,25,10,5])=>n?c.reduce((x,y,i)=>y>n?x:x+f(n-y,c.slice(i)),1):1
</code>```

The only differences being the default value of c (it had a set value in the original challenge), and changing the 0 in the .reduce function to 1 (this was two bytes shorter and a bazillion times faster than c=[100,25,10,5,1]).

Here's a modified version which outputs all combinations, rather than the number of combinations:

```<code>f=(n,c)=>n?c.reduce((x,y,i)=>y>n?x:[...x,...f(n-y,c.slice(i)).map(c=>[...c,y])],[]):[[]]
</code>```

Title: A penny saved is a penny

Body:
JavaScript (ES6), 59 bytes

f=(n,c)=>n?c.reduce((x,y,i)=>y>n?x:x+f(n-y,c.slice(i)),0):1

Coins are input from highest to lowest, e.g. f(26,[100,25,10,5,1]). If you have a penny, remove it and use this much faster version instead:

f=(n,c)=>n?c.reduce((x,y,i)=>y>n?x:x+f(n-y,c.slice(i)),1):1

This uses a recursive formula much like @nimi's. I originally wrote this a few days ago when the challenge was still in the sandbox; it looked like this:

f=(n,c=[100,25,10,5])=>n?c.reduce((x,y,i)=>y>n?x:x+f(n-y,c.slice(i)),1):1

The only differences being the default value of c (it had a set value in the original challenge), and changing the 0 in the .reduce function to 1 (this was two bytes shorter and a bazillion times faster than c=[100,25,10,5,1]).

Here's a modified version which outputs all combinations, rather than the number of combinations:

f=(n,c)=>n?c.reduce((x,y,i)=>y>n?x:[...x,...f(n-y,c.slice(i)).map(c=>[...c,y])],[]):[[]]


答:
Jelly (fork), 2 bytes

```<code>æf
</code>```

This relies on a branch of Jelly where I was working on implementing Frobenius solve atoms so unfortunately you cannot try it online.

Usage

```<code>$ ./jelly eun 'æf' '12' '[1,5,10]'
4
$ ./jelly eun 'æf' '26' '[1,5,10,25]'
13
$ ./jelly eun 'æf' '19' '[2,7,12]'
2
$ ./jelly eun 'æf' '13' '[2,8,25]'
0
</code>```

Explanation

```<code>æf  Input: total T, denominations D
æf  Frobenius count, determines the number of solutions
    of nonnegative X such that X dot-product D = T
</code>```

Title: A penny saved is a penny

Body:
Jelly (fork), 2 bytes

æf

This relies on a branch of Jelly where I was working on implementing Frobenius solve atoms so unfortunately you cannot try it online.

Usage

$ ./jelly eun 'æf' '12' '[1,5,10]'
4
$ ./jelly eun 'æf' '26' '[1,5,10,25]'
13
$ ./jelly eun 'æf' '19' '[2,7,12]'
2
$ ./jelly eun 'æf' '13' '[2,8,25]'
0

Explanation

æf  Input: total T, denominations D
æf  Frobenius count, determines the number of solutions
    of nonnegative X such that X dot-product D = T