Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Sandbox

Post History

75%
+4 −0
Sandbox Expand a polynomial [FINALIZED]

posted 3y ago by Moshi‭  ·  edited 3y ago by Moshi‭

#4: Post edited by user avatar Moshi‭ · 2021-09-11T02:52:35Z (about 3 years ago)
  • Expand a polynomial
  • Expand a polynomial [FINALIZED]
#3: Post edited by user avatar Moshi‭ · 2021-09-01T21:27:39Z (about 3 years ago)
  • # Challenge
  • Given the roots of a polynomial (that is, the $x$ values where the polynomial evaluates to zero), as an array of real numbers, return the polynomial's coefficients.
  • That is, given real roots $r_1, r_2, \cdots , r_n$, find the coefficients of the expansion of $(x-r_1)(x-r_2)\cdots(x-r_n)$.
  • 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 $x$ values where the polynomial evaluates to zero), as an array of real numbers, return the polynomial's coefficients.
  • That is, given real roots $r_1, r_2, \cdots , r_n$, find the coefficients of the expansion of $(x-r_1)(x-r_2)\cdots(x-r_n)$, 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 by user avatar Moshi‭ · 2021-08-31T23:08:17Z (about 3 years ago)
  • # 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 $x$ values where the polynomial evaluates to zero), as an array of real numbers, return the polynomial's coefficients.
  • That is, given real roots $r_1, r_2, \cdots , r_n$, find the coefficients of the expansion of $(x-r_1)(x-r_2)\cdots(x-r_n)$.
  • 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 by user avatar Moshi‭ · 2021-08-31T22:15:31Z (about 3 years ago)
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!