Post History
Sandbox
Expand a polynomial [FINALIZED]
#3: Post edited
- # Challenge
- Given the roots of a polynomial (that is, the
values where the polynomial evaluates to zero), as an array of real numbers, return the polynomial's coefficients. That is, given real roots , find the coefficients of the expansion of .- You may use either lowest power first or highest power first order for the resulting list of coefficients.
- ## Tests
- ```
- [] -> [1]
- [1] -> [-1, 1] // (x - 1) = -1 + 1x
- [1, 2] -> [2, -3, 1] // (x - 1)(x - 2) = 2 - 3x + 1x^2
- [1, 1] -> [1, -2, 1] // (x - 1)^2 = 1 -2x + 1x^2
- [1, 2, 3] -> [-6, 11, -6, 1] // (x - 1)(x - 2)(x - 3) = -6 + 11x - 6x^2 + x^3
- ```
- This is code golf, so the shortest answer in bytes wins!
- # Challenge
- Given the roots of a polynomial (that is, the
values where the polynomial evaluates to zero), as an array of real numbers, return the polynomial's coefficients. - That is, given real roots
, find the coefficients of the expansion of , or any non-zero scalar multiple of it. - You may use either lowest power first or highest power first order for the resulting list of coefficients.
- ## Tests
- ```
- // Note that any non-zero scalar multiple of these results is valid
- [] -> [1]
- [1] -> [-1, 1] // (x - 1) = -1 + 1x
- [1, 2] -> [2, -3, 1] // (x - 1)(x - 2) = 2 - 3x + 1x^2
- [1, 1] -> [1, -2, 1] // (x - 1)^2 = 1 -2x + 1x^2
- [1, 2, 3] -> [-6, 11, -6, 1] // (x - 1)(x - 2)(x - 3) = -6 + 11x - 6x^2 + x^3
- ```
- This is code golf, so the shortest answer in bytes wins!
#2: Post edited
- # Challenge
Given the roots of a polynomial, as an array of numbers, return the polynomial's coefficients. You may use either lowest power first or highest power first order.- ## Tests
- ```
- [] -> [1]
- [1] -> [-1, 1] // (x - 1) = -1 + 1x
- [1, 2] -> [2, -3, 1] // (x - 1)(x - 2) = 2 - 3x + 1x^2
- [1, 1] -> [1, -2, 1] // (x - 1)^2 = 1 -2x + 1x^2
- [1, 2, 3] -> [-6, 11, -6, 1] // (x - 1)(x - 2)(x - 3) = -6 + 11x - 6x^2 + x^3
- ```
- This is code golf, so the shortest answer in bytes wins!
- # Challenge
- Given the roots of a polynomial (that is, the
values where the polynomial evaluates to zero), as an array of real numbers, return the polynomial's coefficients. - That is, given real roots
, find the coefficients of the expansion of . - You may use either lowest power first or highest power first order for the resulting list of coefficients.
- ## Tests
- ```
- [] -> [1]
- [1] -> [-1, 1] // (x - 1) = -1 + 1x
- [1, 2] -> [2, -3, 1] // (x - 1)(x - 2) = 2 - 3x + 1x^2
- [1, 1] -> [1, -2, 1] // (x - 1)^2 = 1 -2x + 1x^2
- [1, 2, 3] -> [-6, 11, -6, 1] // (x - 1)(x - 2)(x - 3) = -6 + 11x - 6x^2 + x^3
- ```
- This is code golf, so the shortest answer in bytes wins!
#1: Initial revision
Expand a polynomial
# Challenge Given the roots of a polynomial, as an array of numbers, return the polynomial's coefficients. You may use either lowest power first or highest power first order. ## Tests ``` [] -> [1] [1] -> [-1, 1] // (x - 1) = -1 + 1x [1, 2] -> [2, -3, 1] // (x - 1)(x - 2) = 2 - 3x + 1x^2 [1, 1] -> [1, -2, 1] // (x - 1)^2 = 1 -2x + 1x^2 [1, 2, 3] -> [-6, 11, -6, 1] // (x - 1)(x - 2)(x - 3) = -6 + 11x - 6x^2 + x^3 ``` This is code golf, so the shortest answer in bytes wins!