7 kyu

Total Sums of Coefficients of a Binomial Raised to the Nth-Power

287 of 378raulbc777

Description:

When you want to get the square of a binomial of two variables x and y, you will have:

(x+y)2=x2+2xy+y2(x+y)^2 = x^2 + 2xy + y ^2

And the cube:

(x+y)3=x3+3x2y+3xy2+y3(x+y)^3 = x^3 + 3x^2y + 3xy^2 +y^3

It is known from many centuries ago that for an exponent n, the result of a binomial x + y raised to the n-th power is:

(x+y)n=(n0)xny0+(n1)xn1y1+(n2)xn2y2++(nn1)x1yn1+(nn)x0yn \displaystyle (x+y)^n = {{n} \choose {0}} x^ny^0 + {{n} \choose {1}} x^{n-1}y^1 + {{n} \choose {2}} x^{n-2}y^2 +\cdots +{{n} \choose {n-1}} x^1y^{n-1} + {{n} \choose {n}} x^0y^n

Or using the sumation notation:

(x+y)n=k=0n(nk)xnkyk=k=0n(nk)xkynk\displaystyle (x+y)^n = \sum_{k=0}^n {{n} \choose {k}} x^{n-k} y^k=\sum_{k=0}^n {{n} \choose {k}} x^k y^{n-k}

Each coefficient of a term has the following value:

(nk)=n!(nk)!k!=(nk+1)(n2)(n1)nk! \displaystyle {n \choose k} = \dfrac{n!}{(n-k)! \cdot k!} = \dfrac{(n-k+1)\cdots(n-2)(n-1)n}{k!}

Each coefficient value coincides with the amount of combinations without replacements of a set of n elements using only k different ones of that set.

Let's see the total sum of the coefficients of the different powers for the binomial:

(x+y)0(1)(x+y)^0(1)

(x+y)1=x+y(2)(x+y)^1 = x+y(2)

(x+y)2=x2+2xy+y2(4)(x+y)^2 = x^2 + 2xy + y ^2(4)

(x+y)3=x3+3x2y+3xy2+y3(8)(x+y)^3 = x^3 + 3x^2y + 3xy^2 +y^3(8)

Task

Create a function that returns (an array) of the coefficients sums from 0 to n (inclusive), where the last element is the sum of all previous elements.

We add some examples below:

for n = 0, return 1, 1
for n = 1, return 1, 2, 3
for n = 2, return 1, 2, 4, 7
for n = 3, return 1, 2, 4, 8, 15

Features of the test

Low Performance Tests
Number of tests = 50
9 < n < 101

High Performance Tests
Number of Tests = 50
99 < n < 5001

N.B. In C, input is limited to 0 <= n <= 63
Fundamentals
Data Structures
Algorithms
Mathematics
Logic

Stats:

CreatedDec 9, 2016
PublishedDec 9, 2016
Warriors Trained942
Total Skips26
Total Code Submissions1193
Total Times Completed378
Python Completions287
Ruby Completions48
Haskell Completions38
C Completions38
Total Stars14
% of votes with a positive feedback rating83% of 101
Total "Very Satisfied" Votes73
Total "Somewhat Satisfied" Votes21
Total "Not Satisfied" Votes7
Total Rank Assessments5
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • raulbc777 Avatar
  • smile67 Avatar
  • rowcased Avatar
  • user9644768 Avatar
  • hobovsky Avatar
  • cliffstamp Avatar
  • Just4FunCoder Avatar
Ad