7
The challenge is to write the shortest function/program to find a polynomial given the roots. The function or program should take valid input; that is, a list of integers representing the roots of the polynomial, and return valid output.
Output should return a sequence of numbers representing the polynomial. For example:
2, 3
represents 2x^1 - 3x^0 = 0
1, 6, 1, 8, 0, 3, 3
represents 1x^6 + 6x^5 + 1x^4 + 8x^3 + 0x^2 + 3x^1 + 3x^0 = 0
-1 0 5, -3
represents -1x^3 + 0x^2 + 5x^1 + -3x^0 = 0
I hope you get the idea.
Example Usage
For an input of 1, 2
, the output should be 1, -3, 2
, which represents the equation 1x^2 + -3x^1 + 2x^0 = 0
, or x^2 - 3x + 2 = 0
.
For an input of 1, -1, 0
, the output should be 1, 0, -1, 0
.
For the input, duplicate values should be removed and order does not matter. For example, the result with input 3, 3, 6
should be the same as the result with input 6, 3
.
Float arguments are optional.
As this is code golf, the shortest entry in characters wins. Good luck!
2>
1@ steveverrill What I intended was to find the smallest polynomial given a set of solutions, and (x-3)(x-3)(x-6) is larger than (x-6)(x-3). I do see your argument though. – The Turtle – 2015-08-20T00:37:37.083
7
Most [tag:code-golf] contests are scored by
– Digital Trauma – 2015-08-20T01:35:54.723bytes
and notcharacters
. I would advise the former. The latter encourages weird base256/unicode compression of the source, which IMO don't really add anything to the contest, and merely serve to obfuscate the code, making less accessible answers, thus decreasing the overall quality of the site. http://meta.codegolf.stackexchange.com/questions/2364/recommend-that-new-users-use-bytes-not-charactersYou speak of input and output, and represent them as comma separated strings... is this the format we must use, or can we use, for instance, arrays?
[1,2,3]
rather than"1, 2, 3"
? – Glen O – 2015-08-20T04:15:32.913what is the size of the largest integer that may appear? otherwise I guess all these answers don't live up to the spec unless they are using big integers – Chris Beck – 2015-08-20T05:39:56.973
@DigitalTrauma Okay. I'll do so for next time. – The Turtle – 2015-08-20T21:29:43.920
@GlenO As long as the data type can be easily interpreted by humans as solutions, I would say that would be fine. – The Turtle – 2015-08-20T21:31:34.823