The provided script gives me the answer “-82650”, when the correct answer is “-82640”. I’ve tried removing the line “add (Base Value) to (Quadratic List)”, but that got me “-82600”.
I think your bug is that if degree=5 you really need six coefficients, including the constant term. But I’m not sure.
But I’m guessing you’re a recent refugee from Scratch, because this can be done much more easily in Snap!. For one thing, we have an exponentiation operator:
Next, we can apply that operator to several numbers at once:
it’ll turn into a SUM block when you let go of the mouse.)
But probably the user of your block would like to have the coefficient of the largest exponent at the left, and the constant term at the right, so I counted the exponents down to zero rather than up from zero:
If you don’t like to have to use a LIST block to enter the coefficients, you can add a little syntactic sugar by making COEFFICIENTS a variadic numeric input:
Nah, I just did it that way for convince of indexing. I actually never liked scratch and used it for maybe a week in middle school solely because I had too. It always felt like they dumb’ed things down too much, imo.
On to the other things you mentioned. I never actually knew you could do that with lists! My APCSP class has only just started going over lists with the shopping list lesson, so I’m not super similar with list functionalities still. Same with SUM, didn’t know that, but that’s actual really handy!
The code you gave does work, and much more simply at that. Now I’ll start thinking on how to inc operate that into my graphing calculator to make it actually graph.
Why “length of coefficients -1 to 0” and then have an appended 0 at the end of your list. Instead, just leave it as “length of coefficients to 0” and for the constant just have a separate input that gets added at the end, and remove the appended 0 at the end of the coefficient list. This still gets you the same right answer, and trims down the complexity a little, no?
I didn’t mean that the code should append a zero, just that I appended a zero to your example to account for the fact that a degree-five polynomial actually has six terms. In actual use, the block should allow for any constant term, not assume zero!