Count, Replace, Add Up! [duplicate]

This question already has an answer here:

Definition

Define the nth term of the CRAU sequence as follows.

1. Begin with the singleton array A = [n].

2. Do the following n times:

For each integer k in A, replace the entry k with k natural numbers, counting from 1 to k.

3. Compute the sum of all integers in A.

For example, if n = 3, we start with the list .

We replace 3 with 1, 2, 3, yielding [1, 2, 3].

We now replace 1, 2, and 3 with 1, 1, 2 and 1, 2, 3 (resp.), yielding [1, 1, 2, 1, 2, 3].

Finally, we perform the same replacements as in the previous step for all six integers in the array, yielding [1, 1, 1, 2, 1, 1, 2, 1, 2, 3].

The sum of the resulting integers is 15, so this is the third CRAU number.

Write a program of a function that, given a strictly positive integer n as input, computes the nth term of the CRAU sequence.

This is . May the shortest code in bytes win!

1 ->       1
2 ->       4
3 ->      15
4 ->      56
5 ->     210
6 ->     792
7 ->    3003
8 ->   11440
9 ->   43758
10 ->  167960
11 ->  646646
12 -> 2496144
13 -> 9657700

marked as duplicate by xnor code-golf StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Jun 21 '16 at 7:32

• This seems a rather roundabout way to present a challenge to compute choose(2*n,n-1). – xnor Jun 21 '16 at 7:27
• – Dennis Jun 21 '16 at 7:29
• I'm calling it a dupe of a previous (disguised) binomial challenge. Maybe you can instead have the output be the full list without summing? – xnor Jun 21 '16 at 7:33
• Welcome to Programming Puzzles and Code Golf! Unfortunately this challenge is too similar to Code Golf: Number of paths! to warrant a separate post. I recommend posting future challenges to the Sandbox where they can get meaningful feedback before being posted to the main site. ;-P – Digital Trauma Jun 21 '16 at 19:24
• @DigitalTrauma Thank you. I'll keep that in mind. – Dennis Jun 21 '16 at 22:20

MATL, 5 bytes

EGqXn

Explanation:

E       #Double the input
Gq     #Push "input - 1"
Xn   #Calculate "nchoosek" on the two numbers

Python, 65 bytes

def f(k):
n,p=2*k,1
for i in range(1,k):p=p*n//i;n-=1
return p

Explanation: It's a simplified version of n choose k. See this sequence.

Retina, 27 bytes

.\$*
M!&+%.+(?=1)|^.+
0

Input in unary, using 0 as the unary digit.

Try it online!

J, 5 bytes

<:!+:

Uses the binomial coefficient of (2n, n-1).

For 22 bytes, this is a possible solution based on using the process described in the challenge.

[:+/([:;<@(1+i.)"0)^:]

Usage

Note: Extra commands used to format output for multiple input.

f =: <:!+:
(,.f"0) >: i. 13
1       1
2       4
3      15
4      56
5     210
6     792
7    3003
8   11440
9   43758
10  167960
11  646646
12 2496144
13 9657700

Explanation

<:!+:  Input: n
+:  Double the value of n to get 2*n
<:     Decrement n to get n-1
!    Calculate the binomial coefficient of (2*n, n-1) and return

[:+/([:;<@(1+i.)"0)^:]  Input: n
]  Identify function, gets the value n
(     ...     )^:   Repeat the following n times with an initial value [n]
(    )"0        Means rank 0, or to operate on each atom in the list
i.           Create a range from 0 to that value, exclusive
1+             Add 1 to each to make the range from 1 to that value
<@                Box the value
[:;                  Combine the boxes and unbox them to make a list and return
[:+/                    Sum the values in the list after n iterations and return